margin-top和top到底什么区别!!!!!
<style>.div1{border:1px red solid;width:200px;height:100px;position:absolute;color:#FFFFFF;background:#33CCFF;}.div2{border:1px red solid;width:200px;height:100px;position:relative;background:#000000;color:#FFFFFF;margin-top:100px; //这里top:100px 的话div2就往下,如果 margin-top:100px;的话 ,为什么div1也会跟着往下}</style><body><div class="div1">div1</div><div class="div2">div2</div></body>
margin-top指页边空白
top 一般用于绝对定位
举例给你看:
margin
margin-top refers to the margins of the page
top is generally used for absolute positioning
Correct answer
Someone has solved it!
Let me give you an example:
Can anyone tell me? What is relative between margin and top? What is absolute?
For example, div2 is position:relative;
Then its margin-top: 100 is relative.
Then its top: 100 is absolutely What is absolute
Who can tell me what margin is relative to top and what is absolute
For example, div2 is position:relative;
Then his margin-top: 100 is relative What is relative
Then his top: 100 is absolutely what
position: relative is relative positioning. Also, when writing css, it is best to bring the unit px. This is a bad habit.
Saying it means not saying it. I just want to know that div2 is relative, why does it have margin-top: 100px? div3 will also move down instead of moving down relative to div3
.div3{ width:300px; height:300px; background:#999; border:1px solid #666; position:relative;}
Because div3 does not have a border set
Why does this happen without a border set! I’m dizzy
Oh, I understand. Does anyone have a document that explains this relative position and absolute position? I am confused by the style
I still have a question: Does margin-left:100 div3 not move with div2? Why
http://www.hicss.net/use-margin-or-padding/
The poster should learn the basics of css
margin-top refers to the page margin Blank
top is generally used for absolute positioning
This
I still have questions about margin-left:100 div3 will not move with div2? Why
div3 is the parent layer of div2
The left margin of div2 is based on the left margin of the parent layer
So div3 will not move
Quote from the 3rd floor's reply:
Example Here you go:
margin-top: is the distance between the content and the border
top: is the distance between the content and the content
margin-top is for setting the outer margins
top is for positioning
Learn html The div css can be found here http://blog.sina.com.cn/u/2760399482