好的,这是一张桌子,我相信您会问的。
我想不出预先选择以下p元素的任意宽度会带来问题的情况。 如果您想要的元素小于输入框(最小宽度),则没问题,并且无论如何也不会更改大小。
但是,如果您想添加一个比输入框大的description元素(并且会增加单元格的宽度),或者想要添加内容,那么该单元格无论如何都会增长。
我认为,在不知道您将拥有的所有要素的情况下,很难说出真相。 在评论中,您还提到了单选按钮。 我将为每种类型的输入设备(框,单选按钮,True / False选择,滑块,下拉框)添加一个不同的类,并为每个输入设备设置唯一的固定宽度。
但是,到那时,实际上可能更容易(用LOC减少)在JavaScript中完成。 我无法推测在那里,因为我不太了解JavaScript。
This is a super long label to show that the table can grow. | |
Another Label | Delete this text to see that non "p" description text will still make the table shrink or grow. This is a fixed-width description with the same length as the input element above. |
A Third Label | This text gets to expand the cell. Another test example. |
CSS:
table {
border: 1px solid black;
}
.right-col p {
margin: 0;
width: 150px;
color: red;
}
input[type=radio] ~ p {
margin: 0;
width: 25px;
color: blue;
word-wrap: break-word;
}