Use!important to solve the layout difference between IE and Mozilla _css/html

Source: Internet
Author: User

In the design of "web designer" page, there is a problem has been bothering me, the main menu in IE and other (Mozilla, opera, etc.) browser shows the effect of 2px deviation. Screenshot below:

The effect in IE

The effect in Mozilla Firefox

This is due to the bug caused by IE's explanation of the distance between the boxes (refer to Onestab's "floating model Problem"). I have not solved this problem until I translate "Table vs css--a Battle of life and Death", the author of a tip helped me find a solution: with!important.

!important is the syntax defined by CSS1 to increase the application priority of the specified style rule (see: W3.org's Interpretation). Syntax format {srule!important}, which is written on the last side of the definition, for example:

Box{color:red!important;}

The most important point is that IE does not support this syntax all the time, while other browsers support it. So we can use this to give IE and other browsers different style definitions, for example, we define a style like this:

. colortest { 
border:20px solid #60A179!important;
border:20px solid #00F;
padding:30px;
width:300px;
} 

When browsing in Mozilla, you can understand the!important priority, so show the color of the #60a179:

When browsing in IE, it is not possible to understand the priority of!important, so the color of the #00f is displayed:

As you can see, with!important, we can set different styles for IE and non ie browsers, as long as we add!important to the back of the non IE browser style. Therefore, the above mentioned my homepage 2px the display difference also easily solves:

PADDING-TOP:11PX!important;
padding-top:9px;

!important must become a tool for CSS layout, please remember and master it:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.