views:

86

answers:

1

I have a css style, which when applied to a static html page works fine.

The problem is, that content is dynamically loaded, into layer3, and then into layer 2.

I don't really understand the consistency. Sometimes the layers are far apart, sometimes they are meshed over each other.

Why is this happening, and how can I keep layer3 in a static position?

An example of the layers being very far apart:

<html><head>
<title>Test page</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<div id="Layer0">
<div id="Layer1" class="Layer1">
<h3 align="left">A menu</h3>
<div align="left">
<ul class="BLUE">
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
</ul>
</div>
</div>
<div id="Layer2">
<div id="leftlayer" class="leftlayer">
<form name="searchForm">
An example form: 
<input name="search" type="text">
<br>
<input name="Submit" value="Update" onclick="searchUserInfo('parallelimport');return false" type="submit">
</form>
</div></div>
<div id="Layer3"><h1> Why is the layer so far away?</h1>
</div>
</div>
</div>
</body></html>

An example of the layers being merged

<html><head>
<title>Test page</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<div id="Layer0">
<div id="Layer1" class="Layer1">
<h3 align="left">A menu</h3>
<div align="left">
<ul class="BLUE">
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
</ul>
</div>
</div>
<div id="Layer2">Content goes here</div>
<div id="Layer3">
<h1>Why is the layer up here now?</h1>
<table width="100%" border="0">
<tbody>
<tr>
<td width="15%">This wrecks</td>
<td width="10%">The very</td>
<td width="65%">Layout of the page</td>
</tr>
</table>
</div>
</div>
</div>
</body></html>

An example of what I am trying to achieve:

<html><head>
<title>Test page</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<div id="Layer0">
<div id="Layer1" class="Layer1">
<h3 align="left">A menu</h3>
<div align="left">
<ul class="BLUE">
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
</ul>
</div>
</div>
<div id="Layer2">
<h1>I would like information to be here</h1>
<div id="Layer3">
<h1>And then the table to be below the above info</h1>
<table width="85%" border="0">
<tbody>
<tr>
<td width="15%"><strong>This is</strong></td>
<td width="20%"><strong>much better</strong></td>
</tr>
</tbody>
</table>
<h1>I would like the Layer 3 to always be in a constant position</h1>
<h1>Does this mean I should have it outside of Layer2?</h1>
</div>
</div>
</div>
</body></html>

My CSS:

#Layer0 {
  width: 100%;
  height: 100%;
}

body{
margin:10px 10px 0px 10px;
padding:0px;
color:#999999;
font-family:"Trebuchet MS",arial,sans-serif;
font-size:70.5%;

}

#Layer2 {
background:#fff;
color:#000;
voice-family: "\"}\"";
voice-family: inherit;
padding:20px;

}

#Layer2 p {color:#888;}

#Layer2 a, a:link { color:#006633; text-decoration: none;}

#Layer2 a:hover, a:active{ color:#FF6666; text-decoration: none;}

html>body #Layer2 {
}

p,h1,pre {
margin:0px 10px 10px 10px;
font:Arial, Helvetica, sans-serif;
font-size:12px;
line-height: 1.6em;
text-align:justify;
text-decoration:none;
}

h1 {
font-size:2.5em;
text-align: center;
color:#ccc;
padding-top:15px;

}

h3 {
font-size:14px;
color:#999;

}

.leftlayer {
  float: left;
  left: 20%;
  width: 20%;
  height: 100%;
  margin-right: 10%;
}
.leftlayer strong {
  text-align: left;
}
.leftlayer2 {
  float: left;
  width: 20%;
  height: 100%;
  margin-left: 2%;
}
#rightlayer {
  float: left;
}
#Layer3 {
  float: bottom;
}
+2  A: 

Adding borders to your various layout elements can really help debug when you're faced with a tricky CSS issue. For instance, if you add the following to your .leftlayer CSS class, you'll see what's wrong with the first example you posted:

 border: 1px dashed #ccc;

You'll notice that the div surrounding your form with class="leftlayer" is pushing Layer3 to the right. This happens because the leftlayer div appears before the Layer3 div in the HTML flow. In order to get a better result, move Layer3 above the .leftlayer, like this:

<div id="Layer3">
 <h1> Why is the layer so far away?</h1>
</div>
<div id="Layer2">
 <div id="leftlayer" class="leftlayer">
  <form name="searchForm">
   An example form: 
   <input name="search" type="text">
   <br>
   <input name="Submit" value="Update" onclick="searchUserInfo('parallelimport');return false" type="submit">
  </form>
 </div>
</div>

I'm not sure if that's exactly what you needed to achieve, but it's a start.

Floats can really muck with your layout, so it helps to understand the box model quite thoroughly. I find this is a great reference article: http://www.brainjar.com/css/positioning/default.asp

zombat