Home >Web Front-end >CSS Tutorial >Detailed introduction to zoom attribute in css
The zoom attribute is an IE-specific attribute. In addition to setting or retrieving the zoom ratio of the object, it can also trigger IE's haslayout attribute, clear floats, clear margin overlap, etc. However, it is worth noting that Firefox Browser does not support the zoom attribute, but the zoom attribute can also be supported in the webkit kernel browser.
1. Some of the previous YY
First of all, I don’t know if you noticed that the title “Clear Floats” has quotation marks. I've been wondering recently whether this so-called "clearing float" is accurate. People have a herd mentality, especially in our society with a collectivist culture. Conformity is not a negative label. In Asian collectivist cultures (such as Japan), it symbolizes patience, self-control, and maturity. However, sometimes Continuing with some inaccurate opinions, do you still remember the story of "two iron balls hitting the ground at the same time" in elementary school?
I have something personal and emotional to say here, and refutations are very welcome. I often see the word "clear float" in foreign technology, which translates to "clear float". I am new to the industry, so I can only speculate whether "clear float" really means that, so I It is widely used, and the more widely it is used, the less likely it is to find its imprecision.
I recently thought about some things about "clearing floats" and found that the more I think about the term "clearing floats", the more inaccurate it becomes. The accurate statement should be "clearing the impact of float". What is the real "clearing float"? float:none; This is the literal meaning of "clearing float". Of course, it is also possible that "clearing floats" is an abbreviation, which means "clearing the impact of floats". It is just a casual name, and everyone calls it that, and everyone actually knows it. I hope I am overthinking it.
YY ends, let’s get to the main topic of this article, some thoughtful content, and my understanding of the reasons why overflow and zoom can clear the impact of floating. These are superficial understandings. I hope people who really understand can give me some advice. Corrections, rebuttals and your own opinions are most welcome.
2. The wrapping of elements
The term "wrapping" often appears in JavaScript, especially in js libraries such as jQuery. It is a very vivid word. Yesterday I saw this very inspiring sentence: "Visual thinking can give your mind more space to solve problems in a unique and effective way." What is inspiring is that the "visual thinking" here is changed. Other terms such as "emotional thinking", "visual thinking", etc. are also used. That is to say, incorporating some very subjective and illogical thinking when thinking about problems will help to have a broader space to solve problems.
When I mention the word "package", I think of white blood cells eating bacteria (thinking visually - associating), as well as warmth and peace of mind (thinking emotionally). This is related to factors such as human genetics and growth. Why am I talking about these seemingly irrelevant things? Because a lot of the things I am going to describe below are my own feelings, "I think this is what it is like", a lot of subjective things.
(1) Let’s take a look at the role of zoom in non-IE browsers: Look at the example below. I accessed it under Google Chrome. In this example, zoom The function is to zoom in to 2 times the original size (readers can try to zoom out by themselves)
1.zoom:1 time
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style> p{ width: 100px; height: 100px; border: 3px solid red; zoom: 1; } </style> </head> <body> <p>hello</p> </body> <html>
The result of the above code is as shown in the figure:
2.zoom: 2 means the zoom is 2 times the original:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style> p{ width: 100px; height: 100px; border: 3px solid red; zoom: 1; } </style> </head> <body> <p>hello</p> </body> <html>
Note: zoom appears to support zooming in or out in non-IE browsers, but because this attribute is a non-standard css attribute, Therefore, generally in non-IE browsers, zoom is not used to achieve the zoom effect of p. Now, if you want to zoom in or out, you directly use the transform attribute of CSS3.
(2) After looking at the performance of zoom in non-IE browsers, we should take a look at the role of this attribute in IE browsers.
Zoom的使用方法:
zoom : normal | number
normal : 默认值。使用对象的实际尺寸
number : 百分数 | 无符号浮点实数。浮点实数值为1.0或百分数为100%时相当于此属性的 normal 值用白话讲解就是zoom:后面的数字即放大的倍数,可以是数值,也可以是百分比。如:zoom:1,zoom:120%。而这个属性只要在IE中才起作用,所以很少用到它的实际用途,而最经常用到作用是清除浮动等,如:
.border{
border:1px solid #CCC;
padding:2px;
overflow:hidden;
_zoom:1;
}
_zoom是CSS hack中专对IE6起作用的部分。IE6浏览器会执行zoom:1表示对象的缩放比例,但这里
overflow:hidden;和_zoom:1;是连起来用的,作用是清除border内部浮动。
同理,还可以使用同样方法清除margin属性在IE浏览器中的重叠问题:这就要提到zoom属性在IE中的第二个作用了,即
兼容IE6、IE7、IE8浏览器,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:
(2)触发IE浏览器的haslayout ,解决ie下的浮动,margin重叠等一些问题。
比如,本站使用p做一行两列显示,HTML代码:
<p class="h_mainbox"> <h2>推荐文章</h2> <ul class="mainlist"> <li><a href="#" style="color:#0000FF" target="_blank">CSS库吧</a></li> <li><a href="#" style="color:#0000FF" target="_blank">原创< /a></li> </ul> </p>
CSS代码:
.h_mainbox { border:1px solid #dadada; padding:4px 15px; background:url(../mainbox_bg.gif) 0 1px repeat-x; margin-bottom:6px; overflow:hidden} .h_mainbox h2 { font-size:12px; height:30px; line-height:30px; border-bottom:1px solid #ccc; color:#555;} .h_mainbox h2 span { float:right; font-weight:normal;} .h_mainbox ul { padding:6px 0px; background:#fff;} .mainlist { overflow:auto; zoom:1;} .h_mainbox li { width:268px; float:left; height:24px; overflow:hidden; background:url(../icon3.gif) 0 6px no-repeat; padding:0px 5px 0px 18px; line-height:200%;}
.mainlist里面的zoom:1的那里就可以在IE6、IE7、IE8正常显示效果了。
(3)下面是zoom属性在IE浏览器中常见作用总结,希望对今后在使用这个属性时有所帮助:
1、检查页面的标签是否闭合
不要小看这条,也许折腾了你两天都没有解决的 CSS BUG 问题,却仅仅源于这里。毕竟页面的模板一般都是由开发来嵌套的,而他们很容易犯此类问题。
快捷提示:可以用 Dreamweaver 打开文件检查,一般没有闭合的标签,会黄色背景高亮。
2、样式排除法
有些复杂的页面也许加载了 N 个外链 CSS 文件,那么逐个删除 CSS 文件,找到 BUG 触发的具体 CSS 文件,缩小锁定的范围。
对于刚才锁定的问题 CSS 样式文件,逐行删除具体的样式定义,定位到具体的触发样式定义,甚至是具体的触发样式属性。
3、模块确认法
有时候我们也可以从页面的 HTML 元素出发。删除页面中不同的 HTML 模块,寻找到触发问题的 HTML 模块。
4、检查是否清除浮动
其实有不少的 CSS BUG 问题是因为没有清除浮动造成的。养成良好的清除浮动的习惯是必要的,推荐使用 无额外 HTML 标签的清除浮动的方法(尽量避免使用 overflow:hidden;zoom:1 的类似方法来清除浮动,会有太多的限制性)。
5、检查 IE 下是否触发 haslayout
很多的 IE 下复杂 CSS BUG 都与 IE 特有的 haslayout 息息相关。熟悉和理解 haslayout 对于处理复杂的 CSS BUG 会事半功倍。推荐阅读 old9 翻译的 《On having layout》(如果无法翻越穿越伟大的 GFW,可阅读 蓝色上的转帖 )
快捷提示:如果触发了 haslayout,IE 的调试工具 IE Developer Toolbar 中的属性中将会显示 haslayout 值为 -1。
6、边框背景调试法
故名思议就是给元素设置显眼的边框或者背景(一般黑色或红色),进行调试。此方法是最常用的调试 CSS BUG 的方法之一,对于复杂 BUG 依旧适用。经济实惠还环保^^
最后想强调一点的是,养成良好的书写习惯,减少额外标签,尽量语义,符合标准,其实可以为我们减少很多额外的复杂 CSS BUG,更多的时候其实是我们自己给自己制造了麻烦。
The above is the detailed content of Detailed introduction to zoom attribute in css. For more information, please follow other related articles on the PHP Chinese website!