我遇到了一个古怪的问题而无法找到答案或弄明白。
问题在于<legend>
中的<form>
标记。
我使用<form>
创建了一个表单,当我使用嵌套在<fieldset>
内的<legend>
时,页面呈现正常,就好了!
当我使用<form>
而没有<fieldset>
但继续使用<legend>
时,页面会中断。
具体而言,<legend>
文字不符合我在<body>
下应用于<style>
的格式。而不是居中文本,它位于左侧。 (见代码..)
这可能是我非常愚蠢的事情但是,我很难过。我唯一能想到的是<legend>
不能单独使用(没有像<fieldset>
这样的元素。)
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Misha's Homepage</title>
<style>
body {
background-color:black;
text-align:center;
color:white
}
</style>
</head>
<body>
<h1>Welcome!</h1>
<hr>
<p title="Carpe Diem">If you are reading this, well, we've only just begun.</p>
<h2>Stay Hungry...</h2>
<h3>Stay Foolish!</h3>
<a href="https://youtu.be/2fAP-5NVZAA">Velocidas Eradico</a>
<h1>Squad Up!</h1>
<img src="ak_cartoon_whiteONclear2.jpg" alt="Get Sum." style="width:302px;height:217px">
<form>
<legend>Gimme Yo Digitz!</legend>
<br>First Name:
<br>
<input type="text" name="firstname">
<br>Last Name:
<br>
<input type="text" name="lastname">
<br>
<br>Choose:
<br>
<input type="radio" name="state" value="bored">Bored
<br>
<input type="radio" name="state" value="sleepy">Sleepy
<br>
<input type="radio" name="state" value="horny">Horny
<br>
<br>
<input type="submit" value="Hit it!">
</form>
</body>
</html>
答案 0 :(得分:1)
legend
必须放在fieldset
内。就像table
及其相关元素一样,没有td
,您就无法th
或tr
。
关于legend
元素有一个有趣的事实,很多人都不知道如果你将legend
置于fieldset
的任何地方,它将始终显示在顶部fieldset
的。{与tfoot
内的table
一样,即使您将其放在HTML的顶部,也会始终在tbody
之后呈现。
示例:
<fieldset>
<span>Content</span>
<legend>Title</legend>
</fieldset>
&#13;
即使上面的<legend>
元素在 <span>
元素之后写入,它仍会呈现在<fieldset>
元素的顶部。