...

View Full Version : css text-align help



Mr Creeky
11-26-2008, 09:15 PM
Hello all,

Could someone tell me where I'm going wrong with my css code.
http://caitsolutions.com/beta/wrapper.htm

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?

BigRusky
11-26-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.

Excavator
11-26-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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CSS</title>
<style type="text/css">
<!--
body {
margin:0px;
}

#wrapper {
width:960px;
margin: 15px auto 0 auto;
text-align:center;
}

#wrapper .center {
font-family:"MS Serif", "New York", serif;
font-size:14px;
color:#06F;

}

#wrapper .left {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
color:#333;
float: left;
}
--></style>
</head>

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

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
11-27-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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum