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 trialKyle Smith
490 PointsWhy do we use #logo etc? So why don't we just use a logo { color: #fff; } etc?
As the title says, why do we use:
<a href="index.html" id="logo">
and style
#logo {
color: #fff;
}
Instead of:
a logo {
color: #fff;
}
Are they both usable, but #logo
is just easier to use in this case?
Sorry if this doesn't make much sense, I just want to know and understand this before moving on.
3 Answers
Thomas Brun
Front End Web Development Techdegree Student 5,896 PointsIn your example, "#logo" is the "id" attribute of the <a> tag in the HTML. You can reference this ID by using #logo through your HTML and CSS. (Just as you would reference a particular class by using ".class")
Using "a logo" instead, or "a #logo" would not work. Another way to reference this particular link without using the id attribute would be to use it with its parent element, for example:
article a {
color: #fff;
}
That would select the <a> tag (s) contained in the <article> parent element. Using the ID just makes things easier, since each id must be unique; you can find more info here.
Hope it helps!
Abhishek Kambli
2,657 Pointsin logo is used for ID, we use id and in future we will also use classes which helps to oragnize your css in better way, eg you have five paragraph in your html document but you want to style a particular paragraph in different way ID is helpful, classes and id's can be used for a lot of things, so maybe you have same navigation design across all your website pages (eg index.html, about.html, contact.html) you can target all of them with class or id
Also logo is not a keyword in css so you cant directly use it in css, you can use specific keywords i.e tags name (eg p, img, ul, li, a, header, nav) to style
Cindy Lea
Courses Plus Student 6,497 Pointsa is a reserved word for a link& logo is just a name to use to refeence something.