CSS selector: how to style items [1-2][5-6][9-10] etc by pair
Working jsFiddle here.
Use :nth-child(4n+3), :nth-child(4n+4)
CSS:
li:nth-child(4n+4), li:nth-child(4n+3) {
color:red;
}
HTML:
<ul>
<li>No</li>
<li>No</li>
<li>YES</li>
<li>YES</li>
<li>No</li>
<li>No</li>
<li>YES</li>
<li>YES</li>
<li>No</li>
<li>No</li>
<li>YES</li>
<li>YES</li>
</ul>
Select nth child select 1, 2, 5, 6, 9, 10 etc
If I understood you correctly, you want to select:
1 2 3 4 5 6 7 8 9 10 ...
+ + + + + + ...
For that you can use:
.selector>div:nth-child(4n+1), .selector>div:nth-child(4n+2){ background-color:red;}
<div class="selector"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> <div>9</div> <div>10</div></div>
select multiple child in css
You can separate the classes with a comma ,
.ListTaskTime tbody tr >td:nth-child(3),
.ListTaskTime tbody tr >td:nth-child(6),
.ListTaskTime tbody tr >td:nth-child(9) {
/* Common Styles Goes Here, Styles will apply to child 3,6 and 9 */
}
Note: You need to check the nth-child
and define it manually in your stylesheet, as CSS cannot decide it for you if columns increase.
If you are using a server side language for generating a dynamic table, you can use functions like substr()
to cut down the letters.
Side note : You don't have to use >
unless and until you don't have any child table, this is sufficient.. tbody tr td:nth-child(3)
nth-child for every two table rows
Realize that you are doing groups of 4, then you can see that you can have every 4th element and every 4th element minus one being white, then every 4th element minus two, or every 4th element minus 3 being grey.
So, you'd use 4n
and 4n-1
, then 4n-2
and 4n-3
:
div:nth-child(4n), div:nth-child(4n-1) {
background: red;
}
div:nth-child(4n-2), div:nth-child(4n-3) {
background: blue;
}
That code isn't precise to your case, I wrote it for a jsFiddle proof-of-concept.
NB disclaimer: Keep in mind that nth-child
does not work in IE8. Typical issue, of course.
Select doubles using nth-child() in CSS3
ul li:nth-child(4n+1),
ul li:nth-child(4n+2) {
background: #CCC;
}
ul li:nth-child(4n+3),
ul li:nth-child(4n+4) {
background: #DDD;
}
This will give you every 4th element starting with the 1st, and 2nd as color #CCC and every 4th element starting with the 3rd and 4th as #DDD
jsfiddle here: http://jsfiddle.net/mU2tn/1/
CSS even odd for every other odd div in class
:nth-child(4n)
gives us 0, 4, 8, etc.
Since you want 1, 5, 9, you should try :nth-child(4n + 1)
What's the difference between UTF-8 and UTF-8 with BOM?
The UTF-8 BOM is a sequence of bytes at the start of a text stream (0xEF, 0xBB, 0xBF
) that allows the reader to more reliably guess a file as being encoded in UTF-8.
Normally, the BOM is used to signal the endianness of an encoding, but since endianness is irrelevant to UTF-8, the BOM is unnecessary.
According to the Unicode standard, the BOM for UTF-8 files is not recommended:
2.6 Encoding Schemes
... Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature. See the “Byte Order Mark” subsection in Section 16.8, Specials, for more information.
Related Topics
Aligning Text and Select Boxes to The Same Width in CSS
CSS Font Twitter Like Close Button, What Did I Missing
How to Change The CSS of Only One Page in Wordpress
How to Make The Scrollbar on a Div Only Visible When Necessary
How to Keep a Div Always on The Screen, But Not Always in a Fixed Position
Keep Element Fixed While Safari Navigation Bar Collapes on iOS
Styling Input Range for Webkit with Pure CSS
Simple Two Column HTML Layout Without Using Tables
Select Second Active Slide in Slickslider Through CSS-Selector
Making a Button and Textbox The Same Height Next to Each Other
Iframe Z-Index for Drop Down Menu
CSS Selector: How to Style Items [1-2][5-6][9-10] etc by Pair
HTML5 Video Background, Keep Center of Video in Center
Change Cursor Over HTML5 Canvas When Dragging The Mouse
Div Scrollbar - Any Way to Style It
Display Optgroup Label as Initial Option
What Is Meant by "Participate" in The Definition of "Normal Flow" in The CSS 2.1 Spec