【发布时间】:2020-11-09 02:25:24
【问题描述】:
我正在尝试和我的朋友一起为电影之夜制作一个投票网站,但我对 html/css 不是很感兴趣。我使用 w3schools 和一些试验和错误来获得 5 个水平设置的单选按钮,文本居中位于各个按钮上方。
问题是中间按钮没有以框本身的标题居中。另一种理解方式是左边缘和第一个单选按钮之间的间隙与最后一个按钮和右边缘之间的间隙大小不同。
#but {
display: block;
margin-left: auto;
margin-right: auto;
text-align: center
}
#pair {
display: inline-block;
width: 20%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
<fieldset class="pollbox" style="white-space: nowrap;">
<legend align="center">Film Name</legend>
<div id="pair">
<label for="-2">Trash</label>
<input type="radio" name="filmname" value="-2" id="but">
</div>
<div id="pair">
<label for="-1">Dislike</label>
<input type="radio" name="filmname" value="-1" id="but">
</div>
<div id="pair">
<label for="0">Neutral</label>
<input type="radio" name="filmname" value="0" id="but">
</div>
<div id="pair">
<label for="1">Like</label>
<input type="radio" name="filmname" value="1" id="but">
</div>
<div id="pair">
<label for="2">Lush</label>
<input type="radio" name="filmname" value="2" id="but">
</div>
</fieldset>
【问题讨论】:
-
设置
float: left;并为#pair删除display: inline-block;。 -
谢谢@subarachnid,效果很好!你能解释一下这是做什么的吗?再次感谢!
-
@m4ge 嘿,快来看看我是否解决了你的问题,还是需要提高我的技能?