[英]Allign div with margin-left and margin-right
I have a div element with a css like this 我有一个像这样的CSS的div元素
div.details {
float:right;
margin-right:50px;
margin-left:50px;
} }
however this only keeps the margin from the right. 但是,这仅使右边距保持不变。 how can I align the div 50px both from left and right
我如何从左和右对齐div 50px
It does add margin in both the sides, but since you're floating it to the right, you're able to see only the right margin. 它确实在两侧都增加了边距,但是由于您将其向右浮动,因此您只能看到正确的边距。 If you see another element pushing into this element's left margin, that could be because of some other css.
如果您看到另一个元素推入该元素的左边距,则可能是由于其他一些CSS。 Can you post a jsfiddle in that case?
在这种情况下,您可以发布jsfiddle吗?
Florin Pop's answer is good if you want to align the div to the center. 如果要将div对准中心,Florin Pop的答案很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.