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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Centering one style within an outer style

    I'm trying to center a <div> with a CSS style within another style; but I want to center it within the outer style.

    Here is the relevant code:

    Code:
    	<div id="content">		
    		<div id="form">
    		 	<div id="control">
    		 	  <select name="position" onChange="customPos();">
    		 	   <?=$list1?>
    		 	  <option value="custom">custom</option>
    		 	  </select>
    		 	</div>
    		</div>	
    	</div>
    I want to center the "control" div within the "content" div; because it's inside the "form" div it's obviously being centered in there & not content.

    Thanks a lot!

  • #2
    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 cyphix,
    in your CSS add
    Code:
    #control {
    width: 200px; /or whatever width you need*/
    margin: 0 auto;
    }
    Should work...
    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

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks but unfortunately it didn't work

  • #4
    Regular Coder Donkey's Avatar
    Join Date
    Sep 2003
    Location
    Blackfield UK
    Posts
    312
    Thanks
    1
    Thanked 36 Times in 36 Posts
    I don't think what you are trying to do can work.

    You can centre "control" within "form" or "form" within "content" but you can't centre "control" within "content" because "form" is in the way.
    " 90% of everything is crud" - Theodore Sturgeon
    Filthy Beast - a 60's Rock Band

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    I think if #form is wide enough that #control should be able to be centered in it... hard to say without seeing the rest of the code though.
    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

  • #6
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Yup... centers fine:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <meta name="" content="authored by http://www.nopeople.com/Design" />
    <style type="text/css">
    html, body {
    	background: #CCCCCC;
    }
    * {
    	margin: 0;
    	padding: 0;
    }
    #content {
    	width: 600px;
    	margin: 100px auto;
    	overflow: auto;
    	background: #FFCC00;
    }
    #form {
    	width: 400px;
    	float: right;
    	background: #CC0000;
    }
    #control {
    	width: 200px;
    	margin: 0 auto;
    	background: #00FF00;
    }
    </style>
    </head>
    <body>
        <div id="content">		
    		<div id="form">
    		 	<div id="control">
    		 	  <select name="position" onChange="customPos();">
    		 	   <?=$list1?>
    		 	  <option value="custom">custom</option>
    		 	  </select>
    		 	</div>
    		</div>	
        <!--end content--></div>
    </body>
    </html>
    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


  •  

    Posting Permissions

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