The golden rule of writing Cross-browser-compatible CSS code

Source: Internet
Author: User
Tags relative

As a web designer, your site has exactly the same performance in a variety of browsers as the goal of many people, however, this is a goal that can never be truly achieved, and many people think that perfect cross-browser compatibility is not necessary, although it is true, in many cases, an approximate compatibility is easy to implement, This article is about a variety of Cross-browser compatible CSS coding guidelines and techniques.

Understanding CSS Box Models

If you want to implement Cross-browser-compatible CSS code that doesn't require a lot of Kit Kat, a thorough understanding of the CSS box model is the first thing, and the CSS box model is not difficult and basically supports all browsers, except for some specific conditions in IE browsers.

The CSS box model is responsible for handling the following things:

    • How much space is occupied by a BLCOK (block) Level object
    • The bounds of the object, leaving the white
    • The size of the box
    • The relative position of the box and other elements of the page

The CSS box model has the following guidelines:

    • Block (chunk) objects are rectangles (in fact, all objects are)
    • Its dimensions are determined by width, height, padding, borders, and margins.
    • If you do not set the height, the height of the box will automatically adapt to its contents, plus white, etc. (unless you use float)
    • If you do not set the width, a non-float box will be filled with its parent container horizontally (minus the parent container's white-left)

When working with block-level objects, you must be aware of the following considerations:

    • If the width of a box is set to 100%, it can no longer set margins, padding, and borders, or it will burst its parent container
    • Vertically adjacent margin can cause complex collapse problems, resulting in layout problems (such as two vertically adjacent block objects with Bottom-margin 40 on them, and the following objects with a top-margin of 20), and two objects with a spacing of 40 instead of 60- Translator
    • object with relative position and absolute position, with different behavior


The box model shown in Firefox's Firebug

Understand the difference between block-and inline-level objects

This seemingly simple problem can be greatly appreciated if it is thoroughly understood.

The following figure explains the difference between block-level objects and inline-level objects:

Related Article

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.