Apply style to element, only if a certain element exists next to it

后端 未结 1 1117
不思量自难忘°
不思量自难忘° 2021-01-17 22:33

I\'m using the

tag on several pages, but on ONE page I\'m using an
相关标签:
1条回答
  • 2021-01-17 22:43

    This only works if the <section/> comes after the <aside/>:

    <aside>content</aside>
    <!-- if there is another node in between, use the '~' selector -->
    <section>content</section>
    

    In that case you could use aside ~ section or aside + section:

    section {
        padding: 8px;
    }
    aside + section {
        width: 500px;
        float: left;
    }
    

    In all other cases you'll have to use JavaScript because these selectors only work in one direction, top to bottom.

    With CSS4 there might be a way using the Subject of a selector with Child combinator, but that's future. This selector was removed from the specification.

    0 讨论(0)
提交回复
热议问题