html - 位置 div margin top 30px 但使用 margin auto 将 margin 保持在中心?

标签 html css margin

我在让我的 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/

相关文章:

javascript - 在 javascript 变量中查找类

javascript - jQuery - 如何创建可撤消的操作?

html - 表格内有非白色背景奇怪的边框

html - 将背景图像放入带有伪元素的形状中

html - Bootstrap 4 中的表格列宽

html - 颜色透明在 IE 中不起作用

html - Bootstrap 行 : get cols within row to be centered?

css - 如何禁用边距折叠?

html - css margin : auto issue in footer

html - margin-top 清除值 : left