标签中的HTML标题元素 [英] HTML heading elements in labels

查看:136
本文介绍了标签中的HTML标题元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要放置标题时,我使用h-number标记.但是,例如,如果我需要label中的标题,我也应该使用h-number吗?

When I need place a title, I use h-number tags. But in case that I need a title in a label, for instance, should I use h-number, too?

示例:

<label ...>
    <h1>Username</h1>
    <input ... />
</label>

推荐答案

没有必要这样做.只需使用样式

There is no need to do so. Just use styles

label,
label span {font-size: 20px; font-weight: bold}

<label for="username-input">Username</label>
<input type="text" name="username" id="username-input">

<!-- Or, if you want the input inside of the label -->
<label>
  <span>Username</span>
  <input type="text" name="username">
</label>

通常,您不希望将块元素(例如标题标签)放在内联元素(例如标签)内.但是,您始终可以更改其显示样式.

Generally, you do not want to put block elements (such as heading tags) inside of inline elements (such as a label). However, you can always alter their display style.

要记住的另一件事是标题应保留给标题.标签标签应保留用于标签. 根据您的情况,标签内的h1标签不是有意义的",因为它不是页面的标题.您可能想使用一些不太突出的(例如span),但要使其看起来像您想要的那样.

Another thing to remember is that heading tags should be reserved for headings. Label tags should be reserved for labels. In your case, the h1 tag inside of the label doesn't "make sense" since it is not the heading of the page. You would want to use something less prominent, such as a span, but make it look how you want.

这篇关于标签中的HTML标题元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆