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 trialMelissa Lang
Courses Plus Student 2,566 PointsHow do I only stylize 2 unordered lists differently on a page than the other unordered lists?
I have 2 unordered lists that are created within a table and every time I stylize them, they change the appearance of the other unordered list which I don't want to be changed.
2 Answers
Kevin Korte
28,149 PointsUsually in your HTML you'll give them a unique class, and that you can apply list styles to any list that has this CSS class. That way the two you want will pick up the styles, but the other lists without that class will now. You can also use some combination of advanced CSS sectors, but that can get complicated fast, so the better solution would be to use a class. As an example
<ul class="styled-list">
<li></li>
<li></li>
</ul>
Jeff Lemay
14,268 PointsSimple, classes and IDs!
In your html, you can add a class or ID to each unordered list. Remember, you can have multiple classes on the same page but only one ID. So if you want to have multiple lists styled similarly (but still different than your basic list), use a class like .my-list-style. If most of your lists look the same but you want one to be completely different, use an ID like #special-contact-list.
<ul>
<li>This one will be</li>
<li>styled with basic</li>
<li>unordered list styling.</li>
</ul>
<ul class="my-list-style">
<li>With a class attached,</li>
<li>I can style this one</li>
<li>differently than others.</li>
</ul>
ul.my-list-style {
list-style-type:none;
color: #0000FF;
padding: 10px 20px;
}