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
css bold first word
提问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-word
pseudo-element in CSS; you'll have to wrap the first word in an extra element and then select that.
::first-word
CSS 中没有伪元素;您必须将第一个单词包装在一个额外的元素中,然后选择它。
回答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
回答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>