gpt4 book ai didi

css - 将位置为 : absolute in IE11 in a table 的输入元素居中

转载 作者:行者123 更新时间:2023-11-28 15:23:15 24 4
gpt4 key购买 nike

我无法理解为什么 IE11 在使用 position: absolute 时没有记住 text-align: center。我创建了一个 JS fiddle 。基本上我有两个复选框,我希望它们在表格单元格的中心相互堆叠。

table {
width:100%;
height: 50px;
text-align: center;
}

#box1 {
position: absolute;
}
<table>
<tr>
<td>test</td>
<td>
<input id="box1" type="checkbox">
<input id="box2" type="checkbox">
</td>
<td>test</td>
</tr>
<tr>
<td>test</td>
<td>test</td>
<td>test</td>
</tr>
</table>

https://jsfiddle.net/3f5993oc/这适用于 chrome,但不适用于 IE。我正在寻找一种适用于两种浏览器的解决方案。感谢您的帮助。

最佳答案

对于IE,你需要使用position:relative/absolute,坐标和重置margin

table {
width: 100%;
height: 50px;
text-align: center;
}

td {
position: relative;
}

#box1 {
left: 0;
right: 0;
margin: 0.175em auto;
position: absolute;
}
<table>
<tr>
<td>test</td>
<td>
<input id="box1" type="checkbox">
<input id="box2" type="checkbox">
</td>
<td>test</td>
</tr>
<tr>
<td>test</td>
<td>test</td>
<td>test</td>
</tr>
</table>

关于css - 将位置为 : absolute in IE11 in a table 的输入元素居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45698728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com