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 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2009
    Location
    Norway, Europe
    Posts
    94
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Vertical-align problem

    I have a little problem with the footer of my page:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/strict.dtd">
    
    <html>
    <head>
    	<title></title>
    	<style type="text/css">
    
    		#footer {
    		background: #006400; 
    		clear: both;
    		width: 100%;
    		height: 5em;
    	}
    
    	#footer p {
    		vertical-align: middle;
    	}
    
    	.spaceout {
    		margin: 2em 2em;
    	}
    
    		</style>
    </head>
    
    <body>
    		<div id="footer">
    			<div class="spaceout">
    				<p>&copy; Me 2009. This page is entirely coded by me using XHTML and CSS.</p>
    			</div> <!-- spaceout -->
    		</div> <!-- footer -->
    </body>
    </html>
    However, the paragraph in the footer doesn't appear in the middle of the it, but in the top, even though I use vertical-align: middle;. How can I align it to the middle, vertically?

  • #2
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Use line-height:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/strict.dtd">
    
    <html>
    <head>
    	<title></title>
    	<style type="text/css">
    
    		#footer {
    		background: #006400; 
    		clear: both;
    		width: 100%;
    		height: 5em;
    	}
    
    	#footer p {
    		height:5em;
    		line-height:5em;
    	}
    
    		</style>
    </head>
    
    <body>
    		<div id="footer">
    			<p>&copy; Me 2009. This page is entirely coded by me using XHTML and CSS.</p>
    		</div> <!-- footer -->
    </body>
    </html>
    I don't know your intentions for the rest of the page but it doesn't seem like you need an extra containing div, as the paragraph tag works just fine as a block-level container for your text.

    This is the best page on vertical centering in CSS that I've seen. Describes the two methods: line-height and negative margins.
    matt | design | blog

  • #3
    New Coder
    Join Date
    Feb 2009
    Location
    Norway, Europe
    Posts
    94
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Thank you!

    - I'm just wondering though: How can I get vertical-align to work?

    Thanks again,
    -DarkLightA
    Always Use a DOCTYPE!
    Always Use * {margin: 0; border: none; padding: 0;} in the top of your CSS stylesheet.
    Always Use only CSS for layout; never (X)HTML.
    Always Have fun while coding!

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,688
    Thanks
    22
    Thanked 1,829 Times in 1,813 Posts
    Hello DarkLightA,
    Your use of the XHTML Strict DocType indicates that your interested in coding your site with valid and current code. vertical-align:middle; is a deprecated HTML tag.
    msuffern has shown you the proper way to do it and the link he gave you explains it very clearly, along with an optional method if line-height doesn't work for you (like if you were to end up with more than one line of text).

    I'm not sure how to get vertical-align:middle; to work. I tried it here locally but even changing the doctype doesn't make it center your text. Maybe for that tag to work it needs to be in a table? Not a clue.
    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

  • #5
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Hi DarkLightA,

    As the link describes, vertical-align doesn't actually do what you might expect it to do from the name; that is, align block-level elements vertically with respect to their container.

    What it does do is described in the
    • vertical-align in table cells
    • vertical-align on inline elements
    subsections of the above link.

    I understand it can be confusing. There is some truth to the statement

    the CSS specification really screwed this one up (in my opinion)—vertical-align is used to specify two completely different behaviors depending on where it is used.
    matt | design | blog


  •  

    Posting Permissions

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