4

Its easy to see. In example 1 all works pretty well, but when I add one line of code more in example 2), it's breaking. Why? And how I should code it?

Example 1: http://jsfiddle.net/sUtvd/154/

[...].tripple {
width: 90%;
margin: 5%;
}[...]

Example 2: http://jsfiddle.net/Ec95D/3/

[...].tripple {
width: 90%;
margin: 5%;
border: solid;
}[...]
JJJ
  • 32,902
  • 20
  • 89
  • 102
Patryk Perduta
  • 366
  • 1
  • 2
  • 9
  • But, wait why in second example your dont have any border value? It is about border.. Or maybe I'm missing something – Szymon Nov 06 '13 at 16:05

6 Answers6

1

Add float:left to .tripple if border should go all way around divs

srdjans
  • 11
  • 3
1

Add

display: inline-block;

to .tripple

http://jsfiddle.net/LaN5z/1/

ZimTis
  • 179
  • 9
0

You need to clear the floats. When all of the child elements are floating, the parent is not aware of their height, and so collapses. Putting something like a clearfix on the parent should fix the problem. See http://nicolasgallagher.com/micro-clearfix-hack/ for details on the clearfix.

See http://jsfiddle.net/designingsean/Ec95D/4/ for a working example. CSS from the link is below. Then just add .cf to the parent element.

.cf:before,
.cf:after {
  content: " ";
  display: table;
} 

.cf:after {
  clear: both;
}

You could also make the parent have an overflow set to pretty much anything, though auto makes the most sense in most cases. See http://jsfiddle.net/designingsean/cx7Wg/ for a working example of that.

For more on clearfix vs overflow, check out this pretty solid SO question and answer: What methods of ‘clearfix’ can I use?

Community
  • 1
  • 1
Sean Ryan
  • 6,048
  • 2
  • 25
  • 23
0

You should clear your floats: you can use this standard css from HTML5 biolerplate:

.clearfix:before,
.clearfix:after {
    content: " ";
    display: table;
}

.clearfix:after {
    clear: both;
}

Fiddle

<div class="tripple clearfix">
dezman
  • 18,087
  • 10
  • 53
  • 91
0

I personally use a div which is to clear:both for these occasions. Check this fiddle.

http://jsfiddle.net/Ec95D/7/

2hamed
  • 8,719
  • 13
  • 69
  • 112
0

The float property in:

.left, .right, .middle {
    float:left;
    width: 33%;
    height: 100px;
}

makes the parent div empty. Float is a CSS positioning property.

There could be a better approach, but a simple way is to put each colored box in a table with 0 cell spacing and padding.

oski
  • 261
  • 2
  • 3