[英]How do I have fieldset::before rule account for the legend?
I'm placing content in ::before rules on each of the fieldsets in my form, but they seem to be placed under the legend of the field, not as the first child like I would expect. 我在表单中的每个字段集上将规则放在:: before规则之前,但它们似乎放在该字段的图例下,而不是我期望的第一个孩子。 I would like to have the ::before content justified with the top of the legend, not the top of the input elements.
我想让:: before内容与图例的顶部对齐,而不要与输入元素的顶部对齐。 It isn't enough to shift the ::before content vertically across the board because my legends are different heights.
仅在整个面板上垂直移动:: before内容是不够的,因为我的图例的高度不同。 Does anyone know why this is happening and how to get the behavior I want?
有谁知道为什么会这样以及如何获得我想要的行为?
Expected behavior: 预期行为:
before legend
legend
legend
input
HTML: HTML:
<form>
<fieldset>
<legend>This is the legend.</legend>
<input type="text" />
</fieldset>
<fieldset>
<legend>This is a very very very very very very very very very very very very very very very very very very very very very long legend.</legend>
<input type="text" />
</fieldset>
</form>
CSS: CSS:
fieldset
{
margin-left: 40px;
width: 120px;
}
fieldset::before
{
margin-left: -40px;
float: left;
content: "before";
}
http://jsfiddle.net/GYzTA/2/ http://jsfiddle.net/GYzTA/2/
EDIT: 编辑:
I found a "doh" solution of just changing the CSS selector, but I'm still curious why the fieldset::before rule seems to insert the content after the legend. 我找到了一个仅更改CSS选择器的“ doh”解决方案,但我仍然很好奇为什么fieldset :: before规则似乎将内容插入图例之后。
fieldset legend::before
{
margin-left: -40px;
content: "before";
}
Referencing Default CSS values for a fieldset <legend> 引用字段集<legend>的默认CSS值
Simply put, it is not possible across browsers to position the LEGEND element in a Fieldset.
简而言之,跨浏览器不可能将LEGEND元素放置在Fieldset中。
Solution: Use <span>
instead of <legend>
解决方案:使用
<span>
而不是<legend>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.