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

How difficult to find the right selector...

Hi everybody! I just completed the "Build a Website" course, and trying to fix some CSS on a website project.

How tough it can be to find the right selectors!!! ;-)

For example on this page https://ichblogge.com/seminar-blog-erstellen-neu/ (its work in progress) I try to expand the max-width og the top paragraph to 1000px. See also here: https://cl.ly/2F0q3E0p1n0I

Can anyone explain me which selector to use?

Best, Julius

3 Answers

The first paragraph "Was nützen dir ewig lange Online-Kurse..."?

In this case, it's the parent element of the paragraph, <section class="postcontents wrapper"> that is limiting the width of everything inside it. The rule you want to change is this one:

.wrapper {
    max-width: 700px !important;
}

If I change the rule for '.wrapper' then the code applies to the whole page wrapper.

I want it to apply only to the part I highlighted here https://cl.ly/2F0q3E0p1n0I

If you can change the HTML markup, you should probably just create a new class called something like 'header' and put the styles in that, so they don't affect the other elements on the page.

If you can't change the HTML markup, you could do something like this:

.dark:first-of-type .wrapper {
    max-width: 1000px;
}

There is a div with a .dark class that has a child div with the class .wrapper that you want to target. But you only want the first one, not the other ones on the page, so that's where :first-of-type comes in. We can't use :first-child because it's not the first child of it's parent, just the first div child.

You also need to get rid of the !important flag in the other regular .wrapper rule. Otherwise that will override everything. Best practice is to avoid using !important unless you have no other option.