以下是我的代码:
#myTable {
float: left;
vertical-align: middle;
}
p {
float: left;
vertical-align: middle;
}
<div id="container">
<p>
Title
</p>
<table id="myTable">
<tr>
<td>
<input name="input1" id="input1" type="radio" value="1">
<label for="input1">No</label>
</td>
<td>
<input name="input2" id="input2" type="radio" value="2">
<label for="input2">Yes</label>
</td>
</tr>
</table>
</div>
问题是p
和table
不能垂直排列。我该如何解决?
答案 0 :(得分:1)
您可以更改p标签的页边空白
p {
float: left;
vertical-align: middle;
margin-top:5px;
}
https://jsfiddle.net/viethien/gjwms4n1/4/
已更新:
您可以删除左浮动并使用display:inline-block
#myTable {
display:inline-block;
vertical-align: middle;
}
p {
display:inline-block;
vertical-align: middle;
font-size: 24px;
}
答案 1 :(得分:1)
如果您可以摆脱浮点数(这可能真的很有用),则将两个元素都视为 inline-blocks / inline-tables ,如下所示:
#myTable {
display: inline-table;
vertical-align: middle;
}
p {
display: inline-block;
vertical-align: middle;
}
#myTable {
display: inline-table;
vertical-align: middle;
}
p {
display: inline-block;
vertical-align: middle;
}
<div id="container">
<p>
Title
</p>
<table id="myTable">
<tr>
<td>
<input name="input1" id="input1" type="radio" value="1">
<label for="input1">No</label>
</td>
<td>
<input name="input2" id="input2" type="radio" value="2">
<label for="input2">Yes</label>
</td>
</tr>
</table>
</div>
答案 2 :(得分:0)