0

I'm trying to make a nice grid layout using CSS but can't get them to display in rows of 3 with an individual column row of 33.3333%

The grid style I'm going for is this.

Here is the code I have so far;

HTML:

    <section id="web">
   <div class="row">
   <span class="web large-3 columns"><img src="images/1.gif"></span>
   <span class="web large-3 columns"><img src="images/2.jpg"></span>
   <span class="web large-3 columns"><img src="images/3.png"></span>
   </div>
   <div class="row">
   <span class="web large-3 columns"><img src="images/4.jpg"></span>
   <span class="web large-3 columns"><img src="images/5.png"></span>
   <span class="web large-3 columns"><img src="images/6.jpg"></span>
   </div>
</section>

CSS:

section { display: block; }

section#web {
background: #f8f8f8;
padding: 80px 0;
}

.row {
width: 100%;
margin: 0 auto;
max-width: 1144px;
}

span.web {
margin-bottom: 20px;
text-align: center;
position: relative;
border: 1px solid #e3e3e3;
}

.row .large-3 {
position: relative;
width: 33.33333%;
}

.row .columns {
position: relative;
padding-left: .83333em;
padding-right: .83333em;
width: 100%;
float: left;
}

My JSFiddle.

1
  • Could be an issues with the 33.333%, sometimes browsers have different behaviors for decimals. Commented Jul 11, 2014 at 23:52

1 Answer 1

2

You set the width as pixels. Instead, you should use percentages e.g width: 33%. And 33.3 for this layout is a bad choice as you applied 20px for margins. Maybe 28% would be fine.

The fiddle: http://jsfiddle.net/Vfffg/119/

.container > div {
  margin: 20px;
  width: 28%;
  height: 100px;
  background: blue;
  float: left;
  color: #fff;
  text-align: center;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.