简体   繁体   English

两条路线子和条件样式

[英]Two routes children and conditional styling

I got this case:我得到了这个案例:

<div class="parent">
    <div class"routeA">
        <div class="header">
            <li></li>
            <li class="p-highlight"></li>
            <li></li>
        </div>
    </div>
    <div class="routeB">
        <div class="content">
        </div>
    </div>
</div>

I need to make.content to have border-radius: 6px when.p-highlight is not with first li, and.content to have border-radius: 0px 0px 6px 6px when.p-highlight is combined with first li我需要 make.content 有border-radius: 6px when.p-highlight 不是第一个li,并且.content 有border-radius: 0px 0px 6px 6px when.p-highlight 和第一个li 结合

Is this even possible?这甚至可能吗?

Yes, it's possible with the following rule but you need to be aware that the:has() pseudo class is not fully supported by all browsers (eg firefox, Opera, Chrome for Android etc) You can check compatibility at caniuse.com Yes, it's possible with the following rule but you need to be aware that the:has() pseudo class is not fully supported by all browsers (eg firefox, Opera, Chrome for Android etc) You can check compatibility at caniuse.com

Note: I've also added a border to.content so you can see the effect.注意:我还为.content 添加了一个边框,这样你就可以看到效果了。

 .content { border: 1px solid black; border-radius: 6px; }.parent:has(li:first-child.p-highlight).content { border-radius: 0 0 6px 6px; }
 <div class="parent"> <div class="routeA"> <div class="header"> <li class="p-highlight">One</li> <li>Two</li> <li>Three</li> </div> </div> <div class="routeB"> <div class="content"> Content </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM