Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

CSS Pseudo classes

  • 06-02-2013 11:48am
    #1
    Registered Users, Registered Users 2 Posts: 3,132 ✭✭✭


    Can someone help me with this?

    Here's my HTML
    
    <!DOCTYPE html>
    <html>
    	<head>
    		<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
    		<title>Result</title>
    	</head>
    	<body>
            <div>
    		<p><a href="http://www.mylink.com">link one</a>
    		<p><a href="http://www.mylink.com">link two</a>
                    <p><a href="http://www.mylink.com">link three</a>
    	</div>
    </body>
    </html>
    

    Here's my CSS
    a:first-child{ 
    Font-color:#CDBE70
    }
    a:nth-child(3){
    font-color:#FFc125
    }
    
    

    I want to set the first link to the font color #CDBE70 and set the third link to the font color #FFC125


Comments

  • Registered Users, Registered Users 2 Posts: 1,757 ✭✭✭Deliverance XXV


    silvine wrote: »
    Can someone help me with this?

    Here's my HTML
    
    <!DOCTYPE html>
    <html>
    	<head>
    		<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
    		<title>Result</title>
    	</head>
    	<body>
            <div>
    		<p><a href="http://www.mylink.com">link one</a>
    		<p><a href="http://www.mylink.com">link two</a>
                    <p><a href="http://www.mylink.com">link three</a>
    	</div>
    </body>
    </html>
    

    Here's my CSS
    a:first-child{ 
    Font-color:#CDBE70
    }
    a:nth-child(3){
    font-color:#FFc125
    }
    
    

    I want to set the first link to the font color #CDBE70 and set the third link to the font color #FFC125

    Try using CSS classes instead.
    
    <!DOCTYPE html>
    <html>
    	<head>
    		<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
    		<title>Result</title>
    	</head>
    	<body>
            <div>
    		<p><a [COLOR="Red"][B]class="one"[/B][/COLOR] href="http://www.mylink.com">link one</a>
    		<p><a [COLOR="Red"][B]class="two"[/B][/COLOR] href="http://www.mylink.com">link two</a>
                    <p><a href="http://www.mylink.com">link three</a>
    	</div>
    </body>
    </html>
    
    a[COLOR="Red"][B].one[/B][/COLOR]{ 
    Font-color:#CDBE70
    }
    a[COLOR="Red"][B].two[/B][/COLOR]{
    font-color:#FFc125
    }
    
    


  • Registered Users, Registered Users 2 Posts: 4,509 ✭✭✭robbiezero


    p:first-child a {
    color: #CDBE70
    }

    p:nth-child(3) a {
    color: #FFc125
    }


  • Registered Users, Registered Users 2 Posts: 1,757 ✭✭✭Deliverance XXV


    Try using CSS classes instead.
    <!DOCTYPE html>
    <html>
    	<head>
    		<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
    		<title>Result</title>
    	</head>
    	<body>
            <div>
    		<p><a [COLOR="Red"][B]class="one"[/B][/COLOR] href="http://www.mylink.com">link one</a>
    		<p><a [COLOR="Red"][B]class="two"[/B][/COLOR] href="http://www.mylink.com">link two</a>
                    <p><a href="http://www.mylink.com">link three</a>
    	</div>
    </body>
    </html>
    
    a[COLOR="Red"][B].one[/B][/COLOR]{ 
    Font-color:#CDBE70
    }
    a[COLOR="Red"][B].two[/B][/COLOR]{
    font-color:#FFc125
    }
    
    

    Whoops! Read the question wrong. Think older IE has some issues with pseudo classes. When outputting from a db with unknown amounts and I want different styling I normally use PHP counters and different CSS classes.


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭oeb


    silvine wrote: »
    Can someone help me with this?

    Here's my HTML
    <!DOCTYPE html>
    <html>
        <head>
            <link type="text/css" rel="stylesheet" href="stylesheet.css"/>
            <title>Result</title>
        </head>
        <body>
            <div>
            <p><a href="http://www.mylink.com">link one</a>
            <p><a href="http://www.mylink.com">link two</a>
                    <p><a href="http://www.mylink.com">link three</a>
        </div>
    </body>
    </html>
    
    Here's my CSS
    a:first-child{ 
    Font-color:#CDBE70
    }
    a:nth-child(3){
    font-color:#FFc125
    }
    
    
    I want to set the first link to the font color #CDBE70 and set the third link to the font color #FFC125

    Hi there, there is a couple of things with the above.

    Firstly, in your html, you are better off closing the paragraphs with a </p> tag

    Next, the css property you are looking for is "color" not "font-color"

    Finally, you are not using selectors right. If we break down the html you have there.

    You have a div that contains 3 child elements (all of which are p elements) each of which contains 1 child. The a element.
    [HTML]
    <div>
    <p> <!-- Child 1 of div -->
    <a> <!-- Child 1 of p -->
    </p>
    <p> <!-- Child 2 of div -->
    <a> <!-- Child 1 of p -->
    </p>
    <p> <!-- Child 3 of div -->
    <a> <!-- Child 1 of p -->
    </p>
    </div>
    [/HTML]

    So as robbiezero indicated, the psudo class needs to be placed on the p element, and not on the a.
    robbiezero wrote: »
    p:first-child a {
    color: #CDBE70
    }

    p:nth-child(3) a {
    color: #FFc125
    }


  • Registered Users, Registered Users 2 Posts: 3,132 ✭✭✭silvine


    Thanks. It got it working but Codeacademy won't pass me. It says "Did you remember to set your first <a> to the color #CDBE70?"

    The colours of the links change okay. Might be a bug.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭oeb


    silvine wrote: »
    Thanks. It got it working but Codeacademy won't pass me. It says "Did you remember to set your first <a> to the color #CDBE70?"

    The colours of the links change okay. Might be a bug.

    Have you tried using first-child on the first selector?


  • Registered Users, Registered Users 2 Posts: 3,132 ✭✭✭silvine


    Like this?
    p:first-child a{
        color: #CDBE70;
    }
    

    Still won't pass me.


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭oeb


    silvine wrote: »
    Still won't pass me.

    What's the actual question?


  • Registered Users, Registered Users 2 Posts: 3,132 ✭✭✭silvine


    The error is:

    Oops, try again.
    Did you remember to set your first <a> to the color #CDBE70?

    The question is
    Feel like you're really starting to understand this CSS stuff? Prove it!

    Add three links to the body of the HTML document. They can go anywhere and the text between the tags can say whatever you like.
    On the CSS tab, set the all a:hovers to have no text-decoration.
    Set the first link to the font color #CDBE70. (Remember: in this case, the first link also happens to be the first child of the body element.)
    Set the third link to the font color #FFC125.

    The link is http://www.codecademy.com/courses/web-beginner-en-WF0CF/3?curriculum_id=50579fb998b470000202dc8b#!/exercises/4


  • Registered Users, Registered Users 2 Posts: 4,509 ✭✭✭robbiezero


    silvine wrote: »

    Remove the paragraph tags and just add the links directly to the body.
    Your css is now:
    a:first-child {
    color: #CDBE70
    }
    
    a:nth-child(3) {
    color: #FFc125
    }
    

    Your html
    <html>
    	<head>
    		<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
    		<title>Result</title>
    	</head>
    	<body>
    	    <a class="one" href="http://www.mylink.com">link one</a>
    	<a class="two" href="http://www.mylink.com">link two</a>
                   <a href="http://www.mylink.com">link three</a>
    		
    	</body>
    </html>
    

    excuse the formatting.


  • Advertisement
  • Moderators, Society & Culture Moderators Posts: 17,643 Mod ✭✭✭✭Graham


    As a quick FYI, in the top right of each CodeCademy tutorial there is a link to 'Q & A section' where others go into problems they had had with that particular step.

    I'd say at least 50% of the problems are because the code you've entered isn't exactly as Codecademy expects (even though it might be correct). The Q & A will often point you in the direction of the expected format.


  • Registered Users, Registered Users 2 Posts: 3,132 ✭✭✭silvine


    Seemed to work but I'm still not sure what I did wrong. I'll press on with the other lessons. Thanks!


  • Registered Users, Registered Users 2 Posts: 4,509 ✭✭✭robbiezero


    silvine wrote: »
    Seemed to work but I'm still not sure what I did wrong. I'll press on with the other lessons. Thanks!

    You added the links to paragraph elements instead of directly to the body.


  • Registered Users, Registered Users 2 Posts: 3,132 ✭✭✭silvine


    The Python lessons make CSS look easy!


Advertisement