View Full Version : css text-align help

Mr Creeky
Nov 26th, 2008, 09:15 PM
Hello all,

Could someone tell me where I'm going wrong with my css code.

As you will see, there are two styles within a centered <div>.
The first blue sentence should be in the center of the page/<div>, the other set to the left hand side.

However they both appear on the left, what have I missed?

Nov 26th, 2008, 09:36 PM
i dont why, but it works fine if you use divs instead of span. You would also then not need the break between the divs.

Nov 26th, 2008, 11:07 PM
Hello Mr Creeky,
Try this -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {

#wrapper {
margin: 15px auto 0 auto;

#wrapper .center {
font-family:"MS Serif", "New York", serif;


#wrapper .left {
font-family:Arial, Helvetica, sans-serif;
float: left;

<div id="wrapper"><span class="center">Text formated by the style.center</span>
<span class="left">Text formated by the style .left</span></div>

text-align:center; needs to be set in #wrapper because that's what the text is going to be centered in.
Floats are another way of positioning. See a float tutorial here. (http://css.maxdesign.com.au/floatutorial/)

Mr Creeky
Nov 27th, 2008, 01:06 AM
Excavator, Hello and thank you.

I had been playing with float left but had not taken the center off the other style. Worked like a charm!

Learning to drop <table> is a hard lesson :D