Solve browser compatibility problems

Source: Internet
Author: User

Anyone who uses Div + CSS to build a website must be aware of CSS compatibility issues. Today, I will teach you five ways to solve the problem of browser compatibility.
The reason for CSS incompatibility is that the default CSS attribute values are different in different browsers.
First: Specify the attribute value for common CSS.
Body, Div, DL, DT, DD, ol, H1, H2, H3, H4, H5, H6, form, input, P, Th, TD {margin: 0; padding: 0 ;}
IMG {border: 0px ;}
Ul {margin: 0px; padding: 0px ;}
Ul Li {list-style: none ;}
The common code for the above website creation is to format the CSS style, so that various browsers can render the webpage according to the attribute values we set.
Second: the problem of centering objects in IE and FF
In IE, you should know that you only need to set body {text-align: center;} to center the display.
However, this method does not work in ff. Here, you need to change it to body: {text-align: center; margin: 0px auto;} margin, which means that the upper and lower distance is 0 pixels and the left and right are automatic. So FF is centered.
Third move: vertical center (only for one row)
For example, if a div with a height of 30px is displayed in the upper left corner by default, you can add a line-Height: 30px to it if you want to center vertically. If you want him to go down, modify line-Height: 30px. The larger the value, the higher the score, the overflow: hidden style; (the excess part is not displayed)
Step 4: set three styles for each block object
Width: ** PX; Height: ** PX; overflow: hidden; you must set these three styles even if the height and width indicate that the attribute values are automatic. The purpose is to solve the problem of default browser values.
Fifth: CSS styles for IE6, IE7, and FF (this method is often used in special cases)
Previously, the website was frequently used! Important to set priority, but it won't work after IE7. The following is a solution for solving the CSS priority of IE6, IE7, and ff.
#1 {color: #333;}/* FF environment */
* Html #1 {color: #666;}/* IE6 environment */
* + Html #1 {color: #999;}/* IE7 environment */
The order of writing must not be changed.
In this way, the webpage is displayed under FF #333, IE6 #666, and IE7 #999;

Have you learned?

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.