Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIV gap at top of page

Status
Not open for further replies.

PerlIsGood

Programmer
Jan 24, 2002
154
US
This is my first trip into "no-tables" design. I have a gap at the top of my page and I can't seem to get rid of it. I'm pretty sure the culprit is the relative-position menu bar I'm adding (div#menu). (example here).

So what am I doing wrong?

HTML:
Code:
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>...text</title>
<link rel="stylesheet" href="main.css" type="text/css" />
<!--[if IE]>
	<link rel="stylesheet" href="ie.css" type="text/css" />
<![endif]-->
</head>
<body>

<div id="menu">
	<script type="text/javascript" src="tab_menu.js"></script>
</div>
<div id="logo">
	<img src="picts/logo.jpg" alt="...text" />
</div>
<div id="flash">...flash</div>

<div id="content">
	<h1>H1</h1>
	<p>...text</p>
	<p>...text</p>
	<p>...text</p>

	<h1>H1</h1>
	<p>...text</p>
</div>

<div id="sub0"></div>
<div id="sub1">
	<h2>H2</h2>
	...text
</div>
<div id="sub2">
	<h2>H2</h2>
	...text
</div>
<div id="pipe">
	<script type="text/javascript" src="menu.js"></script>
</div>
<div id="footer">
	<script type="text/javascript" src="copyright.js"></script>
  </p>
</div>

</body>
</html>

CSS:
Code:
/* =========== */
/* PAGE LAYOUT */
/* =========== */

body {
	margin: 0px;
	background-color: #fff;
	font-family: arial;
}

div {
	margin: 0px;
	border-style: solid;
	border-width: 0px;
	border-collapse: collapse;
}

div#logo {
	background-color: transparent;
	background-image: url("picts/pipe.jpg");
	float: left;
	text-align: left;
	width: 70%;
	height: 150px;
}

div#flash {
	background-color: transparent;
	background-image: url("picts/pipe.jpg");
	float: right;
	text-align: right;
	width: 30%;
	height: 150px;
	clear: right;
}

div#menu {
	position: relative;
	top: 125px;
	left: 279px;
	background-color: transparent;
	padding-bottom: 0px;
	padding-top: 5px;
	text-align: left;
	height: 25px;
	min-width: 100px;
	max-width: 450px;
	z-index: 1;
	display: inline;
	overflow: hidden;
}

div#pipe {
	background-color: #0f4174;
	padding-top: 0px;
	text-align: center;
	vertical-align: top;
	height: 25px;
	clear: both;
}

div#content {
	padding: 8px;
	background-color: #fff;
	text-align: justify;
	min-height: 150px;
	width: 75%;
	float: left;
}

div#sub0 {
	background-color: transparent;
	max-height: 3px;
	min-height: 3px;
	clear: right;
}

div#sub1 {
	background-color: #0f4174;
	width: 18%;
}

div#sub2 {
	background-color: #888;
	clear: right;
	width: 18%;
}

div#sub1, div#sub2 {
	text-align: left;
	font-size: 10pt;
	padding: 15px;
	min-height: 185px;
	float: right;
	margin: 3px 2px 3px 0px;
	-moz-border-radius-topleft: 2em;
	-moz-border-radius-bottomleft: 2em;
	-moz-border-radius-bottomright: 2em;
	border-width: 1px 1px 1px 1px;
}

div#footer {
	background-color: transparent;
	background-image: url("picts/bottom-shade.gif");
	background-repeat: repeat-x;
	text-align: left;
	width: 100%;
	height: 20px;
	clear: both;
}

Notorious P.I.G.
 
Wow, all I can say. Congratulations that only that is wrong with your layout.

I have suggested this to someone already today, so here's the second time. Start slow. Work out the page on paper first and think about it. Then read about how things are done. Start simply. Create containers. Keep document flow. If you stumble on a problem, look for a solution online (chances are someone wanted to do the same before you), maybe ask questions at a place like this. Then continue.

What you gave us, is a terrible mess of complete lack of understanding of css and how positioning works. Relatively positioned item 125px from a top, with minimum and maximum width and at the same time being inline??? And you ask why is there a gap at the top? This needs a rework.
 
That's exactly what I did. I sketched the layout on paper, then moved to my text editor creating some blank-ID divs. Then one-by-one I defined each div-class, carefully watching the layout unfold.

Unfortunately div#menu got added as an afterthought and now I'm having trouble getting it into the normal flow of the document. There is also quite a bit of bloat in that declaration due to me trying to figure out how to fit it properly. If I remove that one div, the layout works great...

Which is what brings me here. Any other suggestions?

Notorious P.I.G.
 
I don't understand. The #menu must fit somewhere. If your layout is flowing, I can't see the problem of just flowing another element inside. Maybe if we saw the page, we would understand the problem easier. But you can change the html and css I presume, so you can stick #menu wherever it should be flowing normally.
 
Yeah I'm confused by that too. I've only been using divs for about 24 hours, but it was my understanding that if I used :relative positioning it would take that element out of the normal flow, without rendering the location it would reside if I used :static or no positioning... but that's exactly what it's doing. My understanding is probably incorrect though...

No matter where I move that particular div statement, the place the div would be rendered in normal mode still gets rendered as a blank space, as well as the location where I want it to show...

I'd point you to the page, but it's not on any servers at the moment. I listed enough code above that the html page and css can be created manually by copying to local files, if you're curious.

Notorious P.I.G.
 
Incidentally, you might want to get your (X)HTML validating. I doubt very much whether the missing "p" tag here will validate OK:

Code:
<div id="footer">
    <script type="text/javascript" src="copyright.js"></script>
  </p>
</div>

I've got to wonder why you don't just put the footer text in, rather than relying on JS. It seems like you go to all this trouble to provide a nice accessible design, and then force people without JS to see no menu or no footer.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yeah I caught that trailing <p> tag last night. Not sure what it was doing there, but without it both my html and css validate (without FF proprietary elements).

I'm still debating on how to handle footers and other common page elements. JS was a quick and dirty solution, I may switch to PHP before I'm finished. But seriously, how many people these days don't have JS enabled?

Notorious P.I.G.
 
But seriously, how many people these days don't have JS enabled?

That's not the point I was making. The point I was making is that why bother going to a nice fluid, accessible design, and ruining it by using JavaScript to output content.

Look at it this way: "How many users can't view tables"? Less than surf with JS disabled, I'll wager... but yet you're still taking the time and effort to build a table-less design.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yeah you have a valid point. As I mentioned, I'll work out a server side solution before I'm finished with this thing.

Anyway, thanks for the input guys. :)

Notorious P.I.G.
 
Oh, and roughly (it's very hard to define as it depends on your target audience) around 1 in 10 of visitors to your site may not have javascript capabilities:




____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top