Sign in to follow this  
crivens

Help appreciated with CSS/HTML layout issue

Recommended Posts

crivens    182
I don't usually need to delve into CSS much in my job, but once in a while I come across that I can't work out. I've put the HTML/CSS up on jsfiddle:

[url="http://jsfiddle.net/uvByD/3/"]http://jsfiddle.net/uvByD/3/[/url]

It's a simple two column layout, the left column is fixed and the right is fluid. The layout height must be exactly the page height, it cannot exceed the page's height or be less than it.

If you open firebug, the left and right columns both flow underneath the top navbar. They should be pushed down by the navbar but they shouldn't exceed the length of the page as a result. I've tried various options and the one I posted I tried use a margin or padding to push the sidebar and content DIVs down, but this ends up making the page too long.

The contents of the jsfiddle is here:

[source lang="xml"]<!DOCTYPE html>
<head>
<meta charset='UTF-8' />
<title>Test</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#navbar {
width: 100%;
height: 30px;
background-color: yellow;
display: inline;
top: 0;
left: 0;
position: absolute;
}
#wrapper {
background-color: red;
width: 100%;
height: 100%;
}
#main-wrapper {
background-color: blue;
width: 100%;
height: 100%;
}
#sidebar {
background-color: orange;
width: 32px;
height: 100%;
float: left;
display:inline;
}
#content {
background-color: green;
height: 100%;
margin-left: 32px;
}
.clear { clear: both;}
</style>
</head>

<body>
<div id="wrapper">
<div id="navbar"></div>
<div class="clear"></div>
<div id="sidebar"></div>
<div id="content"></div>
</div>
</body>
</html>?[/source]


Any ideas what I'm missing? I can't for the life of me see how to fix this.

Thanks Edited by Mike_Stoddart

Share this post


Link to post
Share on other sites
Anthracis    296
Hallo,
I have just tried the HTML code you posted in IE 8 and in Chrome and was not able to reproduce your issue.
both bars just end with the end of the window. Not exceeding the height in any of those browsers.
So that seems to be a firefox (as I guess from you using firebug) specific formatting issue.

Unfortunately I have no firefox installed on my working machine to take a look at the effect there.

Share this post


Link to post
Share on other sites
Anthracis    296
[quote name='Mike_Stoddart' timestamp='1351162276' post='4993742']
Ok thanks. I don't have access to IE8 but I'll see if I can find someone who uses it. It doesn't work in Chrome either.
[/quote]


that is strange, I tried it in Chrome and for me it worked the way you described it should work.

As I wrote in my previous post I was [b]not [/b]able to reproduce your issue.

By the way I am using Chrome 22.0.1229.94 m Edited by Anthracis

Share this post


Link to post
Share on other sites
crivens    182
Oh geez how embarrassing. My previous version was the one that would extend the page length. In this version the sidebar and content DIVs fill the whole screen and parts of them are hidden beneath the top nav bar. The sidebar and content should be underneath the navbar. I tried pushing them down with a margin but then they extend the page length.

Sorry - I need to stop posting when I'm in a hurry.

Share this post


Link to post
Share on other sites
Anthracis    296
okay, that is different thing. I can reproduce that effect.
I tried positioning the divs all absolute and came up with the following:

[source lang="xml"]<!DOCTYPE html>
<head>
<meta charset='UTF-8' />
<title>Test</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#navbar {
width: 100%;
height: 30px;
background-color: yellow;
display: inline;
top: 0;
left: 0;
position: absolute;
}
#wrapper {
background-color: red;
width: 100%;
height: 100%;
}
#main-wrapper {
background-color: blue;
width: 100%;
height: 100%;
}
#sidebar {
background-color: orange;
width: 32px;
left:0px;
display:inline;
position:absolute;
top:30px;
bottom:0px;
}
#content {
background-color: green;
left: 32px;
position:absolute;
top:30px;
bottom:0px;
}
.clear { clear: both;}
</style>
</head>

<body>
<div id="wrapper">
<div id="navbar"></div>
<div class="clear"></div>
<div id="sidebar"></div>
<div id="content"></div>
</div>
</body>
</html>[/source]

It seems to produce the right result in IE, FF and Chrome.

Hope that helps

Share this post


Link to post
Share on other sites
Maxamor    361
Mike, I can help you with this but I'm confused as to what you're trying to create, exactly. So far this is what I gather:[list]
[*]You want two columns to visually fill the viewport 100% (vertically).
[*]You want to stretch a navigation bar across the top of both columns without causing the document height to be greater than 100%.
[/list]
It possible that you could just create faux-columns using a background image, but the [i]actual[/i] <div> elements won't have 100% height. I would recommend using a technique like this because you'll run into headaches when using height: 100%, especially if you want to introduce margin or padding.

If it would be acceptable to use background-image trickery, and just overlay your "real" columns on top, I would go that route.[list]
[*]You can read about the faux-columns technique here: [url="http://www.alistapart.com/articles/fauxcolumns/"]http://www.alistapart.com/articles/fauxcolumns/[/url]
[*]You can read about an equal-height column technique here: [url="http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks"]http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks[/url]
[/list]
If you need some other kind of solution, we can iterate on your jsFiddle and get things working.

Share this post


Link to post
Share on other sites
crivens    182
[quote name='Anthracis' timestamp='1351185550' post='4993854']
okay, that is different thing. I can reproduce that effect.
I tried positioning the divs all absolute and came up with the following:

[source lang="xml"]<!DOCTYPE html>
<head>
<meta charset='UTF-8' />
<title>Test</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#navbar {
width: 100%;
height: 30px;
background-color: yellow;
display: inline;
top: 0;
left: 0;
position: absolute;
}
#wrapper {
background-color: red;
width: 100%;
height: 100%;
}
#main-wrapper {
background-color: blue;
width: 100%;
height: 100%;
}
#sidebar {
background-color: orange;
width: 32px;
left:0px;
display:inline;
position:absolute;
top:30px;
bottom:0px;
}
#content {
background-color: green;
left: 32px;
position:absolute;
top:30px;
bottom:0px;
}
.clear { clear: both;}
</style>
</head>

<body>
<div id="wrapper">
<div id="navbar"></div>
<div class="clear"></div>
<div id="sidebar"></div>
<div id="content"></div>
</div>
</body>
</html>[/source]

It seems to produce the right result in IE, FF and Chrome.

Hope that helps
[/quote]

Thanks - weird this doesn't work in Chrome 22.0.1229.94 on Fedora 16 for me - the content DIV has no width.

Share this post


Link to post
Share on other sites
crivens    182
[quote name='Maxamor' timestamp='1351186032' post='4993859']
Mike, I can help you with this but I'm confused as to what you're trying to create, exactly. So far this is what I gather:[list]
[*]You want two columns to visually fill the viewport 100% (vertically).
[*]You want to stretch a navigation bar across the top of both columns without causing the document height to be greater than 100%.
[/list]
It possible that you could just create faux-columns using a background image, but the [i]actual[/i] <div> elements won't have 100% height. I would recommend using a technique like this because you'll run into headaches when using height: 100%, especially if you want to introduce margin or padding.

If it would be acceptable to use background-image trickery, and just overlay your "real" columns on top, I would go that route.[list]
[*]You can read about the faux-columns technique here: [url="http://www.alistapart.com/articles/fauxcolumns/"]http://www.alistapar...es/fauxcolumns/[/url]
[*]You can read about an equal-height column technique here: [url="http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks"]http://matthewjamest...er-css-no-hacks[/url]
[/list]
If you need some other kind of solution, we can iterate on your jsFiddle and get things working.
[/quote]

Thanks - I may have already those pages but I'll take a look.

I'm not always the best at explaining what I'm visualising, but the navbar should be height=30px at the top of the screen and fill the screen's width. The two columns should extend vertically from the bottom of the navbar (the navbar shouldn't overlay them and vice versa) to fill the page without extending the page.

Share this post


Link to post
Share on other sites
crivens    182
[quote name='Anthracis' timestamp='1351185550' post='4993854']
okay, that is different thing. I can reproduce that effect.
I tried positioning the divs all absolute and came up with the following:

[source lang="xml"]<!DOCTYPE html>
<head>
<meta charset='UTF-8' />
<title>Test</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#navbar {
width: 100%;
height: 30px;
background-color: yellow;
display: inline;
top: 0;
left: 0;
position: absolute;
}
#wrapper {
background-color: red;
width: 100%;
height: 100%;
}
#main-wrapper {
background-color: blue;
width: 100%;
height: 100%;
}
#sidebar {
background-color: orange;
width: 32px;
left:0px;
display:inline;
position:absolute;
top:30px;
bottom:0px;
}
#content {
background-color: green;
left: 32px;
position:absolute;
top:30px;
bottom:0px;
}
.clear { clear: both;}
</style>
</head>

<body>
<div id="wrapper">
<div id="navbar"></div>
<div class="clear"></div>
<div id="sidebar"></div>
<div id="content"></div>
</div>
</body>
</html>[/source]

It seems to produce the right result in IE, FF and Chrome.

Hope that helps
[/quote]

The content DIV has no width in Firefox 16 either.

Share this post


Link to post
Share on other sites
Anthracis    296
Yes you are absolutely right.
I did not pay attention to the background color, else I should have seen that.

I forgot to set the right coordinate of the content div to 0px.
so the complete version should be :

[CODE]
<!DOCTYPE html>
<head>
<meta charset='UTF-8' />
<title>Test</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#navbar {
width: 100%;
height: 30px;
background-color: yellow;
display: inline;
top: 0;
left: 0;
position: absolute;
}
#wrapper {
background-color: red;
width: 100%;
height: 100%;
}
#main-wrapper {
background-color: blue;
width: 100%;
height: 100%;
}
#sidebar {
background-color: orange;
width: 32px;
left:0px;
display:inline;
position:absolute;
top:30px;
bottom:0px;
}
#content {
background-color: green;
left: 32px;
position:absolute;
top:30px;
bottom:0px;
right:0px;
}
.clear { clear: both;}
</style>
</head>

<body>
<div id="wrapper">
<div id="navbar"></div>
<div class="clear"></div>
<div id="sidebar"></div>
<div id="content"></div>
</div>
</body>
</html>
[/CODE]

at least that works for me now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this