php - Change css class for the first 3 records extracted from mysql -


i have query extracts product categories , lists them in div. add margin-bottom css class of first 3 records extracts.

css

.icons-box {padding: 20px 10px 10px 10px;} 

php:

 $cat_list = "select *               tbl_category               cat_parent_id >0 order cat_id asc";                  $result_list = dbquery($cat_list);                    while($row_list = dbfetchassoc($result_list)) {                       extract($row_list); ?> <div class="icons-box">  <h3><?php echo $cat_name; ?></h3>  <p><?php echo $cat_description; ?></p> </div>  <?php } ?>   

how can that?

thanks

if understand code correctly, add below css:

.icons-box p:nth-child(-n+3) {     margin-bottom:20px; } 

more on nth-child mdn

the :nth-child(an+b) css pseudo-class matches element has an+b-1 siblings before in document tree, given positive or 0 value n, , has parent element.

this can more described way: matching element bth child of element after children have been split groups of elements each.

the values , b must both integers, , index of element's first child 1.

in other words, class matches children index fall in set { + b; n = 0, 1, 2, ... }.

among other things, allows selectors match every other row in table.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -