Wednesday, December 17, 2014
Columns dropping off
I’ve talked about using gridsin designing websites previously, aligning your elements to a formula to create consistency and harmony. It isn’t hard to integrate into your design process, but issues can pop up in putting the layout to code; one such problem is columns dropping off.
As seen in this example image the issue is that the margin (in red) of the object (in yellow) extends past the main containers boundary (in black) . There are two solutions to this problem, the first and the most obvious is to apply a special class to the last column. This is what I have personally used in the past for what its worth.
In a four column layout I will name the class col1 and use it for the first three columns, the fourth and last I will call col4. In my style sheet I set the width of all the columns to 200px and a right margin of 10px, but below that for col4 I rescind that order.
CSS
[sourcecode language=’css’]
.col1, .col4{
width:200px;
margin-right:10px;
}
.col4 {
margin-right:0px;
}
[/sourcecode]
HTML
[sourcecode language=’html’]
Clinical Depression
Government of Canada
deviantART
NortheastEnder
[/sourcecode]
The other method is probably the better solution, and the easiest to maintain, esspecialy if you have a dynamic list of items. First you switch up the margin to the left side of the columns, then you give the group a negative margin. You can wrap it in a div or use an unordered list to accomplish this. But the result is the left most margin is cancelled out.
CSS
[sourcecode language=’css’]
.work{
width:950px;
margin-left:-10px;
}
.col1{
float:left;
margin-left:10px;
width:200px;
}
[/sourcecode]
HTML
[sourcecode language=’html’]
Clinical Depression
Government of Canada
deviantART
NortheastEnder
[/sourcecode]
Your mileage may vary depending with your settings, but these techniques never fail me.
No comments: