Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of transferring and folding up and down margin in CSS

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "the transmission and folding method of upper and lower margin in CSS". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1.margin-top transfer

Why does the upper margin pass?

If the top line of the block-level element overlaps the top line of the parent element, the margin-top value of the block-level element is passed to the parent element.

Sample code: set margin-top: 20px; for the inner box.

.reference {

Width: 100px

Height: 100px

Background-color: # f00

Color: # fff

}

.box {

Width: 200px

Height: 200px

Background-color: # 0f0

}

.inner {

Width: 100px

Height: 100px

Background-color: # 00f

Margin-top: 20px

}

Reference box

The value of margin-top for inner is passed to box.

2.margin-bottom transfer

Why does the lower margin pass occur?

If the bottom line of the block-level element overlaps the bottom line of the parent element, and the height of the parent element is auto, then the margin-bottom value of the block-level element is passed to the parent element.

Sample code: set margin-bottom: 20pxscape for the inner box and height: auto; for the parent element.

.box {

Width: 200px

Height: auto; / * sets the height of the parent element to auto, or no height. The default is auto * /

Background-color: # 0f0

}

.inner {

Width: 100px

Height: 100px

Background-color: # 00f

Margin-bottom: 20px

Color: # fff

}

.reference {

Width: 100px

Height: 100px

Background-color: # f00

Color: # fff

}

Inner

Reference box

The value of margin-bottom for inner is passed to box.

This is the end of the introduction of "the method of passing and folding up and down margin in CSS". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report