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
    May 2012
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    make a section different color

    Hello

    So I have this webpage that has a gray background. it looks like this:



    I want a specific section to have a green background, like this:


    If I was trying to make the whole page green, I would know how to do that, but I dont know how to do just a section of the page?

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,749
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Hello mike316,
    You can add another div element and style it from the CSS to do that.
    Like this -
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	margin: 0;
    	background: #ccc;
    }
    #container {
    	height: 600px;
    	width: 400px;
    	margin: 200px auto;
    	background: #cf0;
    }
    </style>
    </head>
    <body>
        <div id="container">
        <!--end container--></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

  • Users who have thanked Excavator for this post:

    mike316 (04-07-2013)

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Hello Excavator,

    1. Does the #container have to be at a specific part of the style.css file? or can I just put it at the very end?

    2. does it have to be called "container" ? can I call it "dog" ? as long as the html id matches?

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,749
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Quote Originally Posted by mike316 View Post
    Hello Excavator,

    1. Does the #container have to be at a specific part of the style.css file? or can I just put it at the very end?
    For small sites I like the CSS to be ordered the same as the markup. It makes it easier spot what's styling what. Just my preference though, and hardly works when you get into a larger site. The order doesn't much matter though it can affect the specificity.



    2. does it have to be called "container" ? can I call it "dog" ? as long as the html id matches?
    It can be named just about anything you want though there are some rules. See ID and Class here
    Even more helpful maybe, see this tutorial.
    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

  • Users who have thanked Excavator for this post:

    mike316 (04-07-2013)


  •  

    Posting Permissions

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