Results 1 to 6 of 6

Thread: Question about backgrounds

  1. #1
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question about backgrounds

    New here...go easy.

    I am trying to find a solution to a problem I often run into. I am trying to figure out how to set a background for a page and then place a centered column on the page that runs the full length of the page no matter how much content I have in the middle column. I seem to run into this problem a lot and always have to find a work around. I want to solve this issue once and for all. Can you help?

    Here's is a conceptual example of it not working:

    CSS file:
    Code:
    body {
      margin:0;
      padding:0;
      background:#003399;
    }
    
    * {margin:0px; padding:0px;}
    
    #content {
    	background:#FF0000;
    	width:800px;
    	margin:0 auto;
    }
    HTML code:
    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=ISO-8859-1" />
    <link href="css_example.css" rel="stylesheet" type="text/css" />
    <title>Untitled Document</title>
    </head>
    <body>
    	<div id="content">
    		<p>Here is a little content</p>
    	</div>
    </body>
    </html>
    I have also hosted the example so it is easy for you to take a look at it.
    http://www.soundparanoia.com/slop/css_example.html

    In the example, I want the red to extend the length of the page no matter what the content is. I know the example is trivial, but I think it's probably the easiest one to use for exemplifying this issue.

    Thanks for the help!

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Set the height of the content to 100%
    - Mike

  3. #3
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mburt
    Set the height of the content to 100%
    I always thought that's the way to do it, but it doesn't do a darn thing. It makes complete sense, but does not seem to make any change.

  4. #4
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    This will work the way you want:

    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=ISO-8859-1" />
    <style>
    	html
    	{
    		height: 100%;
    	}
    
    	body
    	{
    		height: 100%;
      margin:0;
      padding:0;
      background:#003399;
    	}
    
    * {margin:0px; padding:0px;}
    
    	#content
    	{
    		position: relative;
    		min-height: 100%;
    background:#FF0000;
    	width:800px;
    margin:0 auto;
    	}
    
    	* html #content
    	{
    		height: 100%;
    	}
    </style>
    <title>Untitled Document</title>
    </head>
    <body>
    	<div id="content">
    		<p>Here is a little content</p>
    	</div>
    </body>
    Ryan
    Sevierville, TN

  5. #5
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you! That seemed to be the magic I was looking for!

  6. #6
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    If you want to add a footer and have it stay on the bottom of the screen just add this to the CSS:

    Code:
    #footer
    	{
    		position: absolute;
    		bottom: 0;
    	}
    and place a Footer div within the Wrapper DIV like this (I changed ur Content div to Wrapper and added a Div for Content as it should be):

    Code:
    <div id="wrapper">
    <div id="content"><p>Here is a little content</p></div>
    <div id="footer">Footer Content</div>
    </div>
    Note: this will only work on short content. If the page has to scroll the footer will be at the bottom of the scroll. If you have short content like in my demo it will remain at the bottom of the browser window.
    Ryan
    Sevierville, TN

Bookmarks

Posting Permissions

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