简体   繁体   English

字段集中图例标签的位置是否重要?

[英]Does the position of legend tag within fieldset matter?

I have a fieldset as below:我有一个字段集如下:

<fieldset>
    <legend>Colour</legend>
    <label><input type="radio" name="colour" value="blue"> Blue </label>
    <label><input type="radio" name="colour" value="red"> Red </label>
</fieldset>

Here if I keep the legend tag below all the label tags, the HTML renders the fieldset exactly same as before.在这里,如果我将legend标签保留在所有label标签下方,则 HTML 呈现的fieldset与以前完全相同。

<fieldset>
    <label><input type="radio" name="colour" value="blue"> Blue </label>
    <label><input type="radio" name="colour" value="red"> Red </label>
    <legend>Colour</legend>
</fieldset>

Even this renders the same.即使这样也一样。

So question here is, whether it is programmatically correct and as per standards to write legend tag at any place within fieldset .所以这里的问题是,在fieldset任何地方编写图例标签是否在编程上是正确的,是否符合标准。

So question here is, whether it is programmatically correct and as per standards to write legend tag at any place within fieldset .所以这里的问题是,在fieldset任何地方编写图例标签是否在编程上是正确的,是否符合标准。

No, it is not.不,它不是。 The legend element (if present) must be the first child of a fieldset element. legend元素(如果存在)必须fieldset元素的第一个子元素。


This is what the HTML5 spec.这就是HTML5 规范。 says:说:

4.10.15 The fieldset element 15年4月10日的fieldset元素
[...] [...]

Content model : 内容模型

Optionally a legend element, followed by flow content .可选的legend元素,后跟 流内容


The HTML4.01 spec. HTML4.01 规范。 defines the fieldset element as follows:定义fieldset元素如下:

 <!ELEMENT FIELDSET - - (#PCDATA,LEGEND,( %flow; )*) -- form control group -->

where the comma-separated list defines the order in which the child elements must appear, ie LEGEND has to appear before other flow (block or inline) elements.其中逗号分隔的列表定义了子元素必须出现的顺序,即LEGEND必须出现在其他流(块或内联)元素之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM