如何在 HTML 元素中使用 CSS 设置特定单词的样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11076085/
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
How do I style a specific word with CSS in an HTML element?
提问by AMC
How do I style a specific word within <p>
tags?
EX: STUDIO Xis the best studio ever.
如何在<p>
标签中设置特定单词的样式?EX:STUDIO X是有史以来最好的工作室。
^^How do I, using css, make "STUDIO X" a different font than "is the best studio ever?"
^^我如何使用 css 使“STUDIO X”成为与“有史以来最好的工作室”不同的字体?
回答by Marcio Mazzucato
You should do this:
你应该做这个:
HTML
HTML
<p>
<span>STUDIO X</span> is the best studio ever
</p>
CSS
CSS
p {
font-size:12px;
}
span {
font-size:16px;
font-weight:bold;
}
I recommend you to define a specific class for <p>
and <span>
tags, it will prevent unexpected overwrites.
我建议你为<p>
和<span>
标签定义一个特定的类,它会防止意外覆盖。
回答by Elvis D'Souza
You can wrap it with a span tag
你可以用 span 标签包裹它
<p><span class="best_studio">STUDIO X</span> is the best studio ever.</p>
and use CSS to define the style
并使用 CSS 定义样式
.best_studio {
font-family: Arial,
font-size: 22px
}
回答by kenwarner
<p><strong>STUDIO X</strong> is the best studio ever</p>
I believe most browsers' default css will bold a strong
element, but you can be explicit about it as well and add your own rule
我相信大多数浏览器的默认 css 都会加粗一个strong
元素,但你也可以明确说明它并添加你自己的规则
p strong { font-weight:bold; }