[英]Using an attribute selector with adjacent sibling
我试图与相邻的类一起使用属性选择器。 但是,它似乎无法协同工作。
还有其他方法可以使相邻的,非相同的同级应用CSS吗?
我也尝试过这个,没有运气:
.tbslant-uphill + .tbslant-downhill {margin-top: -120px;}
[class^="tbslant"] + [class^="tbslant"] {margin-top: -120px;}
<section class="content-block bg-green slant-on tbslant-uphill"></div>
<section class="content-block bg-green slant-on tbslant-downhill”></div>
你的属性选择要求“tbslant”是在类名列表的开始和你的情况不是这样的。
您需要“ tbslant”的选择器出现在列表中的任何位置 。
[class*="tbslant"] + [class*="tbslant"]
[class*="tbslant"] + [class*="tbslant"] { margin-top: 20px; background: blue; } section { padding: 1em; background: red; }
<section class="content-block bg-green slant-on tbslant-uphill"></section> <section class="content-block bg-green slant-on tbslant-uphill"></section>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.