【发布时间】:2017-01-04 05:29:09
【问题描述】:
我正在构建一个带有我想居中的表单的页面,但是我无法使用自动填充或边距来实现这一点(尽管我给了表单一个固定宽度)。
这是我的 HTML 结构:
<div class = "parent row">
<div class = "child1 row">
<form>
<legend>
Inputs goes here
</legend>
<legend>
Inputs goes here
</legend>
</form>
</div>
<div class = "child2 row">
<form>
<legend>
Inputs goes here
</legend>
<legend>
Inputs goes here
</legend>
</form>
</div>
</div>
我正在使用骨架网格系统,并且我有一个父级 div 代表一个 row 并且有两个子级:两者都有一个带有 fieldset 的表单。
我尝试为它们中的每一个赋予固定宽度并使用 padding-auto 和 margin-auto ,但它不起作用。
这里是样式代码(使用 SCSS):
form{
max-width: 400px;
min-width: 250px;
margin-left: auto;
margin-right: auto;
width: 350px;
}
legend,fieldset{
border: 1px grey solid;
max-width: 400px;
padding: 0 25%;
margin-left: auto;
margin-right: auto;
width: 350px;
h4{
background-color: $primary-blue-color;
color: white;
margin-bottom : 40px;
}
input{
margin: 5px;
}
}
在小屏幕上,父 div 居中,但在大屏幕上不会。它以标准方式对齐(从左至右)。
我怎样才能使那个 div 和它的所有子元素在所有类型的屏幕上居中?
【问题讨论】:
-
请在较小的屏幕上发布当前居中该行的 css sn-p。
-
你想要垂直居中吗?
-
@DeepakBandi 不,我想垂直居中