oldandintheway
10-08-2011, 03:10 AM
Hi,
This is my first post here. I've looked at a lot of CSS layout, including these (http://www.dynamicdrive.com/style/layouts/category/C13/), but I find it difficult to single out the magic code that makes them work and not mine. They all seem unnecessarily complex with negative margins.
I am trying to understand the problem illustrated by the following code/page. It works and breaks exactly the same on all 4 browsers (IE9, Firefox, Chrome & Safari - all on Windows Vista).
As it's coded below, it works just fine. The green & cyan columns are side-by-side. As soon as I try to add a border around either column (for example - just remove the comment from the "border" attribute on either column), the cyan column drops down to the next row. I understand why that occurs - the border is outside the box width, so when I add the border, the width is now "1px + 20% + 1px" and therefore it can no longer fit in the available 20%.
Yes, I can change the width from 80% to 79% or from 20% to 19% to provide room for the borders, but I want the columns packed tight, with no spacing between them. I can also have widths of 500px and 100px, and when I add a 1px border to the right column, I just change the width from 100px to 98px to make room for the 1px border around it. But I don't like fixed-width blocks - I want %.
So is it possible to specify the widths in %, and allow for changes in styling (add/remove/edit borders), without having to change the widths and still have tightly-packed blocks?
Thanks.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<html>
<head>
<style type="text/css">
html { margin: 0;}
#container { background-color: yellow;
width: 100%;
margin: 0;
padding: 0;
}
#main { float: left;
width: 80%;
background-color: green;
margin: 0;
padding: 0;
/*border: 1px solid magenta;*/
}
#rightcol { width: 20%;
background-color: cyan;
float: right;
margin: 0;
padding: 0;
/*border: 1px solid magenta;*/
}
</style>
</head>
<body>
<div id="container">
<div id="main"><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></div>
<div id="rightcol"><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></div>
</div>
</body>
</html>
This is my first post here. I've looked at a lot of CSS layout, including these (http://www.dynamicdrive.com/style/layouts/category/C13/), but I find it difficult to single out the magic code that makes them work and not mine. They all seem unnecessarily complex with negative margins.
I am trying to understand the problem illustrated by the following code/page. It works and breaks exactly the same on all 4 browsers (IE9, Firefox, Chrome & Safari - all on Windows Vista).
As it's coded below, it works just fine. The green & cyan columns are side-by-side. As soon as I try to add a border around either column (for example - just remove the comment from the "border" attribute on either column), the cyan column drops down to the next row. I understand why that occurs - the border is outside the box width, so when I add the border, the width is now "1px + 20% + 1px" and therefore it can no longer fit in the available 20%.
Yes, I can change the width from 80% to 79% or from 20% to 19% to provide room for the borders, but I want the columns packed tight, with no spacing between them. I can also have widths of 500px and 100px, and when I add a 1px border to the right column, I just change the width from 100px to 98px to make room for the 1px border around it. But I don't like fixed-width blocks - I want %.
So is it possible to specify the widths in %, and allow for changes in styling (add/remove/edit borders), without having to change the widths and still have tightly-packed blocks?
Thanks.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<html>
<head>
<style type="text/css">
html { margin: 0;}
#container { background-color: yellow;
width: 100%;
margin: 0;
padding: 0;
}
#main { float: left;
width: 80%;
background-color: green;
margin: 0;
padding: 0;
/*border: 1px solid magenta;*/
}
#rightcol { width: 20%;
background-color: cyan;
float: right;
margin: 0;
padding: 0;
/*border: 1px solid magenta;*/
}
</style>
</head>
<body>
<div id="container">
<div id="main"><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></div>
<div id="rightcol"><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></div>
</div>
</body>
</html>