html - Is it possible to centralize a grid using only CSS? -


considering grid contains fixed size items (not choice), , not fixed size.

i centralize container (.grid-container) have same side margin no matter how many items have , how placed inside container long left-aligned.

if isn't possible css how can using javascript?

it's not necessary use twitter-bootstrap grid system demo code.

enter image description here

here code illustrate: https://embed.plnkr.co/f6niiwaosno8tr0ss4xf/

.container {    background-color: #2b3643;  }    .grid-container {    padding: 30px 30px 0 30px;  }    .grid-item-wrapper {    width: 200px;    margin-bottom: 15px;  }    .grid-item {    margin-bottom: 15px;  }    .grid-item > .item-desc {    padding: 8px;    background-color: #333333;    color: #cfcfcf;  }               
  <div class="container">      <div class="grid-container row">        <!-- grid items -->      </div>    </div>    <template id="tmpl_grid_item">      <div class="grid-item-wrapper col-xs-3">        <div class="grid-item">          <div class="item-picture">            <img src="http://lorempixel.com/350/200/food/" style="width: 100%;" />          </div>          <div class="item-desc">            lorem ipsum          </div>        </div>      </div>    </template>

if willing use absolute positioning , css3, there way.

html:

<div class="grid">    <div class="item"></div>    <div class="item"></div>    <div class="item"></div>    <div class="item"></div> </div> 

css:

 .grid{     position: absolute;     width: auto;     left: 50%;     -ms-transform: translatex(-50%); /* ie 9 */     -webkit-transform: translatex(-50%); /* safari */     transform: translatex(-50%);  }  .item{     width: 50px;     height: 50px;     background: #fff;     float: left;     margin: 20px; } 

here working fiddle. hope helps!


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -