9. April 2015
von Blackbam
Recently I discovered some short solution for ignoring a single hidden element with the nth-child selector. If you struggle with the same problem the following might be useful:This is the HTML:
<span class="video_prewrap">a</span>
<span class="video_prewrap">b</span>
<span class="video_prewrap">c</span>
<span class="video_prewrap cpw">d</span>
<span class="video_prewrap">e</span>
The following CSS adds a margin right to every second visible element no matter which element has the cpw class.
.cpw {
    display:none;
}

.video_prewrap {
    margin-right:20px;
}

.video_prewrap:nth-child(2n) {
    margin-right:0;
}

.cpw ~ .video_prewrap:nth-child(2n) {
    margin-right:20px;
}

.cpw ~ .video_prewrap:nth-child(2n-1) {
    margin-right:0;
}
Share

Dieser Eintrag wurde am 9. April 2015 um 0:00 in der Kategorie CSS veröffentlicht. You can book the comments for this article RSS 2.0. Feedback, discussion, commendation and critics are welcome: Write a comment or trackback.


Tags: , ,

No comments yet

Kommentare abonnieren (RSS) or URL Trackback

Leave a comment: