Can you apply CSS rules, in CSS, if a div doesn't exist?
问题 Is this possible, with CSS ? Apply this rule if .div1 doesn't exist: .div2{ property: value; } like <div class="div1"> ... </div> <div class="div2"> <!-- it exists, so do nothing --> </div> and <div class="div2"> <!-- it doesn't exist, apply the css --> </div> 回答1: If you know the 'unstyled' styles of the div, you could use a css sibling selector to style it one way if it follows .div1, and the 'plain' way if it doesnt - ie .div2 { /* styled however you want */ } .div1 + .div2 { /* 'plain'