css - Apply style to element, only if a certain element exists next to it -
i'm using <section> tag on several pages, on 1 page i'm using <aside> tag preceded <section> tag.
in case have <section> followed <aside>, apply width both , have section float left, , aside float right.
basically, if have <section> , <aside> want style work this:
section { width: 500px; float: left; padding: 8px; } aside { padding:8px; width:400px; float:right; } if have <section> want like:
section { padding: 8px; } is there way can either conditional statement in css3, or pseudo-class, without having use javascript, custom classes, or separate css files?
this works if <section/> comes after <aside/>:
<aside>content</aside> <!-- if there node in between, use '~' selector --> <section>content</section> in case use aside ~ section or aside + section:
section { padding: 8px; } aside + section { width: 500px; float: left; } in other cases you'll have use javascript because these selectors work in 1 direction, top bottom.
with css4 there might way using subject of selector child combinator, that's future. selector removed specification.
Comments
Post a Comment