[英]CSS selector not working?
Hey guys, thanks in advance for any help or input. 大家好,谢谢您的帮助或投入。 I am having trouble understanding CSS selectors and i have read the docs..
我在理解CSS选择器时遇到了麻烦,我已经阅读了文档。
I am trying to refer to the UL with the id dropdown in my stylesheet. 我试图在样式表中使用id下拉列表引用UL。 I was under the assumption that i was able to refer to any elements like:
我假设我可以引用任何元素,例如:
#dropdown ul
{
}
This method however does not seem to work :s.. Am i misunderstanding CSS selectors? 但是,此方法似乎不起作用:s ..我是否误解了CSS选择器? The elements in my actual code are nested deeper than this structure but i presume the principle is the same?
我实际代码中的元素嵌套得比此结构更深,但是我认为原理是相同的吗?
<div id="wrapper">
<ul id="dropdown">
<li class="sub"><a href="#">Dropdown</a>
<!-- Sub Menu -->
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
</ul>
<!-- End Submenu -->
</li>
</ul>
</div>
/* Dropdown Menu */
#dropdown ul
{
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
#dropdown ul li
{
display: block;
position: relative;
float: left;
}
#dropdown li ul
{
display: none;
}
#dropdown ul li a
{
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;
}
#dropdown ul li a:hover
{
background: #617F8A;
}
#dropdown li:hover ul
{
display: block;
position: absolute;
}
#dropdown li:hover li
{
float: none;
font-size: 11px;
}
#dropdown li:hover a
{
background: #617F8A;
}
#dropdown li:hover li a:hover
{
background: #95A9B1;
}
Try 尝试
ul#dropdown
{
}
This will select the ul element with ID dropdown. 这将选择带有ID下拉列表的ul元素。
With 同
#dropdown ul
you are trying to locate a ul element within an element with id dropdown. 您正在尝试在ID下拉列表的元素中定位ul元素。 This will select all ul elements inside the #dropdown ul, however many levels deep.
这将选择#dropdown ul内部的所有 ul元素,无论深度多深。
edit: it's right as mario wrote. 编辑:这是正确的,如马里奥写道。
edit2: im sorry for being 5seconds too slow, i just wanted to help. edit2:很抱歉我太慢了5秒,我只是想提供帮助。 For completition of my post:
ul#dropdown
or #dropdown
is the right selection 为了完成我的帖子:
ul#dropdown
或#dropdown
是正确的选择
#dropdown ul
means "select any ul
that is a direct or indirect child of #dropdown
". #dropdown ul
意思是“选择是#dropdown
的直接或间接子代的任何ul
”。 That is not what you want, I think. 我想那不是您想要的。 Try
#dropdown
alone (you don't need to mention ul
as IDs are exclusive, meaning you should only have one #dropdown
in a page). 单独尝试
#dropdown
(您不必提及ul
因为ID是互斥的,这意味着您在页面中只能有一个#dropdown
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.