- This topic is empty.
-
AuthorPosts
-
November 27, 2013 at 8:34 pm #157277
Jordan Grogan
ParticipantHere’s a link to my pen: http://codepen.io/jordangrogan/pen/bukKo
For some reason, I can’t get the gutters and the images to be right. The images should be 33% of the main div (with 25 px margin on each side) and the gutters should be 25px. Am I missing something easy?
Thanks for any help. Happy thanksgiving!
November 28, 2013 at 6:20 am #157300Paulie_D
MemberAm I missing something easy?
Yes….three times 33.3% does equal 100% but then you are adding in margins so the width will add up to more that 100% of the total width of the wrapper.
So…the images cannot be 33.3% wide but rather [ (100% – 100px) / 3 ]percent wide.
You could use
calc
for this but that will depend on what browser support you need.November 28, 2013 at 8:40 am #157302paulob
ParticipantHi,
Just for fun you could use box-sizing (ie8+) so that padding is included in the width and do something like this.
.main { margin: 25px 25px 0 25px; } img.header { width:100%; } img.small { border:0; width: 33.33%; padding: 25px 17px 0 0; float:left; -moz-box-sizing:border-box; -ms-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; } img.small:nth-child(4), img.small:nth-child(7) { padding:25px 0 0 17px; } img.small:nth-child(3n+3) { padding:25px 9px 0 9px; }
It’s a bit hacky though :)
Note that your use of nth-child is incorrect and that ‘img.small:nth-child(3)’ will look for the third img that is a child and not the third image with a class of .small. It only checks the class when it finds out if its the third-child and then applies the rules if the third child has the class.
In your example the header img is the first child so you would have needed to choose 4 and 7.
November 28, 2013 at 9:13 am #157303Paulie_D
MemberWill that give gutters though?
November 28, 2013 at 10:41 am #157305Merri
ParticipantHere is a slightly advanced sample that gives gutters “by feature” of justified text alignment.
http://codepen.io/Merri/pen/Hvzbf
It gives fixed gutters by using calc as suggested by Paulie_D, and uses fluid gutter width as a fallback for browsers that don’t support calc.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.