【发布时间】:2021-05-21 19:49:22
【问题描述】:
假设我有一个按钮:
HTML
<input type="button" class = "button" value="Click here"
CSS
.button {
height: 300px;
width: 300px;
这个按钮会很大,我不想把文本放在中间,我想把它放在中间顶部。我该怎么做?
【问题讨论】:
-
文本对齐 + 行高
假设我有一个按钮:
HTML
<input type="button" class = "button" value="Click here"
CSS
.button {
height: 300px;
width: 300px;
这个按钮会很大,我不想把文本放在中间,我想把它放在中间顶部。我该怎么做?
【问题讨论】:
不要使用heightwidth,而是使用padding
padding: 0px 150px 300px 150px;
【讨论】:
padding: 0px 150px 300px 150px; background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/30876/css-button.png); background-repeat: no-repeat;
你可以根据你给按钮的高度使用 text-align 和 line-height
【讨论】:
试试这个:
input {
width: 300px;
height: 300px;
flex-direction: column;
align-items: center;
}
如果你想从顶部添加一些间隙,你可以添加 padding-top。
【讨论】:
如果我正确理解您的问题,您可以对.button 使用 flex 规则。
.button {
display: flex;
flex-direction: column;
align-items: center;
height: 300px;
width: 300px;
}
<input type="button" class = "button" value="Click here">
【讨论】:
<button><p>text</p></button> ?
我认为您可以添加一些填充以使文本更低
【讨论】: