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 12 of 12
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    136
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Centering banner and navigation

    I want to center my banner and navigation right smack in the middle of my page. BUT only on my first page. Can someone help me please?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"><html>
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta http-equiv="Content-Style-Type" content="text/css">
    
    <title>Cj Web Consulting - Home</title>
    <link rel="stylesheet" type="text/css" href="css/main.css">
    </head>
    
    <body>
    
    
      <div id="container">
      <div id="banner">
    
     <img src="images/newbanner.jpg" alt="banner" width="275" height="275" >
    </div>
    
    <ul id="list-nav">
     <li><a href="index.html">Home</a></li>
     <li><a href="about.html">About Us</a></li>
     <li><a href="portfolio.html">Portfolio</a></li>
     <li><a href="contact.html">Contact</a></li>
    </ul>
    
    </div>
    
    </body>
    
    </html>

  • #2
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    If you want specific stylings for a template based on the URL, I'd probably use PHP and something along the lines of:

    PHP Code:
    <div <?php echo ($_SERVER['REQUEST_URI'] == "/home.php" ?
              
    'id="homeBanner"' 'class="pagesBanner"'?>>

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    136
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you. But I'm familiar with PHP yet.

  • #4
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    Quote Originally Posted by Charisma View Post
    Thank you. But I'm familiar with PHP yet.
    Is that meant to say 'Thank you. But I'm familiar with PHP' or 'Thank you. But I'm familiar with PHP yet'.

  • #5
    Regular Coder
    Join Date
    Oct 2011
    Posts
    136
    Thanks
    4
    Thanked 0 Times in 0 Posts
    LOL Sorry. It should say, I'm not familiar.

  • #6
    New Coder
    Join Date
    Nov 2010
    Location
    Virginia,USA
    Posts
    36
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Since it is a single instance try this inline style

    <img src="images/newbanner.jpg" align="center" alt="banner" width="275" height="275" >

    **EDIT: DOH! Sorry man I forgot about the menu. I wouldnt try this on your menu lol
    Last edited by badwolf; 05-20-2012 at 04:53 PM.

  • #7
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    Quote Originally Posted by badwolf View Post
    Since it is a single instance try this inline style

    <img src="images/newbanner.jpg" align="center" alt="banner" width="275" height="275" >

    **EDIT: DOH! Sorry man I forgot about the menu. I wouldnt try this on your menu lol
    It's a template, so it will be like that on all pages. The OP specifically stated that they wanted the style for particular page.

  • #8
    Regular Coder
    Join Date
    Oct 2011
    Posts
    136
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I tryed the following.

    <img src="images/newbanner.jpg" align="center" alt="banner" width="275" height="275" >

    But all it did was put a space between my banner and navigation.

  • #9
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    What so are you just trying to center it on all pages now?

    You could use display: block; margin: auto;

  • #10
    Regular Coder
    Join Date
    Oct 2011
    Posts
    136
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I just want to center the banner and navigation on the first page only. Right smack in the middle.

  • #11
    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 Charisma,
    If you want to center banner and navigation on one page and not the rest, just give that page's body an id so you can specifically target that pages banner and nav.

    Something like this for markup - <body id="centered">

    And then this for the CSS -
    Code:
    #centered #banner {styling goes here}
    #centered ul#list-nav {styling goes here}
    The other pages, that don't have body#centered, will inherit from their default or some other parent.
    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

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Did you want to vertically align your image and navigation as well or just horizontally? Can you post your current CSS?
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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