1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Got this in my css how to center my links..

Discussion in 'CSS' started by hitboy, Feb 20, 2008.

  1. #1
    I am trying to center my navigation links on my website www.hpkmedia.com with no success.. the css text is below yet when I try to edit the different "left" s to "center" it doesn't work I am not sure how to make my navigation center can anyone help me :D


     
    hitboy, Feb 20, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    All I see are floats? You need to put text-align: center; in the #nav. Should cascade down.
     
    shallowink, Feb 20, 2008 IP
  3. kentuckyslone

    kentuckyslone Notable Member

    Messages:
    4,371
    Likes Received:
    367
    Best Answers:
    0
    Trophy Points:
    205
    #3
    You are correct

    float can only be left or right
     
    kentuckyslone, Feb 20, 2008 IP
  4. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #4
    You can center it by having a div around the floats with an absolute width with the style - margin: 0 auto;
     
    live-cms_com, Feb 20, 2008 IP
  5. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ^That would center the menu so long as the menu had a width. But I thought we were trying to center the actual a's?

    ul.nav li a,ul.nav li a:link,ul.nav li a:visited{border-bottom:0;border-left:0;background:#f3f2ed;color:#069;float:left;display:block;text-decoration:none;padding:0 10px;}

    This stuff above needs to go. No need to say display: block if you're floating it (float makes a block), no need to float the a's if the li's are floated, no need to set borders to 0 unless there were borders set on an a somewhere earlier in the code (which, maybe that's true).
     
    Stomme poes, Feb 21, 2008 IP
  6. XTreMe

    XTreMe Banned

    Messages:
    1,226
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    0
    #6
    the flow can only be left or right, instead of using float you can easily you <center> or padding and margin
     
    XTreMe, Feb 21, 2008 IP
  7. hitboy

    hitboy Well-Known Member

    Messages:
    2,939
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    170
    #7
    I tried what i could but couldnt fix it

    Stomme poes do you mean to delete that code?
     
    hitboy, Feb 21, 2008 IP
  8. hitboy

    hitboy Well-Known Member

    Messages:
    2,939
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    170
    #8
    I tired what you said and it didnt seem to work anyone else got some suggestions?
     
    hitboy, Feb 21, 2008 IP
  9. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #9
    Show the code for that section that you have now. It is the top nav on the site?
     
    shallowink, Feb 21, 2008 IP
  10. hitboy

    hitboy Well-Known Member

    Messages:
    2,939
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    170
    #10
    The code in the first post is what it is currently. Yes it is for the top nav on the site
     
    hitboy, Feb 21, 2008 IP
  11. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #11
    Changed this line display:block to display:inline; :
    ul.nav li a,ul.nav li a:link,ul.nav li a:visited {border-bottom:0; border-left:0; background:#f3f2ed; color:#069; display:inline; text-decoration:none; padding:0 10px;}

    Add text-align:center; to the #nav :
    #nav{height:30px;line-height:30px;padding:0;text-align:center;}

    And it works in FF2.
     
    shallowink, Feb 21, 2008 IP
  12. hitboy

    hitboy Well-Known Member

    Messages:
    2,939
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    170
    #12
    I added it but didnt seem to work this is what my code looks like as of right now
     
    hitboy, Feb 21, 2008 IP
  13. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #13
    Take the float:left; out too.

    ul.nav li a,ul.nav li a:link,ul.nav li a:visited{border-bottom:0; border-left:0; background:#f3f2ed; color:#069; display:inline; text-decoration:none; padding:0 10px;}
     
    shallowink, Feb 21, 2008 IP
  14. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #14
    Here's a hacky way to fix it -

    replace -
    #nav{height:30px;line-height:30px;padding:0;text-align:center;}
    with -
    #nav{height:30px;line-height:30px;padding:0;padding-left: 25px;text-align:center;}


    edit: shallowink's way seems to work and is less hacky than mine.
     
    live-cms_com, Feb 21, 2008 IP
  15. hitboy

    hitboy Well-Known Member

    Messages:
    2,939
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    170
    #15
    Yea I suppose I could do it this way too lol didnt think of that yet I dont think its the best solution
     
    hitboy, Feb 21, 2008 IP
  16. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #16
    Now, without the HTML the CSS is pretty much gibberish, BUT, I've got the feeling that you've got WAY too much CSS and HTML for your own good here.

    I'm assuming #nav is a div wrapping the UL - so we can axe that straight off and style the UL directly - making IT the #nav. You're declaring text decoration about five times more than you need to, have a whole bunch of psuedoclass definitions that do NOTHING...

    Assuming #nav was a wrapping div, delete any classes that are not 'uniques', make the UL id="nav", and we can simplify down to this:

    * {
    	margin:0;
    	padding:0;
    }
    
    #nav {
    	list-style:none;
    	height:30px;
    	font:bold 12px/30px arial,helvetica,sans-serif;
    	text-transform:uppercase;
    }
    
    #nav li {
    	display:inline;
    }
    
    #nav a {
    	float:left;
    	text-decoration:none;
    	padding:0 10px;
    	color:#069;
    	background:#f3f2ed;
    }
    
    #nav a:hover,
    #nav a:active,
    #nav .current_page_item a {
    	color:#555;
    	background:#fff;
    }
    
    #nav .home a {
    	border-left:2px solid #fff;
    }
    
    #nav ul {
    	float:left;
    }
    Code (markup):
    Which is functionally identical to your original CSS - NOT that I can tell what that CSS is even trying to accomplish without the HTML that goes with it.

    Fun that it's two-thirds the size yet has full on formatting.

    As to centering, that's the float biting you in the backside. Generally if this is a cascading menu, that means for centering unless you fix the width of the UL and all the LI, you are likely shit out of luck unless you force centering with .js

    Another reason I've given up on cascading menus (well, that and my increasingly arthritic hands can't seem to navigate the damned things anymore)
     
    deathshadow, Feb 23, 2008 IP