Css layout help

Associate
Joined
19 Jul 2006
Posts
1,847
sorry for a noob question about css.
Im just trying to make a simple layout similar to this
layout-1.jpg

i want pinstriping round the outside, then a div at the top for the logo,
a navbar that i can use graphics in inderneth the logo the main content area,
and a footer.

How do i go about doing this
 
Create a div for the central column as the container and set the CSS so that it's centralised.

example:

#container {
width:??px;
margin:0 auto;
}

or

#container {
width:??px;
position:relative;
margin-left:auto;
margin-right:auto;
}

should do the trick for the container

then every div inside the container div will automatically only be as wide the container div.

so you just create the log div with a specified height, then the nav div, then content, then footer etc.

if you want two divs to float side by side you will need to use the float:left; CSS attribute to make this happen.

For the background you can just give the "body" a background in CSS or you can create a div for the page and put the container div inside of that.
 
Cheers
i have got
Code:
<html>
<head>
<title> Tin Can Art </title>
<LINK href="style.css" type=text/css rel=stylesheet>
</head>
<body>
<DIV id=container>
hello</DIV>
</body>
</html>

and
Code:
BODY {
	
	FONT: 0.9em mangal,  verdana, arial, sans-serif;
	COLOR: #000;
	BACKGROUND: url("stripe.png") #000000;
}

#container {
width:800px;
margin:0 auto;
background-color:#FFFFFF
}

Whys it not in the middle

I see it works in FF but not IE how do i get around this
 
something weird in your code, try this instead:

HTML

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">

<head>

  <title>Tin Can Art</title>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <link href="style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="container">

hello

</div> <!-- End of "container" div -->

</body>

</html>

CSS

Code:
body
{
	margin: 0;
	padding: 0;
}

#container	{
	margin: 0 auto;
	position: relative;
	width: 800px;
	background: #000;
	color: #fff;
}

also you should avoid using capital letters in HTML/CSS where possible :0)
 
Last edited:
Cheers.

I got this now
html
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">

<head>

  <title>Tin Can Art</title>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <link href="style.css" rel="stylesheet" type="text/css" />

</head>


<body>
<div id=container>
<div id=logo>
<img src="logo copy.gif" alt=" Logo" >
</div>
<div id=logospace>
</div>
<div id=navbar>
<ul>
<li> Home </li>
<li> News </li>
<li> My Art </li>
<li> Events </li>
<li> Contact Me </li>
</ul>
</div>
<div id=content>
hello 
</div>
<div id=footer>
hello
</div>
</div>
</body>
</html>

and CSS
Code:
body  {
	color: #000;
	font: 0.9em verdana, arial, sans-serif;
	background: #000000 url("stripe.png") repeat;
	text-align: center;
	min-width: 800px;
}
/* container is the box for the middle all div tags should be nested in here */
#container {
width:800px;
position:relative;
margin-left:auto; 
margin-right:auto;
background-color:#000;
}
/*logo creates the div tag for the logo to fit in */
#logo {
float:left;
width:160px;
height:170px;
background-color:#000;
}
/*logospace creates the div for the black space on the right of the logo just to fil the row */ 
#logospace{
float:right;
width:640px;
height:170px;
background-color:#000000;
}

/*navbar */
#navbar{
float:left;
height:80px;
background-color:#CC0099;
}

	#navbar ul li{
	width:160px; 
	[COLOR="Red"]display:inline;
	text-decoration:none;
	list-style-type:none;[/COLOR]
	text-align:center;
	}

	
/*main content. clear gets rid of floating eliments.*/
#content{
clear: both;
height:auto;
background-color:#aa0099;
}
/*footer*/
#footer {
	clear: both; 
	 width: 800px;
	  color: #888; 
	  padding-top: 20px; 
	  text-align: right;
}

Applogies for the colours its just so i know where the divs are.
Just my nav list, is not displaying horizontaly and it still has bullit points in there. Even though i think in the CSS i have set it to no decoration and dispaly:inline.

What have i done wrong?

FOUND IT!!! need to name navbar all the same all the way through
 
Last edited:
Some tips:

1) by default divs will normally fill the width of the container div, if you set the height of the div you should see that it automatically fills the width of the container. This is why I suggested making a container div with your desired width so all the divs inside of it fit nicely.

2) Don't put text-align: center; on your body unless you want all your text everywhere to be centre aligned, it's better to specify text-alignment on individual divs (default alignment is left).

3) Use <br /> tags to clear floats, in my example below I used a <br /> tag to clear the floats after the navbar.

4) Use different colours for your div backgrounds, how can you see where everything is going when they are mostly black bg's? :)

5) you can use photoshop to help you pick colours etc, I do this a lot with the colour picker tool.

6) Put spaces and indents in your code, how will you manage a page that is 400-500 lines if there is no formatting on the text. indents can be used so you can easily see the sections, how you do this is up to you. Spaces and indents aren't included when the code is processed.

At the moment your code is very ugly, and I am saying this to help you! :)

7) Don't leave spaces between tags unless you have a reason, for example:

<li> Contact Me </li> - is wrong

<li>Contact Me</li> - is right

8) You will find you have to sometimes set margins to 0 in the CSS, for example I had to put margin: 0; in your body to stop firefox adding a margin to the top of the page. I also had to put this CSS on your ul tags so that the navbar sat right:

ul {
padding: 0;
margin: 0;
}

9) Always set the text-alignment on the block level (div) elements, setting text-align: center; on the unordered list (ul) will not make a difference as it's an inline element.

10) Check and double check that the page looks fine between IE and Firefox at intervals, I have had messy things in the past when you don't. Especially where floats and divs are concerned.

11) I have put a text hyperlink into your menu, you will need to adjust the text styles in the CSS for the link, visited, hover, and active styles of the text. text-decoration: none; and then setting your own fonts, colours etc is a good idea. (these need to be entered in the order I put them in, best way to remember this is Love Hate.)

I have included some ammendments I made below to give you more of an idea:

HTML

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">

<head>

  <title>Tin Can Art</title>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <link href="style.css" rel="stylesheet" type="text/css" />

</head>


<body>

<div id=container>

	<div id=logo>

	<img src="logo copy.gif" alt="Logo" />

	</div>

<div id=navbar>

	<ul>
	<li><a href="http://www.google.co.uk">Menu Hyperlink Example</a></li>
	<li>News</li>
	<li>My Art</li>
	<li>Events</li>
	<li>Contact Me</li>
	</ul>

</div>

<br />

<div id=content>
 
Page content goes here

</div>

	<div id=footer>

	Footer goes here

	</div>

</div>

</body>

</html>

CSS

Code:
body  {
	color: #fff;
	font: 0.9em verdana, arial, sans-serif;
	background: gray url("stripe.png") repeat;
	min-width: 800px;
	margin:0;
}

/* container is the box for the middle all div tags should be nested in here */
#container {
width: 800px;
position: relative;
margin-left: auto; 
margin-right: auto;
background-color: #fff;
}

/*logo creates the div tag for the logo to fit in */
#logo {
text-align: left;
height: 170px;
background-color: blue;
}

/*navbar */
#navbar{
float:left;
height:30px;
background-color:#CC0099;
text-align: center;
}

	#navbar ul li{ 
	display:inline;
	text-decoration:none;
	list-style-type:none;
	}

ul	{
	padding: 0;
	margin: 0;
}

	
/*main content. clear gets rid of floating eliments.*/
#content{
background-color: green;
}
/*footer*/
#footer { 
	color: #888;
	height: 50px;
	background: navy;
	text-align: right;
}

br	{
	clear: both;
}

a.link	{
	
}

a.visited	{

}

a.hover	{

}

a.active	{

}
 
Last edited:
Cheers this stuff is really helping me. I have tryed to comment my code better, and that margin thing solved a problem i was having with using background images in the navbar.

I was wondering how you would do this simpler
Code:
#navbar ul li{
float: left;
width: 160px;
height: 50px;
display: inline;
text-decoration: none;
line-height: 40px;
text-align: center;
background-image: url(bg1.png);
}

ul	{
	padding: 0;
	margin: 0;
}

#navbar ul li a{
float: left;
width: 160px;
height: 50px;
display: inline;
text-decoration: none;
line-height: 40px;
text-align: center;
background-image:url(bg1.png);
}
#navbar ul li a:hover{
float: left;
width: 160px;
height: 50px;
display: inline;
text-decoration: none;
line-height: 40px;
text-align: center;
background-image:url(bg2.png);
}

What im wanting to do is when the mouse goes over the link the back ground changes. i tried just using
#navbar ul li a:hover{
background-image:url(bg2.jpg);
}

but this didnt keep the image the correct size
 
Got the site up now http://www.tincanart.co.uk

But the black main container moves positions when theres pictures on the page can i stop this happening?

CSS
Code:
abody  {
	color: #000;
	font: 0.9em verdana, arial, sans-serif;
	background: #000000 url("stripe.png") repeat;
	text-align: center;
	min-width: 800px;
		}
/* container is the box for the middle all div tags should be nested in here */
#container {
	width: 800px;
	position: relative;
	margin-left: auto; 
	margin-right: auto;
	background-color: #000;
	}


/*logo creates the div tag for the logo to fit in */
#logo {
	float: left;
	width: 160px;
	height: 170px;
	background-color: #000;
	}
	
	
/*logospace creates the div for the black space on the right of the logo just to fil the row */ 
#logospace{
	float: right;
	width: 640px;
	height: 170px;
	background-color: #000000;
	}

/*navbar */
#navbar{
	width: 800px;
	}

#nav ul{
	list-style-type: none;
	}
/*sets the attributes for the navbar*/
#navbar ul li{
	float: left;
	width: 160px;
	height: 50px;
	display: inline;
	text-decoration: none;
	line-height: 40px;
	text-align: center;
	background-image: url(bg1.png);
	color: #000;
	font-family: forte, verdana, arial, sans-serif;
	font-size: 20px;
	line-height:50px;}
/*makes the navbar work properly keep in*/
ul	{
	padding: 0;
	margin: 0;
	}
/*navbar link needs to be similar to navbar*/
#navbar ul li a{
	float: left;
	width: 160px;
	height: 50px;
	display: inline;
	text-decoration: none;
	line-height: 40px;
	text-align: center;
	background-image:url(bg1.png);
	color: #fff;
	font-family: forte, verdana, arial, sans-serif;
	font-size: 20px;
	line-height:50px;}
/*navbar hover needs to be similar to link*/	
#navbar ul li a:hover{
	float: left;
	width: 160px;
	height: 50px;
	display: inline;
	text-decoration: none;
	line-height: 40px;
	text-align: center;
	background-image:url(bg2.png);
	color: #000;
	font-family: forte, verdana, arial, sans-serif;
	font-size: 20px;
	line-height:50px;}
	
/*main content. clear gets rid of floating eliments.*/
#content{
	clear: both;
	height: auto;
	background-color: #000;
	color: #fff;
	font-family: verdana, arial, sans-serif;
	font-size: 16px;
	padding-top:10px;
	padding-right:10px;
	}
/*class for images on homepage div*/
div.thumbnail
{
float:left;
margin: 10px;
width: 320px;
}

/* sets the properties for the images on home page*/
div.thumbnail img
{ 
margin-top:10px;
margin: 10px;
}

/*class for images on homepage div*/
div.gallery
{
float:left;
margin: 10px;
width:780px;
}

/* sets the properties for the images on art page*/
div.gallery img
{ 
float:left;
margin-top:10px;
margin: 10px;
width:400px;
height:300px;
}

div.gallery p 
{
margin: 0;
padding: 10px;
Padding-top: 110px;
}
 
.clear{
clear:left;
}

#content a {
	color: #46e0f1; 
	text-decoration: underline;
	text-align: right;
	}
#content a:visited {
	color: #46e0f1; 
	text-decoration: underline;
	text-align: right;
	}
#content a:hover {
	color: #46e0f1; 
	background-color: #fe4144;
	text-align: right;
	}
/*footer*/
#footer {
	  clear: both; 
	  width: 800px;
	  color: #888; 
	  text-align: right;
	}

#footer a {
	color: #46e0f1; 
	text-decoration: underline;
	}
#footer a:visited {
	color: #46e0f1; 
	text-decoration: underline;
	}
#footer a:hover {
	color: #46e0f1; 
	background-color: #fe4144;
	}
 
The black container 'moves' position because the pages which have pictures are longer than the viewport so they have scrollbars. Nothing you can do about it really other then having content on all your pages which will be longer than the viewport - but even then, larger resolution monitors = more viewport.


The CSS for your nav is still really really sloppy. I'll clean it up later for you if you'd like.

You're also much better off using 'em' for font size rather than px.
Read the following for more info.
http://www.clagnut.com/blog/348/
 
Last edited:
Cheers Tripnologist,

I found that there was some margins in there that wasnt needed.
Dont really know about em's bur that blog loogs good.

If you could tidy the nav up that would be wonderful. All i know is that it works :) but im sure theres a neater way of doing it.
 
Download google chrome and open your page in that. Right click somewhere on your page
and click inspect element. You'll then get a list of all the css styles that are being applied directly and indirectly (in herited) to that tag.

You can then spot some of the errors you've decribed above.
 
Back
Top Bottom