Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2008
    Location
    Hatfield, England
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile css text-align help

    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?

  • #2
    New Coder
    Join Date
    Aug 2008
    Posts
    90
    Thanks
    5
    Thanked 3 Times in 3 Posts
    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.

  • #3
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello Mr Creeky,
    Try this -
    Code:
    <!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.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #4
    New Coder
    Join Date
    Nov 2008
    Location
    Hatfield, England
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •