Html 如何在 h2 中为类应用 css?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5198453/
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 to apply css for a class within h2?
提问by prosseek
I have an HTML code as follows
我有一个 HTML 代码如下
<h2><a class="toc-backref" href="#id8">Debug</a></h2>
How can I apply css format to Debug which is inside <a>
(which is inside <h2>
) with a class of "toc-backref"?
如何将 css 格式应用于具有“toc-backref”类的内部<a>
(内部<h2>
)的调试?
回答by dmackerman
You could put a span
inside of the h2
, but that's not necessary. If you want to style the <a>
inside of the <h2>
, just do something like:
你可以在span
里面放一个h2
,但这不是必需的。如果你想设计<a>
内部的样式<h2>
,只需执行以下操作:
h2 a {
// style here
}
Or you can give the link a class:
或者你可以给链接一个类:
h2 a.toc-backref {
// style here
}
回答by Dustin Laine
h2 .toc-backref
{
/* Any style here */
}
回答by hiren gamit
you can also try
你也可以试试
<h2 class="toc-backref"><a href="#id8">Debug</a></h2>
your style will be in css
你的风格将在 css 中
.toc-backref
{
//your style....
}