基于webkit核心的浏览器,如chrome、safari等,在显示小于12px的英文字符时始终会显示为12px。解决这一问题,只需要在设置字体的地方,添加以下css代码:
-webkit-text-size-adjust: none;
这样问题就迎刃而解了。
基于webkit核心的浏览器,如chrome、safari等,在显示小于12px的英文字符时始终会显示为12px。解决这一问题,只需要在设置字体的地方,添加以下css代码:
-webkit-text-size-adjust: none;
这样问题就迎刃而解了。
内容涉及范围:使用input file选择图片后,在不提交至服务器的情况下,预览选择的图片,获取图片文件的大小。
先说一些结论,在默认设置的情况下,ie6和firefox6可以预览和获取大小;ie7-9只能预览;chrome13只能获取大小。只能预览或只能获取大小的,很大程度上都是由浏览器的安全策略造成的。
接下来是一些详情,
html代码:
<input id=”file” type=”file”" />
<div id=”div”>
<img id=”img” />
</div>
各浏览器图片预览及大小获得:
| 浏览器(版本) | 图片预览 | 大小获得 |
| ie6 | 设置img.src=file.value | 通过img.fileSize获得 |
| ie7-9 |
|
无法获得,需结合后台功能 |
| firefox6 | 设置img.src=file.files.item(0).getAsDataURL() | file.files.item(0).fileSize或者file.files.item(0).size |
| chrome13 | 无法通过前端方法本地预览,需结合后台功能,即上传文件后展示 | file.files.item(0).fileSize或者file.files.item(0).size |
在ie7-9、firefox6及chrome13下,浏览器出于安全考虑,无法通过file.value获得选择图片的本地路径,其中ie7-9和chrome13获得的是经过处理的本地路径,而firefox6下获得的是图片的名称。
小乔的解决方案,这应该算是终极的多浏览器兼容的方案了,目前常用的浏览器(ie6-9,firefox,chrome)都是兼容的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <style type="text/css"> .float-div { float:left; } .img-wrapper { border:1px solid gray; width:100px; height:100px; text-align:center; display:table-cell; vertical-align:middle; *display:block; } .img-wrapper * { vertical-align:middle; } .img-wrapper span { *display:inline-block; *height:100%; } .img-wrapper img { border:none; } </style> <div class="float-div"> <a href="#" class="img-wrapper"> <span></span> <img src="80x80.png" alt="80x80" /> </a> </div> |
但是,以上方案在ie6下会受word-wrap:break-word的影响,需要修改word-wrap为normal。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <style type="text/css"> .float-div { float:left; } .img-wrapper { border:1px solid gray; width:100px; height:100px; text-align:center; display:table-cell; vertical-align:middle; *display:block; } .img-wrapper * { vertical-align:middle; word-wrap:normal; } .img-wrapper span { *display:inline-block; *height:100%; } .img-wrapper img { border:none; } </style> <div class="float-div"> <a href="#" class="img-wrapper"> <span></span> <img src="80x80.png" alt="80x80" /> </a> </div> |
一张图片,栖身于一个div构成的囹圄中,不上不下,必须垂直居中、水平居中。为此,本来一层的牢房,就要多出一层,而为了ie还得再加一层。最为一张只是想待在div中央的图片,你伤不起啊。
1 2 3 4 5 6 7 8 9 | <div class="outer">
<div>
<div>
<span class="inlinEl">
<img src="http://a1.att.hudong.com/08/30/01300000369368125422300747744_s.jpg" alt="" />
</span>
</div>
</div>
</div> |
为兼容多个浏览器,使用多层嵌套。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | .outer { #position: relative; width: 100px; height: 100px; } .outer div { width: 100%; text-align: center; #position: absolute; #top: 50%; *left: 0; } .outer div div { display: block; text-align: center; #position: relative; #top: -50%; } .outer div div img { vertical-align: middle; } .outer .inlinEl { display: table-cell; vertical-align: middle; width: 100px; height: 100px; } |
除ie6,其他浏览器使用常规的display: table、display: table-cell和vertical-align: middile来实现垂直居中。ie6下垂直居中通过加#部分实现。最后一段样式,针对img在firefox、chrome下无法正常居中做的一些调整,不添加这一段样式,可能会出现图片在中部偏上。
PS 关于hack,ie6使用#或者_,ie7使用+,ie6和ie7使用*。
除ie,其他浏览器(firefox,chrome)通过为.outer div div添加display: block,使得text-align: center起效。因为image外层div跟image勾结,把自己变成了内联元素。而ie下,直接通过text-align: center实现水平居中。
另外,需要注意的是,需要设置outer的width、height和inlinEl的width、height相同。
为什么增加inlinEl?因为chrome下不正常。【万恶的浏览器啊】
可不可以在img的上一层div上使用inlinEl?可以。但是ie下不正常。【万恶的ie啊】
后来,测试一下多文本居中,此方法可以正常工作,只需要将span.inlinEl的内容替换成需要居中的内容即可。
HTML代码如下,span.inlinEl中可以使用多种标签的组合。
1 2 3 4 5 6 7 8 9 | <div class="outer"> <div> <div> <span class="inlinEl"> 3.Approved RFQs are placed in the Customized Sourcing channel for suppliers to view and quote. Our Industry Specialist will also send the RFQs to matching suppliers. </span> </div> </div> </div> |
CSS代码如下,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | .outer { #position: relative; width: 374px; height: 75px; } .outer div { width: 100%; #position: absolute; #top: 50%; *left: 0; } .outer div div { display: block; #position: relative; #top: -50%; } .outer .inlinEl { display: table-cell; vertical-align: middle; width: 374px; height: 75px; font-size: 12px; line-height: 20px; } |
PS 垂直居中参考资料http://blog.bingo929.com/css-vertical-center.html
在如此纠结的情况下,还不如使用table来实现垂直居中了,实现起来方便多了。