【发布时间】:2017-07-03 21:16:30
【问题描述】:
我有以下 HTML:
<div class="row">
<div class="col-md-6">...</div>
<div class="col-md-6">...</div>
</div>
想要的效果:
.row {
~div:nth-child(1) /*also tried*/ ~div:first-child /*also tried*/ ~div:first-of-type {
position:relative;
left:5vw;
}
~div:nth-child(2) /*also tried*/ ~div:last-child /*also tried*/ ~div:last-of-type {
position:relative;
right:5vw;
}
}
后果:
我可以选择 .row 的孩子
测试颜色:红色;我为 .col-md-6 的内容设置样式(它们设置为继承颜色)
使用背景颜色进行测试:红色;我为 .row 设置样式
并且再次定位.row 的孙子样式
注意:
umbraco 后端中的 .col-md-6 类不能更改,因为这些在 web 应用程序的其他地方使用。我不想在后端手动添加类,也不想根据位置添加带有 JS 的类
如何获取:nth-child(1) / :first-child / :first-of-type
定位正确的 div,并且只定位 div 本身?
【问题讨论】:
-
也许可以试试
div:nth-of-type(1) -
我改成了 position:page;它起作用了选择器,对于某些样式,选择了多个
标签: css twitter-bootstrap css-selectors umbraco