Negative margin usage notes: negative margin usage Problems

Source: Internet
Author: User

Negative margin usage notes: negative margin usage Problems

Negative margin is often used in project strength, for example:

<Div id = "test"> <ul> <li> child element 1 </li> <li> child element 2 </li> <li> child element 3 </li> <li> child element 4 </li> <li> child element 5 </li> <li> child element 6 </li> </ul> </div>
Is the implementation effect:

To ensure css compatibility with ie 6, you need to add a style to the floating li inclusion layer ul.

position: relative;zoom: 1;

At this time, ul should not use clearfix to clear the floating head, ie6 will fail.




Negative value of CSS margin-top

The negative value of margin, called the negative outer patch, can be negative in all four directions, that is, to narrow the periphery of the container. Usually used with position.

For example, a horizontal absolute center is used.

# Box {width: 960px; height: 50px; margin-left:-480px; padding: 0; position: absolute; left: 50%; top: 0; z-index: 16 ;}

Here we use margin-left:-480px;, which is the half width of the container and is absolutely centered.

Of course, there are still a lot of negative patch usage, You can google.

It has nothing to do with compatibility. It depends on you to adjust your css code to achieve compatibility.

Ask a question about the use of margin in CSS

If a value is directly added after margin, it is in the order of left, top, right, and bottom.
So margin: 0-170px 0 0 is equivalent
Margin-left: 0px;
Margin-top:-170px;
Margin-right: 0px;
Margin-bottom: 0px;
If the value is 0, no unit is allowed.

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.