Add the lang attribute here in the body representation, Chinese is zh:
Now define another style for the div element: *:lang(en) #item{ background:green !important; }
This is done to overwrite the original css style with !important, because the :lang selector ie7.0 does not It is not supported, so it will not have any effect on this sentence, so the same effect is achieved under IE6.0. However, unfortunately, Safari does not support this attribute either, so the following CSS style needs to be added: #item:empty { background: green !important } : The empty selector is a CSS3 specification. Although Safari does not support this specification, this element will still be selected regardless of whether this element exists. The green color will now appear on all browsers except Internet Explorer.
For compatibility with IE6 and FF, you can consider the previous one!important Personally, I prefer the first one, which is simple and has better compatibility
What is browser HACK: When we use different browsers (Firefox IE7 IE6) to access the same website or page, there will be some incompatibility problems. Some display normally, and some display incorrectly. Normally, when we write CSS, we will be very annoyed. We just fixed the problem in this browser, but another browser has a new problem. HACK is a method that allows you to independently write styles that support different browsers in a CSS. Now there is harmony. hehe! powered by 25175.net
The compatibility of the IE7 browser recently released by Microsoft has indeed placed a heavy burden on some web page producers. Although IE7 has become standardized, there are still many differences from FF. So you need to use the HACK of IE7. Many friends have asked what the HACK of IE7 is, but I actually don’t know. I haven't found a specific HACK for IE7 yet. In addition to the previous article, the hack method in "CSS Style for Firefox IE6 IE7" is also very useful.
Anyone with a little bit of logical thinking will know that you can use IE and FF's HACK together. Here are three HACKs, for example: (Suitable for novices, haha, experts will pass by here.)
Program code
The first HACK is common to all browsers of IE FF (it is not actually a HACK) height:100px; The second HACK is exclusive to IE6 _height: 100px; The third HACK IE6 IE7 public *height:100px;
Now that we have introduced these three HACKs, let’s take a look at how to define IE6 for each attribute in a style IE7 FF-specific HACK, look at the following code, the order cannot be wrong:
Program code
height:100px; *height:120px; _height:150px;
Let me briefly explain how each browser understands these three attributes:
Under FF, FF does not recognize the second and third attributes, so it reads height:100px;
Under IE7, IE7 does not recognize the third attribute, so it reads the first and second attributes. And because the second attribute overwrites the first attribute, IE7 finally reads the second attribute. Attribute *height:120px;
Under IE6, IE6 recognizes all three attributes, so all three attributes can be read. And because the third attribute overwrites the first two attributes, IE6 finally reads it. is the third attribute.
1 css style for firefox ie6 ie7
Now most of them use !important to hack, and the test for ie6 and firefox can be normal Display, but ie7 can correctly interpret !important, which will cause the page not to be displayed as required! I found a good hack for IE7 using "* html". Now browse it with IE7. There should be no problem. Now write a CSS like this:
Then The font color is #333 under Firefox, #666 under IE6, and #999 under IE7.
2 Centering issues in css layout
The main style definitions are as follows:
body {TEXT-ALIGN: center;} #center { MARGIN-RIGHT: auto; MARGIN-LEFT: auto; }
Explanation:
First define TEXT-ALIGN: center in the parent element; this means that the content within the parent element is centered; for IE This setting is enough.
But it cannot be centered in mozilla. The solution is to add "MARGIN-RIGHT: auto;MARGIN-LEFT: auto; " when setting the child element definition
It should be noted that if you want to use this method to center the entire page , it is recommended not to wrap it in a DIV. You can split out multiple divs in sequence, as long as you define MARGIN-RIGHT: auto;MARGIN-LEFT: auto; in each split div.
#box{ float:left; width:100px; margin:0 0 0 100px; //In this case, IE will generate a distance of 200px display:inline; //Ignore floats}
Here we will explain in detail the two elements of block and inline, and the Block element The characteristics are: it always starts on a new line, and the height, width, line height, and margins can all be controlled (block elements); the characteristics of the Inline element are: it is on the same line as other elements,... cannot be controlled (inline elements) ;
#box{ display:block; //Can simulate inline elements as block elements display:inline; //Achieve the effect of arranging in the same row diplay:table;
5 IE Problems with width and height
IE does not recognize the definition of min-, but in fact it treats normal width and height as if there is min. This is a big problem. If you only use width and height, these two values will not change in a normal browser. If you only use min-width and min-height, the width and height are not set at all under IE. For example, if you want to set a background image, this width is more important. To solve this problem, you can do this:
Solution: Add 2 empty div objects above and below the P object. CSS code: .1{height:0px;overflow:hidden;} or add the border attribute to the DIV.
Block IE browser (that is, it will not be displayed in IE) *:lang(zh) select {font:12px !important;} /* FF, visible to OP*/ select:empty {font:12px !important;} /*visible to safari*/ Select here is the selector, which can be changed according to the situation. The second sentence is unique to the Safari browser on MAC.
Only recognized by IE7 * html {…} You can use this HACK when you need to make styles only for IE7.
Identification for IE6 and below * html {…} Pay special attention to this place. Many landlords have written that it is a HACK for IE6. In fact, IE5.x can also recognize this HACK. Other browsers do not recognize it. html/**/ >body select {……} This sentence has the same effect as the previous sentence.
Only IE6 does not recognize it select { display /*IE6 does not recognize it*/:none;} Here mainly separates an attribute and value through CSS comments, which are released before the colon.
Only IE6 and IE5 do not recognize it select/**/ { display /*IE6, IE5 does not recognize*/:none;} The difference here from the above sentence is that there is an extra CSS between the selector and the curly braces Note.
Only IE5 does not recognize it select/*IE5 does not recognize it*/ { display:none;} This sentence removes the comment in the attribute area from the previous sentence. Only IE5 does not recognize the
box model solution selct {width:IE5.x width; voice-family:""}""; voice-family:inherit; width:correct width;} The box model's clearing method is not handled via !important. This needs to be clear.
Clear float select:after {content:"."; display:block; height:0; clear:both; visibility:hidden;} In Firefox, when the children are all When floating, the height of the parent cannot completely cover the entire child. Then use this HACK to clear the floating to define the parent once, which can solve this problem.
Truncation ellipses select { -o-text-overflow:ellipsis; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; } This is after exceeding the length It will automatically cut off the excess text and end it with an ellipsis, which is a very good technique. It's just that Firefox doesn't support it currently.
Only recognized by Opera @media all and (min-width: 0px){ select {……} } Make separate settings for Opera browser.
The above are some hacks in writing CSS. It is recommended to follow the correct tag nesting (div ul li nested structural relationship), which can reduce the frequency of using hacks and avoid misunderstandings. It is not a The page requires a lot of hacks to maintain multi-browser compatibility). In many cases, the browser may work very well without even a single Hack. These are used to solve local compatibility problems. If you want to improve the compatibility The content is also separated, so you might as well try some of the filters below. Some of these filters are written in CSS to import special styles through filters, and some are written in HTML to link or import required patch styles through conditions.
Filter for IE5.x, only IE5.x is visible @media tty { i{content:"";/*" "*/}} @import 'ie5win.css' ; /*";} }/* */
IE5/MAC filter, generally not needed /**//*/ @import "ie5mac.css "; /**/
The following is the conditional comment of IE. I personally think that using conditional comments to call the corresponding Hack is a perfect multi-browser compatible solution. Put the places where hacks are needed separately. In a file, when the browser version is consistent, the Hacked style can be called. This is not only very convenient to use, but also for making the CSS itself, it can be more strictly observed whether it is necessary to use hacks. In many cases Next, when I write CSS, if I write all the code including Hack into a CSS file, it will be very casual. I can hack as much as I want. But when you write independently, you will unconsciously consider whether If it is necessary to hack, should you first hack the CSS? Or should you first adjust the things in the main CSS so that you don’t need to hack as much as possible? When you can make many browsers behave very well with just a few hacks, are you very surprised? Do you have a sense of accomplishment? Do you know how to choose~~ Haha
IE’s if condition Hack can be used flexibly. Please refer to this IE condition note Only IE All IE can recognize it
Only IE5.0 can recognize Only IE 5.0 IE5.0 can be recognized by IE5.5
Only IE6 can recognize Only IE 7/- Can be recognized by IE6 and IE5.x below IE6 Only IE 7/- Only IE7 can be recognized
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn