首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通配符选择器工作异常

通配符选择器工作异常
EN

Stack Overflow用户
提问于 2016-12-18 21:41:12
回答 1查看 42关注 0票数 0

我有这个选择器

代码语言:javascript
运行
复制
[id^="subf"] {}

它将选择ID以subf开头的所有元素,好吗?但现在我只想选择这些DIVs中的直接父DIVs,如下所示:

代码语言:javascript
运行
复制
<div id="subf1">
 <div></div>  <-- this DIV but not the child DIVs inside
 <div></div>  <-- and this DIV but not the child DIVs inside
</div>

所以我使用这个:

代码语言:javascript
运行
复制
[id^="subf"] > div {}

或者这样:

代码语言:javascript
运行
复制
[id^="subf"] > div, [id^="subf"] > div + div {}

但它们都不能很好地工作,因为: div“subf”> DIV似乎也会影响父"subf1“id^=,我不希望这样。这里出了什么问题?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-12-19 03:51:25

据我所知,[id^="subf"] > div似乎运行得很好。

下面是一个示例,其中只有[id^="subf"]的直接子对象应用了黄色background-colorborder-radius

代码语言:javascript
运行
复制
[id^="subf"] {
display: block;
float: left;
width: 200px;
height: 200px;
margin: 6px;
background-color: rgb(255,0,0);
}

[id^="subf"] div {
display: block;
float: left;
width: calc(50% - 12px);
height: calc(50% - 12px);
margin: 6px;
background-color: rgb(0,0,255);
}

[id^="subf"] > div {
background-color: rgb(255,255,0);
border-radius: 50%;
}
代码语言:javascript
运行
复制
<div id="subf1">

<div>
<div></div>
<div></div>
</div>  <!-- this DIV but not the child DIVs inside -->

<div>
<div></div>
<div></div>
</div>  <!-- and this DIV but not the child DIVs inside -->

</div>

<div id="subf2">

<div>
<div></div>
<div></div>
</div>  <!-- this DIV but not the child DIVs inside -->

<div>
<div></div>
<div></div>
</div>  <!-- and this DIV but not the child DIVs inside -->

</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41208883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档