Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: Striped div table

I'm using Bootstrap css lib. I know how to make striped table with this lib but how to make striped div's?

For ex, in tables you would do this:

<table id="newtable" class="table table-bordered table-striped fixedtable">
    <thead>
        <th>Date</th>
        <th>Info</th>
        <th>Price</th>
    </thead>
    <tbody>
        <tr>
            <td colspan="3">                
                <div>text 1</div> 
                <div>text 2</div>  
                <div>text 3</div>  
                <div>text 4</div>                                
            </td>
        </tr>
    </tbody>    
</table>    

And I need to repeat that "styling" with divs like this:

<div class="row"><div class="col">Text 1 White BG</div></div>
<div class="row"><div class="col">Text 2 Grey BG</div></div>
<div class="row"><div class="col">Text 3 White BG</div></div>
<div class="row"><div class="col">Text 4 Grey BG</div></div>

Question is: How to make: <div>text 1</div>, <div>text 2</div>, <div>text 3</div>, <div>text 4</div> striped?

like image 969
Lugaru Avatar asked Jul 22 '13 08:07

Lugaru


2 Answers

use td div:nth-of-type(odd|even)

The following CSS3 example works in modern browsers

<style>
td div:nth-of-type(odd) {
    background: #e0e0e0;
}
td div:nth-of-type(even) {
    background: #FFFFFF;
}
</style>
<table id="newtable" class="table table-bordered table-striped fixedtable">
    <thead>
        <th>Date</th>
        <th>Info</th>
        <th>Price</th>
    </thead>
    <tbody>
        <tr>
            <td colspan="3">                
                <div>text 1</div> 
                <div>text 2</div>  
                <div>text 3</div>  
                <div>text 4</div>                                
            </td>
        </tr>
    </tbody>    
</table>    
like image 149
shukshin.ivan Avatar answered Sep 28 '22 07:09

shukshin.ivan


Add class legend to your container and then for every other row actually in the divs within that row you can apply a format

CSS

.legend .row:nth-of-type(odd) div {
background-color:antiquewhite;
}
.legend .row:nth-of-type(even) div {
background: #FFFFFF;
}

<div class="container legend">
    <div class="row">
     <div class="col-sm-2">text</div>
     <div class="col-sm-2">more Text</div>
</div>
<div class="row">
     <div class="col-sm-2">text</div>
     <div class="col-sm-2">more Text</div>
 </div>
</div>
like image 23
Rondakay Avatar answered Sep 28 '22 08:09

Rondakay