简体   繁体   English

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

[英]Can we add a <span> inside H1 tag?

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形式..

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; %inline; is: 是:

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

And %special; 并且%special; includes <span> . 包括<span>

The current HTML has this to say : 目前的HTML有这样的说法

Content contents 内容内容
Phrasing content 短语内容

And Phrasing content includes <span> . 短语内容包括<span>

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>

Yes, it's typically fine to use a span inside of an h1 . 是的,在h1使用span通常很好。 span is an inline element, so it's typically okay to use it inside anything (that allows elements inside it!) 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 : ) 另一方面......如果没有必要,不要这样做,因为它有点难看:)

Yes that's fine, but why not 是的,没关系,但为什么不呢

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

If thats all you're doing? 如果这就是你所做的一切?

Yes, you can. 是的你可以。 The span displays inline, so it should not affect the styling of the H1. 跨度显示为内联,因此不应影响H1的样式。

Yes, we can use span tag with header tags and there is nothing wrong in it. 是的,我们可以使用带标题标记的span标记,并且没有任何错误。 Indeed this is widely used for styling header tags, specially for coloring a particular word or letter. 实际上,这被广泛用于样式标题标签,特别是用于着色特定的单词或字母。

Yes, we can use span tag with header tags and there is nothing wrong in it. 是的,我们可以使用带标题标记的span标记,并且没有任何错误。 Indeed this is widely used for styling header tags, specially for coloring a particular word or letter. 实际上,这被广泛用于样式标题标签,特别是用于着色特定的单词或字母。

<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 想想以上几行 - 为我工作 - 使用显示:内联道具

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

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