[英]margin values not working for a div with float none property
I wanted to center a div. 我想将div居中。 i did so with margin and float property..but the margin values is not working properly
我这样做是用margin和float属性..但是保证金值不能正常工作
.body { width: 100%; float: left; } .content { width: 70px; margin: 10px auto 10px auto; float: none; border:1px solid red; } .content p{float:left;margin:0;}
<div class="body"> <div class="container"> <div class="content"><p>hello all<p></div> </div> </div>
here the margin top and bottom values(ie 10px) is not working properly..margin bottom value is commencing from the top which should have from the bottom! 这里的margin顶部和底部值(即10px)无法正常工作。.margin底部值从顶部开始,应该从底部开始!
It's best not to center with float as it takes the element out of the normal document flow. 最好不要以float为中心,因为它将元素从普通文档流中移出。 Center with margin 'auto' instead.
改为以“自动”边距为中心。
HTML 的HTML
<div class="body">
<div class="content">hello all</div>
</div>
CSS 的CSS
.body{
width: 100%;
}
.content{
display:block;
width: 70px;
margin: 10px auto;
}
You can try : 你可以试试 :
body{
margin:0px;
}
.container{
width: 100%;
}
.content{
display:block;
width: 70px;
margin: 10px auto;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.