Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use important to solve the css compatibility between firefox and ie

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use important to solve the css compatibility problem of firefox and ie". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use important to solve the css compatibility problem of firefox and ie".

For some layers with variable content (such as user comments), we want it to have a minimum height (such as 30px), so that even if the content is only one line, it will not be too ugly; at the same time, we hope that when there is more content, the height of the layer can be automatically extended, that is, it requires height: auto. At this point, you can set the min-height property of css. Min-height is valid in Firefox, but IE does not recognize it. You can use the following solution:

The code is as follows:

.div _ class {

Min-height:30px

Height:auto! important

Height:30px

}

The first line setting min-height:30px; is valid for Firefox; the second line height:auto! important; is also valid for Firefox, followed by "! important" is a Firefox-specific flag, settings with this flag have the highest priority, and subsequent settings have no effect. So the third line of height:30px is not valid for Firefox; at the same time, because IE does not recognize min-height and "! important", only the third line is valid, because IE is highly adaptive by default, so even if you set the height of 30px, as long as there is a lot of content, it will automatically open, there is no need to set height:auto. Finally, the above code produces the following effect:

For Firefox, it is equivalent to:

The code is as follows:

.div _ class {

Min-height:30px

Height:auto

}

For IE, it is equivalent to:

The code is as follows:

.div _ class {

Height:30px

}

"! important" is a very easy thing to use, and if you've written cross-browser CSS code for months, it's easy to get annoyed by the difference between Firefox and IE. For example, the padding property is an example.

Suppose such a layer:

The code is as follows:

.div _ name {

Width:100px

Padding:10px

}

In IE, the width of the layer is 100px, and the space around it is 10px; but for Firefox, the width of the layer becomes 100px+10px+10px=120px, which is messy for width-sensitive designs. What should I do? Turn to "! important" for help. Just write like this:

The code is as follows:

.div _ name {

Width:80px! important

Width:100px

Padding:10px

}

Because 80'10'10 '100. Just enough to make the width 100px.

Sometimes, we add a border to a layer, and the width increases in the Firefox, such as:

The code is as follows:

.div _ name {

Width:100px

Padding:10px

Border:2px solid # ccc

}

In the upper layer, the actual width in Firefox is equal to 100+10+10+2+2=124px, because the border also increases the width. What are we going to do? just rely on "! important" and write it like this:

The code is as follows:

.div _ name {

Width:76px! important

Width:100px

Padding:10px

Border:2px solid # ccc

}

Thank you for your reading, the above is the content of "how to use important to solve the css compatibility problem of firefox and ie". After the study of this article, I believe you have a deeper understanding of how to use important to solve the css compatibility problem of firefox and ie. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 278

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to realize the escape of greater than less sign by myBatis

    This article mainly introduces myBatis how to achieve greater than less than sign escape, the article introduces in great detail, has a certain reference value, interested friends must read it! Escape

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report