CSS Problem with :first-child need help

Discussion in 'CSS' started by cri8bat, Aug 16, 2013.

  1. #1
    hi

    I am designing a website and I have a horizontal menu like this
    #navigation ul li a{
    }

    I want to made the first anchor link to be different color, the only way I can see is by using :first-child property. however everything I use this all the anchor links change color :S

    #navigation ul li a:first-child{
    }

    need help
     
    cri8bat, Aug 16, 2013 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    You're not interested in the first child of the list-item, you want the first-child of the list.
    
    #navigation ul li:first-child a {
      ...
      }
    Code (markup):
    cheers,

    gary
     
    kk5st, Aug 16, 2013 IP
  3. cri8bat

    cri8bat Well-Known Member

    Messages:
    1,459
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    160
    #3
    tks gary for reply.
    I tried what you suggested still not working.... :S
     
    cri8bat, Aug 16, 2013 IP
  4. bluebenz

    bluebenz Well-Known Member

    Messages:
    876
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    138
    #4
    Why dont use another class just for the first item of li ?

    This is not a good idea, but the first solution I was thinking, and the last action I will do if no other solution.. :)
     
    bluebenz, Aug 16, 2013 IP
  5. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #5
    Show me. Show me the html markup for the list and the exact css ruleset.
     
    kk5st, Aug 16, 2013 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #6
    What Gary is trying to politely imply is that CSS without the markup it's applied to is gibberish; it's why snippets are pointless trash when trying to diagnose a problem.
     
    deathshadow, Aug 17, 2013 IP
  7. cri8bat

    cri8bat Well-Known Member

    Messages:
    1,459
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    160
    #7
    My mistake, its not the first list but the second list and the code is as follows:
    I want the "order now" link to be different color

    <div id="navigation">

    <ul>
    <li><div class="fb-like"</div></li>
    <li><a href="h">order now</a></li>
    <li><a href="#">linke3</a></li>
    <li><a href="#">linke4</a></li>
    <li><a href="#">linke5</a></li>
    <li><a href="#">linke6</a></li>
    <li><a href="#">linke7/a></li>
    </ul>


    CSS as folows:


    #navigation {
    margin-top: 10px;
    text-align:right;
    }
    #navigation ul {
    padding:0px;
    margin:0px;
    }
    #navigation ul li {
    display:inline;
    }
    #navigation ul li a, #navigation ul li a:link, #navigation ul li a:active, #navigation ul li a:visited {
    color:#FFF;
    text-decoration:none;
    padding-right: 15px;
    padding-left: 15px;
    text-transform: capitalize;
    background-color: #ce2b4e;
    padding-top: 5px;
    padding-bottom: 5px;
    border: thin dashed #ce2b4e;
    }
    #navigation ul li a:hover {
    color:#ce2b4e;
    text-decoration:underline;
    background-color: #EFEFEF;
    }
     
    cri8bat, Aug 17, 2013 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    Then you want li:nth-child(2), not first-child. As before you can only child off the UL, since A would be the children of the LI, not the UL (so all of them are first-child) -- your first LI is the fb like link (which doesn't seem to be part of the on-site navigation so why the *** is it even in the list?) so that's not what you want to target.

    Honestly, I'd either get that div out of the list since it's not semantically part of it, or man up and just use one class to target it.

    That said --- and what I'm about to say I'm seeing WAY to ****ing often -- what the blue blazes do you have that extra DIV around the UL for?!? Serves no legitimate purpose as you aren't doing a blasted thing that couldn't be done directly to the UL!

    of course that's without mentioning the bizarro uncombined padding declarations, psuedo-states for nothing, incomplete 'hover' stack, etc, etc, etc...
     
    deathshadow, Aug 17, 2013 IP
  9. cri8bat

    cri8bat Well-Known Member

    Messages:
    1,459
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    160
    #9
    I have coded this way and now I dont want to back to the code and delete/alter all the files.

    can you just tell me the code for the li:nth-child(2) please
     
    cri8bat, Aug 17, 2013 IP
  10. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #10
    kk5st, Aug 17, 2013 IP