Solving the problem of child element margin changing with the parent element location

Source: Internet
Author: User

1. Add content inside the parent element, and add it before the child element block, and add the content after it is invalid.

Content can be text, pictures or even spaces, the source code directly by the space is invalid, you can use the placeholder  


2. Let the child element or parent element float Float:left.

Disadvantage: In cases where the element cannot be used in a float


3. To add a border to the top of the parent element, you can set the border as transparent: border-top:1px solid transparent.

Disadvantage: Although it is transparent, but also more than 1px of the occupying position, the general accuracy requirements are not high, 1px can be ignored.


4, let the child element or the parent element absolute position: Position:absolute.

Disadvantage: In cases where an element cannot be absolutely positioned


5, let the parent element Overflow:hidden.

Cons: Elements cannot be used in overflow:hidden cases.

To summarize, it is relatively perfect to add placeholders   and Overflow:hidden.

Solving the problem of child element margin changing with the parent element location

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.