How to center li elements in jsquery quicksand plugin

My problem is that in some screen resolutions the list items are not in the center of the div, but <ul>in the center.
Does anyone know a solution?
Thank!

HTML:

<ul class="news-grid">
    <li></li>
    <li></li>
</ul>

Script:

$(function() {
    $('#buttons a').click(function(e) {
        $.get( $(this).attr('href'), function(data) {
            $('.news-grid').quicksand( $(data).find('li'), {adjustHeight: 'dynamic'} );
        }); 
        e.preventDefault(); 
     });
 });

CSS

.news-grid {
    overflow: hidden;
    margin: 0px;
    padding-left: 0px;
    width: 100%;
    line-height: 1.4em;
}

.news-grid:after {
    content: "";
    display: block;
    height: 0;
    overflow: hidden;
    clear: both;
}

.news-grid li {
    display: block;
    float: left;
    width: 217px;
    text-align: left;
    line-height: 17px;
    color: #686f74;
    height: 268px;
    overflow: hidden;
    background: url(../images/item_png8.png) no-repeat top left;
    margin: 0px 0px 20px 30px;
}
+3
source share
2 answers

You can do this quite easily using this css (if you have reset to clear the fields, paddings and ul / li list style). By setting the mapping to a string and not setting the width, each li will be centered along ul text-align: centerand should be relatively evenly positioned due to the correct field.

#news-grid
{
  overflow: hidden;
  text-align: center;
  width: 100%;
  /* whatever other specific styles you want */  
}

#news-grid li
{
  display: inline;
  margin-right: 2%;
  /* whatever other specific styles you want */
}
+2
source

, HTML CSS, , :

  • ResetCss, ?
  • , ?
  • "margin: auto;" "li"?
0

Source: https://habr.com/ru/post/1748523/


All Articles