
[英]Why don't margin-top: auto and margin-bottom:auto work the same as their left and right counterparts?
[英]Why does margin-right not work, but margin-left, margin-top and margin-bottom do?
当我设置margin-right:50px; 我没有看到任何影响,但是当我更换边距时:50px; 保证金左:50px; 或margin-top:50px; 我确实看到了效果。 这是具有保证金权限的代码......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Max Pietsch homepage</title>
<style type="text/css">
.me {
margin-right: 20px;
}
#pic_of_me {
width: 200px;
}
</style>
</head>
<body>
<div class="me">
<img id="pic_of_me" src="me.jpg" alt="A picture of me">
</div>
</body>
默认情况下, Html元素始终在其父元素的左上角分配 。
因此,您的.me
被放置在body
元素的左上角。
如果你添加一个margin-top
或margin-left
你的.me
“将”自己推离这个角落(这就是你看到它移动的原因)。
如果你在元素的右边/下面添加一个margin-right
或margin-bottom
其他元素将被“推”掉。
由于元素右侧/下方没有任何元素,因此无法看到此效果。
试试看!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.