Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Foundations Selectors Basic Attribute Selectors

Ryan Decker
Ryan Decker
3,451 Points

Stage 2 Selectors: Challenge task 3 of 3. Need help with this code. Not sure what I am doing wrong.

Help!

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Attribute Selectors</title>
    <link rel="stylesheet" href="page.css">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sed egestas tortor, vel tincidunt dolor.
    </p>
    <a href="#" title="More!">Duis ut velit faucibus</a>
    <p>
        Proin orci arcu, dapibus vel faucibus in, commodo in nunc. <a href="#">Vestibulum erat dolor laoreet</a> nec cursus non, luctus ut elit. In sed congue lectus, id ullamcorper massa. <a href="#" title="More!">View more &raquo;</a>
    </p>
    <form>
        <input type="text" name="email">
        <input class="submit" type="submit" name="submit">
    </form>
</body>
</html>
style.css
/* Complete the challenge by writing CSS below */

a,title{color: darkred;}

input,text {background-color: lightyellow;}

3 Answers

Edward Bryan Kene Morales
Edward Bryan Kene Morales
7,374 Points

Hey Ryan,

I am not sure what you are trying to accomplish but I see some syntax error in your css code:

a,title {color: darkred;}

input,text {background-color: lightyellow;}

Are you trying to create a CSS declaration that will target target anchor links with the title attributes and input tags with type set as text? If so, the code should look like this:

a[title] {color: darkred;}

input[type="text"] {background-color: lightyellow;}

What's wrong your with your code ,if that is the case, is that, instead of targeting the HTML tags with specific attributes, you are targeting title and text HTML tags which are not valid HTML tags.

Attributes should be placed inside brackets following the HTML tag without any space in between them, hence the code:

a[title] {color: darkred;}

input[type="text"] {background-color: lightyellow;}

This way you are targeting anchor links that has a title attribute attached to it and input elements that has the type equals to text.

I hope this helps! Let me know if you need further assistance. Cheers!

Ryan Decker
Ryan Decker
3,451 Points
  1. Create an attribute selector that will target <a> elements with a title attribute. Add a color property with the value darkred.

My code : a , title {color: darkred;} / This is correct i.e it lets me move to next questions.

  1. Add a new attribute selector that will target the input element with the type attribute value text. Set the background color to lightyellow.

My code: input [type="text"] {background-color: lightyellow;} / Tells me this is wrong. input , text {background-color: lightyellow;} / This is correct i.e lets me move on to next questions.

  1. Finally, add a new attribute selector that will target the submit button. Set the text color to white and the background color to steelblue.

My code: input [type="submit"] {color: white; background-color: steelblue;} / Tells me this is wrong. input , submit {color: white; background-color: steelblue;} / Tells me this is wrong.

Edward Bryan Kene Morales
Edward Bryan Kene Morales
7,374 Points

Okay, just get rid of the space in between the input and the first bracket and you should be good to go.

 input[type="submit"] {color: white; background-color: steelblue;}

I am not sure why how this code is marked correct:

a , title {color: darkred;}

It seems to me that this code targets anchor links and the title tag. Take note that the title tag should only appear in the head and not in the body of the HTML document and those in the head of the document can't be styled nor targeted in the CSS.