我在想如何让一些按钮垂直堆栈,而不是在CSS水平。垂直堆栈按钮
因此,HTML是这样的:
<button>Test<button>
<button>Test<button>
<button>Test<button>
而且这些按钮将通过水平默认堆栈,我要的是让他们垂直堆叠(所以每个人的下一步按钮的顶部)。
我在想如何让一些按钮垂直堆栈,而不是在CSS水平。垂直堆栈按钮
因此,HTML是这样的:
<button>Test<button>
<button>Test<button>
<button>Test<button>
而且这些按钮将通过水平默认堆栈,我要的是让他们垂直堆叠(所以每个人的下一步按钮的顶部)。
定义按钮为块级元素。另外,还要注意使用正确的结束标记(</button>
):
button {
display: block;
}
<button>Test</button>
<button>Test</button>
<button>Test</button>
谢谢!它的工作,但现在他们不集中,做任何方式吗? –
@OscarArranz给按钮一个宽度,然后使用'margin:0 auto'。 – BenM
您可以使用'margin:0 auto''0作为(左右)(左右)自动 –
<buttons>
默认情况下是内嵌块元素。您可以通过造型的显示器来阻止,而不是改变:
button {
display: block;
}
<button>Test</button>
<button>Test</button>
<button>Test</button>
为此,您可以与您的css
button {
display: block;
}
,因为他们已经如上所述,buttons
元素皆预设inline
显示属性。你需要做display: block;
来实现你想要的结果:
p{
font-family: arial;
font-weight: bold;
}
.button{
background-color: #2a609a;
\t width: 130px;
\t height: 60px;
color: white;
outline: none;
font-size: 16px;
border: none;
cursor: pointer;
}
.block-display button{
margin-bottom:5px;
display:block;
}
.button:hover{
background-color: #32CD32;
font-size: 20px;
transition: 0.5s;
}
<div class="default-display">
<p> buttons with defualt display: </p>
</br>
<button class="button">Button 1 </button>
<button class="button">Button 2 </button>
<button class="button">Button 3 </button>
</div>
</br>
<div class="block-display">
<p> buttons with block display: </p>
</br>
<button class="button">Button 1 </button>
<button class="button">Button 2 </button>
<button class="button">Button 3 </button>
</div>
添加'键{显示:块; ''到你的CSS。按钮默认是'inline'元素,如果可能的话,它们将保持在同一行。另一方面,“块”元素(如div)将被强制转换为新行。 **作为一个单独的说明**,请在提问之前做一些调查 - 快速搜索发现大量重复。 – Santi