html - How make 4 items fit perfectly inside the container -
codepen - http://codepen.io/anon/pen/zgyqej
i need make 4 items fit inside container , each item must have 5px margin of other. i'm trying never perfect, mean perfect? first item should in far left, , last @ far right, , yet 4 items need far apart 5px .
code:
html:
<section class="statistics"> <div class="container"> <h2 class="statistics__title">estátisticas</h2> <ul class="statistics__list"> <li class="statistics__item"></li> <li class="statistics__item"></li> <li class="statistics__item"></li> <li class="statistics__item"></li> </ul> </div> </section>
css:
.container { box-sizing: content-box; padding-left: 3%; padding-right: 3%; margin-left: auto; margin-right: auto; } .statistics__title { margin: 15px 15px 15px 0; font-weight: lighter; } .statistics { width: 100%; } .statistics__list { margin: 0; padding: 0; list-style: none; } .statistics__item { margin: 0 5px; display: inline-block; width: 23%; height: 230px; background-color: #fff; border-radius: 5px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24); }
try usin pseudo-class :last-child
on .statistics__item
this way can give elements margin-right:5px
except last element, causing first item in far left, , last @ far right while 4 items seperated margin of 5px.
box-sizing:content-box; padding-left:3%; padding-right:3%; margin-left:auto; margin-right:auto; } .statistics__title { margin: 15px 15px 15px 0; font-weight: lighter; } .statistics { width: 100%; } .statistics__list { margin: 0; padding: 0; list-style: none; } .statistics__item { margin-right: 5px; display: inline-block; width: 23%; height: 230px; background-color: #fff; border-radius: 5px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24); } .statistics__item:last-child { margin-right: 0px; }
<section class="statistics"> <div class="container"> <h2 class="statistics__title">estátisticas</h2> <ul class="statistics__list"> <li class="statistics__item"></li> <li class="statistics__item"></li> <li class="statistics__item"></li> <li class="statistics__item"></li> </ul> </div> </section>
Comments
Post a Comment