我发现了一种将输入和标签元素作为 Accordion 查看器的方法。
为了使我的元素垂直居中,我使用标签,就好像它是一个 div,也就是说,给它 display:table
并在其中创建一个 div。
所以我有:
<div>
<input id='myid'>
<label for ='myid' style='display table'>
<div style='display:table-cell'>
<img ....... >
thetextforthelabel
</div>
</label>
</div>
好的,这很好。
我的问题是:我是否在做“禁止”的事情? 我可以将 label 标记用作容器吗?
我知道它可能不正统..但它对我有用...
最佳答案
您的代码无效。
问题是 div
元素只能使用
Where flow content is expected.
然而,content model的 label
元素是
Phrasing content, but with no descendant labelable elements unless it is the element's labeled control, and no descendant
label
elements.
无论如何,它可能会起作用,因为(与例如 p
元素不同)不能省略 label
元素的结束标记:
Neither tag is omissable
但是,我不确定具有单个单元格的表格元素的优势。考虑改用以下内容:
<div>
<input id='myid'>
<label for='myid' style='display:block'>
<img ....... >
thetextforthelabel
</label>
</div>
关于html - 我可以 'style' 并将标签用作 'normal' 元素吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28094166/