Html css 粗体第一个字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7440572/
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:38:51  来源:igfitidea点击:

css bold first word

htmlcsscss-selectors

提问by Adam

How can I bold the first word of sentence using CSS selectors and is this a good/bad way to do this with respects to browser comparability?

如何使用 CSS 选择器将句子的第一个单词加粗,这对于浏览器的可比性来说是好还是坏?

code:

代码:

  <h2>this is a sentence</h2>

thx

谢谢

回答by BoltClock

There is no ::first-wordpseudo-element in CSS; you'll have to wrap the first word in an extra element and then select that.

::first-wordCSS 中没有伪元素;您必须将第一个单词包装在一个额外的元素中,然后选择它。

回答by 422

Use Span class

使用 Span 类

So creat a class called bold and wrap first word in the class.

所以创建一个名为bold 的类并在类中包装第一个单词。

.bold {
font-weight:bold;
}

Then

然后

<h2><span class="bold">the</span> brown fox</h2>

回答by user15100

just put the first word in a strong tag.

只需将第一个单词放在一个强标签中。

<h1><strong>This</strong> is how you do it simply.</h1>

Here is the JS Fiddle

这是JS小提琴

回答by Daniel De León

The current CSS selectors do now allow this.

当前的 CSS 选择器现在允许这样做。

So I change my approach to bold the first line.

所以我改变了我的方法来加粗第一行。

HTML

HTML

<h2>this<br> is a sentence</h2>

CSS

CSS

h2::first-line{
   font-weight: bold;
}

回答by Hossam Ghareeb

I have put the word between <b>First</b>

我把这个词放在 <b>First</b>