[英]Can't get CSS3 selectors to work
I am trying to learn the new CSS3 selectors and so have tried the following code: 我正在尝试学习新的CSS3选择器,因此尝试了以下代码:
<body class="frontpage">
<section name="top">
<header class="head" name="top">
<div id="my-name">
<h1 id="title">
Josh Dempsey
</h1>
</div>
</header>
</section>
</body>
With the CSS: 使用CSS:
body[class*="f"]>section[name$="op"]>header[class|top]>div[id*="my"]>h1[id=title]{color:white;}
I would expect my name to be printed in white, not black/auto. 我希望我的名字印成白色,而不是黑色/自动。
My other CSS in case anyone can find anything out from it: 我的其他CSS,以防有人从中找到任何东西:
body[class*="fro"]{background-color:#f8efe1;height:auto;width:auto;direction:ltr;z- index:1;}
section[name*="t"]{position:absolute;top:0px;left:0px;width:100%;height:100px;}
header[class$="ad"]{background-color:#272727;height:100%;width:100%;}
h1[class="title-of-site"]{color:white;font-family:'Open Sans',sans-serif;font- weight:300;margin:0}
header[class$="op"]>div[name*=image_holder] {position:absolute;top:5px;left:10%;bottom:5px;height:40px;width:40px;background-color:
transparent;}
I have checked all of this on W3.org and have successfully validated it. 我已经在W3.org上检查了所有这些内容,并成功验证了它。 So I am stumped by this. 所以我为此感到困惑。 Thanks. 谢谢。
You had a few syntax issues in the selector (mainly quotations around the values). 选择器中有一些语法问题(主要是值周围的引号)。
The reason the selector wasn't working was you had header[class|top]
pointing to the wrong attribute, as header had class="head"
. 选择器不起作用的原因是您有header[class|top]
指向错误的属性,因为header具有class="head"
。 You need to change that to name and put an equals after the vertical line. 您需要将其更改为名称,并在垂直线后放置一个等号。
header[name|="top"]
This is the full selector working below: 这是下面的完整选择器:
body[class*="f"] > section[name$="op"] > header[name|="top"] > div[id*="my"] > h1[id="title"]
{
color:white;
}
将header[class|top]
替换为header[class|name="top"]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.