为 li id 定义 CSS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8488141/
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
Define CSS for li id
提问by Tim
How do I define a style for an li id? Does it work the same way as an li style?
如何定义 li id 的样式?它的工作方式与 li 风格相同吗?
e.g.
例如
<li id="news" class="section_wrapper"></li>
回答by Andy E
Use the ID selector:
使用ID 选择器:
#news {
color: red;
}
If you want higher specificity, you can combine both the element and ID selectors:
如果你想要更高的特异性,你可以结合元素和 ID 选择器:
li#news {
color: red;
}
回答by Nick Shvelidze
yes, it's the same
you should add li#news {/*style here*/}
in css
是的,您应该li#news {/*style here*/}
在 css 中添加相同的内容
回答by Nathan MacInnes
IDs are represented by hashes. So instead of li {
...
ID 由散列表示。所以,而不是li {
...
#news {
font-weight: bold;
}
回答by dknaack
Yes you can do this.
是的,你可以这样做。
<ol>
<li id="news1" class="section_wrapper">Item 1</li>
<li id="news2" class="section_wrapper">Item 2</li>
<li id="news3" class="section_wrapper">Item 3</li>
</ol>
#news1 {
background-color: red;
}
here is a jsFiddlethat demonstrates it
这是一个演示它的jsFiddle
hope this helps
希望这可以帮助