Html 为句子的第一个单词着色 CSS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25561450/
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
Color the First word of Sentence CSS
提问by Juanid Farooq
I was trying to color just first WORD of sentence
我试图给句子的第一个单词着色
<div class="logoS">Title Of The Page</div>
CSS which am using is
正在使用的 CSS 是
.logoS{
padding: 0px;
float: left;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
color: white;
border:solid 1px black;
font-weight: bold;
font-size: 22px;
}
.logoS::nth-word(1) {
margin-right: 20px;
}
i just want to color "TITLE" not other words, any solution
我只想给“TITLE”上色而不是其他词,任何解决方案
回答by user3835327
Try this, hope this will help .
试试这个,希望这会有所帮助。
.logoS:before {
color: red;
content: "Title ";
}
<div class="logoS">Of The Page</div>
回答by Joshua Howard
The code
编码
<div class="logoS"><span id="first">Title</span> Of The Page</div>
.logoS{
padding: 0px;
float: left;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
color: blue;
border:solid 1px black;
font-weight: bold;
font-size: 22px;
}
#first {
margin-right: 20px;
color: red;
}
回答by Jenz
Use a span with preferred style for the first word like
对第一个单词使用具有首选样式的跨度,例如
<div class="logoS"><span class="spanstyle">Title </span>Of The Page</div>
// CSS
.spanstyle {
color:blue;
}
Check this link. There is :first-letter
and :first-line
, but no :first-word
.
检查此链接。有:first-letter
和:first-line
,但没有:first-word
。
回答by Ian Wise
Use a span tag, this way it won't start a new line. For example:
使用 span 标签,这样它就不会开始新的一行。例如:
<div class="logoS"><span id="title">Title</span> Of The Page</div>
and then in your css just add:
然后在你的 css 中添加:
#title{
color: red
}
Hope this works!
希望这有效!
回答by drneel
There is :first-letter and :first-line, but no :first-word (MDN Search). Just wrap your first word in an element. Fiddle exmaple
有 :first-letter 和 :first-line,但没有 :first-word(MDN 搜索)。只需将您的第一个单词包装在一个元素中。 小提琴示例
<div class="logoS"><span id="first-word">Title</span> Of The Page</div>
.logoS{
padding: 0px;
float: left;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
color: blue;
border:solid 1px black;
font-weight: bold;
font-size: 22px;
}
#first-word {
margin-right: 20px;
color: red;
}
Or you can use javascript (here's an example), but if you look at the code, all he does is wrap the first word in a span and add a class.
或者你可以使用javascript(这里有一个例子),但是如果你查看代码,他所做的就是将第一个单词包装在一个跨度中并添加一个类。