Alternating Row Colors in Bootstrap 3 - No Table
Since you are using bootstrap and you want alternating row colors for every screen sizes you need to write separate style rules for all the screen sizes.
/* For small screen */
.row :nth-child(even){
background-color: #dcdcdc;
}
.row :nth-child(odd){
background-color: #aaaaaa;
}
/* For medium screen */
@media (min-width: 768px) {
.row :nth-child(4n), .row :nth-child(4n-1) {
background: #dcdcdc;
}
.row :nth-child(4n-2), .row :nth-child(4n-3) {
background: #aaaaaa;
}
}
/* For large screen */
@media (min-width: 992px) {
.row :nth-child(6n), .row :nth-child(6n-1), .row :nth-child(6n-2) {
background: #dcdcdc;
}
.row :nth-child(6n-3), .row :nth-child(6n-4), .row :nth-child(6n-5) {
background: #aaaaaa;
}
}
Working FIDDLE
I have also included the bootstrap CSS here.
Alter bootstrap's table striped Rows to be every other couple rows?
.yourTableClass tr:nth-child(4n+1), .yourTableClass tr:nth-child(4n+2) {
background: pink;
}
How to create a table WITHOUT alternating row colors when using Blueprint CSS framework?
You need a more specific selector to override... BP is pretty general though so that shouldnt be an issue for example:
table.no-zebra tbody tr:nth-child(even) td,
table.no-zebra tbody tr.even td {
background: transparent;
}
you can replace transparent with whatever color to make all rows a solid color.
Bootstrap table striped: How do I change the stripe background colour?
.table-striped > tbody > tr:nth-child(2n+1) > td, .table-striped > tbody > tr:nth-child(2n+1) > th {
background-color: red;
}
add this line into your style.css after main bootstrap.css
or you could use (odd) or (even) instead of (2n+1)
Alternate table row color using CSS?
$(document).ready(function()
{
$("tr:odd").css({
"background-color":"#000",
"color":"#fff"});
});
tbody td{
padding: 30px;
}
tbody tr:nth-child(odd){
background-color: #4C8BF5;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1">
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>13</td>
</tr>
</tbody>
</table>
Related Topics
How to Create a Box When Mouse Over Text in Pure CSS
CSS White Space at Bottom of Page Despite Having Both Min-Height and Height Tag
Flex-Wrap Not Working as Expected in Safari
Text-Overflow:Ellipsis on a Link
How to Exclude a Specific Element from Inheriting CSS Rules
Scaling Object Element Height Proportional to Width + Constant with CSS
Pagespeed Caching CSS, Annoying to Develop
Input Effect on Keyboard Tab -> Focus, But Not on Click
What Is the Simplest Way to Implement Pure CSS Show/Hide
How to Get a Three Column Layout with Twitter Bootstrap
Prevent Wrapping of Menu Items
Alternating Row Colors in Bootstrap 3 - No Table
How to Detect Ie and Edge Browsers in CSS
Less Immediate Parent Selector
Do I Need to Generate a CSS File from Pygments for My Jekyll Blog, to Enable Colorful Code Snippet