Skip to main content
gamedev.net
🔒 Locked

[web] Div Issues

Started by gamechampionx 1 reply 1.3k views
Original Post
gamechampionx
gamechampionx
I've been recently trying to brush up on some html and I've been working on a prototype for a site layout. Here's what it looks like so far: http://www.etherealdivine.com/newsite/proto_unvalidated.html. I do eventually want to get get the menu to fill the same height as the body of the document and vice versa. I've been having a bunch of trouble trying to figure out how to do this. I've tried using CSS to set the height to 100% but from what I've seen, that's all relative to the page size and any container applied to the div (such as another div). Code:

<!--<!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" xml:lang="en" lang="en">
<head>
<title>Prototype</title>
<style type="text/css">
#title {
background-color: yellow;
float: left;
width: 100%;
height: 20%;
}
#menu {
background-color: blue;
float: left;
width: 20%;
}
#main {
background-color: green;
margin-left: 20%;
width: 80%;
}
#pic {
background-color: red;
float: left;
width: 100%;
height: 20%;
}
#contents {
background-color: orange;
float: left;
width: 100%;
overflow-y: auto;
}
#bottom {
background-color: green;
float: left;
width: 100%;
}
</style>
</head>
<body style="background-color: black">
Title
Any tips on getting this to work would be greatly appreciated. Also, when I add the following doctype:

<!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" xml:lang="en" lang="en">
the behavior changes and the height of the title section is shrunk. http://www.etherealdivine.com/newsite/proto_validated.html Validation info: http://validator.w3.org/check?uri=http%3A%2F%2Fwww.etherealdivine.com%2Fnewsite%2Fproto_validated.html&charset=(detect+automatically)&doctype=Inline&group=0 Any help on either of these issues would be great help. The last time I tried to align anything in HTML, it was using tables lol. Thanks in advance.
gamechampionx
gamechampionx
OK, I figured out how to make the document body extend to the window by using: "border: 0; margin: 0;" on the document body.

What I'm still struggling with is vertically resizing divs to fit the entire parent container.

From experimenting here: http://www.etherealdivine.com/newsite/simpletest.html, it appears that setting the height of a div within the main body of a page uses the window size, and not the actual contents of the page. More specifically, the page has only three lines of test, so I was expecting 100% height to correspond to about three lines but instead it fills exactly one page.

<html><head><title>Blah</title></head><body style="height: 100%; border: 0; margin: 0;">
test
test2
test3
test4
</body></html>


Also, I was messing around with the height attribute of the body style and it appears that it also works with respect to the window size and not the contents of the page.

Is there a way, without &#106avascript, to work based on content size rather than window size?
Tesseract
Tesseract
The simple answer is, don't set a height on the body. that way each container will only be as tall as its content.

If you want to have two different background colors, that are always the same height regardless of the amount of content in each one, then you might need to throw a repeating background image in their common parent element. Also, do a Google search for multi-column CSS. This should bring up a plethora of tricks to help achieve the effect you are looking for.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.