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 trialFilippo D'Arrigo
5,285 PointsChanging the color for a single element
Hi everyone I need a little help here. I want to change the color of the main-logo only, adding some CSS. I thought to add a span tag and a class but I don't how to position them in my HTML . Plus I'd want all the list items to be on the same line.
<header class="main-header">
<ul class="main-nav">
<li class="main-logo"><h1><a href="#">Logo</a></h1></li>
<li><a href="#">HOMES</a></li>
<li><a href="#">FOR SALE</a></li>
<li><a href="#">RENTALS</a></li>
<li><a href="#">CONTACTS</a></li>
<li><a href="#">FOLLOW US</a></li>
</ul>
</header>
5 Answers
Saskia Lund
5,673 PointsHi!
- What exactly do you mean by "I want to change the color of the main-logo only"? Do you mean the color of text inside the list element with assigned main-logo class? If so, then do this in your CSS:
li.main-logo a {
color: red; /* change this to a HEX value, another colorcode or an rgba value of your choice */
}
To solve the issue with having the entire list in the same line, you need to know that wrapping some text into h1 tokens, will always make the text behave like a block element. And therefore occupy the entire page width to the left and right of its content.
If you want it to stay inline and still use h1 in any of your list items, then add this in your CSS:
ul.main-nav li h1 {
display: inline;
}
To make all of your list items to appear horizontally add this to your CSS
ul.main-nav li {
display: inline-block;
}
Hope this helped.
Saskia
Filippo D'Arrigo
5,285 PointsI also wanted to create a pipe separator between all the list items except the main-logo. Do you think I have to use a pseudo class?
Saskia Lund
5,673 PointsYes, you could.
If the pipe seperator should only be visible BETWEEN two list items, however NOT between li.main-logo and the second list item, add the following to your CSS:
.main-nav li:after {
content: "|";
}
.main-nav li.main-logo:after,
.main-nav li.lastli:after {
content: "";
}
If you don't want the pipe to appear after the last list item, then add class="lastli" to it.
Filippo D'Arrigo
5,285 PointsThanks you very much indeed that worked. But now I have got another problem I've been struggling with. I want to add a pipe line between the first five list items (except the main logo)and leave the others which I gave the class "social-icon" without. How would you do that?
<header class="main-header">
<ul class="main-nav">
<li class="main-logo"><h1><a href="#">Logo</a></h1></li> <!da qui in poi ho sostituito-->-->
<li><a href="#">HOMES</a></li>
<li><a href="#">FOR SALE</a></li>
<li><a href="#">RENTALS</a></li>
<li><a href="#">CONTACTS</a></li>
<li><a href="#">FOLLOW US</a></li>
<li><a href="http://facebook.com/"><img src="webicons/facebook.png" alt="Facebook Logo" class="social-icon"></a></li>
<li><a href="http://twitter.com/"><img src="webicons/twitter1.png" alt="Twitter Logo" class="social-icon"></a></li>
<li><a href="http://rss.org"><img src="webicons/rss.png" alt="Rss Logo" class="social-icon"></a></li>
</ul>
</header>
Filippo D'Arrigo
5,285 Pointssorry I messed up with the indentation
Saskia Lund
5,673 PointsSomething like this maybe?
.main-nav li:after {
content: ' | ';
}
.main-nav li.main-logo:after,
.main-nav li.social-icon:after {
content: ' ';
}
I think I already answered this in my last post xD
Filippo D'Arrigo
5,285 PointsFilippo D'Arrigo
5,285 PointsThanks for your answer.I just wanted to change the main-logo li item and I did forget to add li before main-logo, so the first solution worked fine. Thanks again,cheers.