CSS将按钮宽度调整为文本
我的按钮宽度有问题。我的表单可以切换语言。对于某些语言,按钮的内容比按钮宽度长,如何根据文本长度适当调整按钮宽度? 这是我的CSS:CSS将按钮宽度调整为文本,css,Css,我的按钮宽度有问题。我的表单可以切换语言。对于某些语言,按钮的内容比按钮宽度长,如何根据文本长度适当调整按钮宽度? 这是我的CSS: html .formRowSubmit input[type="submit"] { width: 26%; margin: 5px 0% 5px ; margin-bottom: 10px; height: 25px; border-radius: 3px; outline: 0; -moz-outline-style: none;
html .formRowSubmit input[type="submit"] {
width: 26%;
margin: 5px 0% 5px ;
margin-bottom: 10px;
height: 25px;
border-radius: 3px;
outline: 0;
-moz-outline-style: none;
background: #CAD722;
border: none;
color: white;
font-size: 10px;
font-weight: 150;
cursor: pointer;
transition: box-shadow .4s ease;
}
将按钮显示为内联块(并删除宽度) 如果文本靠近边框,您可能需要添加一些填充。尝试如下: CSS: HTML:
您应该尝试设置
最小宽度,而不是宽度,这将使按钮在需要时展开。完成此操作后,还应设置一些水平填充,以使文本不会像这样对接到末端:
input[type="submit"] {
min-width: 26%;
padding: 5px 15px;
}
使用html.formRowSubmit输入[type=“submit”]{width:auto}谢谢,它可以工作!我还用padding调整了padding:0 10px 0 10px;谢谢,这是我需要的。但您是垂直填充,而不是水平填充;)您应该填充:0 5px 0 5px;这是最好的解决办法。因为我只需要在文本较长时进行调整。谢谢大家
.formRowSubmit input[type="submit"] {
width: auto;
margin: 5px 0% 5px;
margin-bottom: 10px;
height: 25px;
border-radius: 3px;
outline: 0;
-moz-outline-style: none;
background: #CAD722;
border: none;
color: white;
font-size: 10px;
font-weight: 150;
cursor: pointer;
transition: box-shadow .4s ease;
}
<div class="formRowSubmit">
<input type="submit" value="Submit loooong llloooonnnng text">
</div>
input[type="submit"] {
min-width: 26%;
padding: 5px 15px;
}