CSS---Solutions for internal div settings Margin-top not working

Source: Internet
Author: User
About the inner div setting margin-top does not work solution

The code is as follows:

<div> Upper Layer </div>

<div> <!--parent Layer--
<div style= "margin-top:200px;" > Sub-layer </div>
</div>

The ideal effect is the parent layer and the upper layer of the welt display, the child layer is 200px away from the top of the parent layer, normal in IE, but there is a problem in the FF, the child layer and the parent layer is facing, but the parent layer and the upper layer are spaced 200px.

Think of the solution, to help Google, get the following sentence:

When two containers are nested, if there is no other element between the outer container and the inner container, Firefox will margin-top the inner element with the parent element.

That is, because the child layer is the first non-empty element of the parent layer, this error occurs when you use Margin-top.

There are two ways to solve this problem:

1, using floating to solve, will be the sub-layer code to: <div style= "Margin-top:200px;float:left";> sub-layer </div>

2, use Padding-top to solve, namely:

<div style= "padding-top:200px;" >
<div> Sub-layer </div>
</div>

CSS---Solutions for internal div settings Margin-top not working

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.