Html 我们可以在 H1 标签内添加一个 <span> 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7524185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:44:35  来源:igfitidea点击:

Can we add a <span> inside H1 tag?

html

提问by Codeobsession

Is it a proper method to use span tag inside H1 tag?

在 H1 标签中使用 span 标签是一种正确的方法吗?

<h1>
    <span class="boardit">Portfolio</span>
</h1>

I know we can write it in this way...and am also following the below syntax in my own website..

我知道我们可以用这种方式编写它......并且我也在我自己的网站中遵循以下语法......

<h1 class="boardit">
  <span>Portfolio</span>
</h1>

However, I Just wanted to know the cleaner form of html..

但是,我只是想知道 html 的更简洁的形式。

回答by mu is too short

Yes you can.

是的你可以。

HTML4 has this to say:

HTML4 有这样的说法

<!ENTITY % heading "H1|H2|H3|H4|H5|H6">
<!--
  There are six levels of headings from H1 (the most important)
  to H6 (the least important).
-->

<!ELEMENT (%heading;)  - - (%inline;)* -- heading -->

And %inline;is:

并且%inline;是:

<!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">

And %special;includes <span>.

%special;包括<span>.

The current HTML has this to say:

当前的HTML 是这样说的

Content contents
Phrasing content

内容内容
词组内容

And Phrasing contentincludes <span>.

短语内容包括<span>

回答by mnsr

Yes you can. It can be used to format a part of a h1 block:

是的你可以。它可用于格式化 h1 块的一部分:

<h1>Page <span class="highlight">Title</span></h1>

If the style applies to the entire h1 block, I do this:

如果样式适用于整个 h1 块,我会这样做:

<h1 class="highlight">Page Title</h1>

回答by Dave

Yes, it's typically fine to use a spaninside of an h1. spanis an inline element, so it's typically okay to use it inside anything (that allows elements inside it!)

是的,通常可以spanh1. span是一个内联元素,因此通常可以在任何内容中使用它(允许在其中包含元素!)

And there's not really a cleaner way to do it sometimes, say if you want to style only part of the h1.

有时并没有真正更简洁的方法来做到这一点,例如,如果您只想设置h1.

On the other hand... don't do it if it's not necessary, as it is a little ugly : )

另一方面...如果没有必要就不要这样做,因为它有点难看:)

回答by Simon Sarris

Yes that's fine, but why not

是的,那很好,但为什么不呢

   <h1 class="boardit">
      Portfolio
   </h1>

If thats all you're doing?

如果这就是你所做的一切?

回答by geetfun

Yes, you can. The span displays inline, so it should not affect the styling of the H1.

是的你可以。跨度显示内联,因此它不应影响 H1 的样式。

回答by Touhid Rahman

Yes, we can use span tag with header tags and there is nothing wrong in it. Indeed this is widely used for styling header tags, specially for coloring a particular word or letter.

是的,我们可以使用带有标题标签的 span 标签,它没有任何问题。事实上,这广泛用于样式标题标签,特别是用于为特定单词或字母着色。

回答by Touhid Rahman

Yes, we can use span tag with header tags and there is nothing wrong in it. Indeed this is widely used for styling header tags, specially for coloring a particular word or letter.

是的,我们可以使用带有标题标签的 span 标签,它没有任何问题。事实上,这广泛用于样式标题标签,特别是用于为特定单词或字母着色。

回答by takrishna

<h1 style="display:inline;">Bold text goes here</h1> 
<span style="display:inline;">normal text goes here</span>

Think in above lines - Worked for me - use display:inline prop

在上面几行思考 - 为我工作 - 使用 display:inline prop