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

Issues with borders when applying Media Queries

Hello!

So I have been practising what I learnt by creating a small project from scratch, however I am now facing an issue:

I have started with a mobile version, so on my first approach I used (I have created 4 bottoms):

.main-nav li:not(:last-child) {
border-bottom: 1px solid #B22222;
}

Now, I have created a media query for wider screens, and my nav is in one line instead of several lines. This means, I want the bottoms to have a full border, not just the bottom one. I did applied a border like this:

  border: 1px solid grey;

and the border is not applied to any of the bottoms except the last one. Not sure how to fix it, if someone can help?

Thank you1

Steven Parker
Steven Parker
231,007 Points

If you make a snapshot of your workspace and post the link to it here, we can see the rest of the code and replicate the issue .

3 Answers

Steven Parker
Steven Parker
231,007 Points

In "stylesheet.css" on line 146:

    border-bottom: grey;

This contradicts any previous border settings and makes the border thickness 0px, so it is not seen. You can add a thickness and style to make it visible, or remove the line completely to keep the reddish border already established.

I also noticed peculiar behavior caused by the ":not(:last-child)" pseudo-classes. The intention for this was confusing until I checked the HTML and found a tag overlap issue. I'm guessing these pseudo classes were a result of an accident that appeared to (mostly) remedy the effects of the overlap. Here's one example of the several cases of overlap:

      <li><a href="#">News</li></a>    <!-- bad, tags overlap -->
      <li><a href="#">News</a></li>    <!-- correct -->

Fix the HTML and then you can remove all those pseudo-classes.

Hi Steven Parker, thank you! Please, see below:
https://w.trhou.se/mi1sbedak2

Hi Steven,

Thank you for looking into this, it worked! Also, didn't realize <a> should be closed before the list element tag, I have been doing that wrong from ages now! Thanks for clarifying :))))