Newbie Div issue

Hi guys,

I’m a New User of CSS and seem to be havign a spot of bother making a <div> centre. I was under the impression that I set margin:auto; in my css (have also tried margin-left (and right):auto; ) however for some reason the <div> is stayed left justified.

Please can you assist before i go mad! ( well madder)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<title>TDP Surveyors - Surveying & Valuations experts in Cornwall</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/css/tdp.css"

<body class='background'>
	<div class="body"> 
			<div class="logo"><img src="/images/TDp-Square-green-txt1.jpg" /></div>



with associated CSS

background-color: #333333;

.body { 
	padding: 3px; 
	border: 1px solid black;
	background-color: white; 

the weirdest thing is that wheni preview in browser from dreamweaver it works, but when uploaded and viewed via the web it becomes justified tot he left!?!?!?

Your <link> element isn’t closed. That might be causing some kind of a problem. If you only want to center an image, one very simple way to do it would be.

img { display: block; margin: 0 auto; }

Because img elements are naturally inline, you could also give its parent element, text-align: center.

It is now possible i may go find a dark corner and spend a while crying!!

Ijj - my sanity thanks you!

The DIV is centred because you gave it a width and it is a ‘block’ so could make use of the margin auto. Obviously like was mentioned the image won’t be centred as-well with it being inline neither would any contained text. Also don’t trust programs such a Dreamweaver to show you the actual final results as they are just editors and not actually the browser itself.