Forum Moderators: not2easy

Message Too Old, No Replies

width percent problem

         

dmd_anfini

8:33 pm on Feb 8, 2010 (gmt 0)

10+ Year Member



hi there, I am starting in css and html, and as a first try I want to make a fluid page with two divs. The problem is that the defined percentage dimension for the divs does not function. Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="css/teste.css" />
<title>Insert title here</title>
</head>
<body>

<div id="d1">
</div>

<div id="d2">
</div>

</body>
</html>


here is the css


@CHARSET "ISO-8859-1";

body {
background-color: rgb(0,200,200);
width: 100%;
height: 100%;
}

#d1 {
background-color: rgb(0,0,255);
width: 100%;
height: 20%;
}


#d2 {
background-color: rgb(0,255,255);
width: 100%;
height: 80%;
}


All I get is two divs with the default dimensions. Strange, when I change the css to this it functions correctly


@CHARSET "ISO-8859-1";

* {
width: 100%;
height: 100%;
}

body {
background-color: rgb(0,200,200);
width: 100%;
height: 100%;
}

#d1 {
background-color: rgb(0,0,255);
width: 100%;
height: 20%;
}


#d2 {
background-color: rgb(0,255,255);
width: 100%;
height: 80%;
}


I thought that setting the body width and height would do the job, but it seems it doesn't. What I'm doing wrong?

bzgzd

1:38 am on Feb 9, 2010 (gmt 0)

10+ Year Member



There is also html element.

If you set height or width: 100%
you are setting it to the same width as is width of its parent. And parent of <body> is <html>

To test it try adding something like
html { width: 200px; height: 500px; }

So to get full page you can set html to 100% but then it is good to reset margin and padding for html and body also.
html, body {
background-color: red;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}

dmd_anfini

3:13 am on Feb 9, 2010 (gmt 0)

10+ Year Member



thanks bzgzd that solved the problem