我在让我的 div 将我的页面向下移动 30 像素/在我的 div 顶部添加边距 30 像素时遇到问题。我的 div 使用 margin auto 在页面中心对齐。
然而,当我尝试添加这行代码时: 边距:30px auto 0 auto;
没有显示上边距?请有人告诉我我做错了什么吗?谢谢,
#content_other{
width:790px;
height: auto;
font-family: 'Arial Narrow', Tahoma, Verdana, Arial Narrow, sans-serif;
font-size:12px;
margin: 30px auto 0 auto;
position:relative;
overflow: hidden;
padding:20px;
background:#fff;
border: 1px solid #999;
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
-moz-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
html:
<div id="content_other">
<html form here>
</div>
最佳答案
您的代码没有任何问题。 看看这个JSFiddle .边距添加到顶部 我使用了这个 HTML
<div id="content_other">
<form>
<input type="text" />
</form>
</div>
关于html - 位置 div margin top 30px 但使用 margin auto 将 margin 保持在中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29255612/