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 trialStu Cowley
26,287 PointsEep I Should Know This! CSS Display Modes Challenge Part 2
Hi everyone,
Either I'm having a complete lapse in mental concentration but I just can't seem to figure out question 2 of the "CSS Display Modes Challenge".
The question asks "The <ul> with the class main-nav is a block-level element by default, so it takes up the full width of its container. Let's set .main-nav to be as wide as the content inside it. Change the display of .main-nav to the display value that generates a block element that doesn't take up a full line."
I just can't seem to figure it out! Here is are the styles that I am using.
header {
text-align: center
}
.logo {
width: 100px;
margin: auto;
}
/* My answer */
.main-nav ul,
.main-nav li {
display: inline-block;
}
I will keep trying to get the right answer, and if I somehow manage to solve it, I'll post up my answer.
Any hints would be highly appreciated!
Thanking you in advance,
Stu :)
/* Complete the challenge by writing CSS below */
header {
text-align: center;
}
.logo {
width: 110px;
margin: auto;
}
.main-nav ul {
display: inline-block;
}
.main-nav li {
display: inline-block;
}
<!DOCTYPE html>
<html>
<head>
<title>Getting Started with CSS Layout</title>
<link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="page.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<header>
<img class="logo" src="city-logo.svg" alt="logo">
<ul class="main-nav">
<li><a href="#">Ice cream</a></li>
<li><a href="#">Donuts</a></li>
<li><a href="#">Tea</a></li>
<li><a href="#">Coffee</a></li>
</ul>
</header>
</div>
</body>
</html>
13 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Stu,
Did you try going simple and just use the class selector, without any element selectors...
.main-nav {
display: inline-block;
}
:)
Inevitable Walrus
10,032 PointsIt seems a bit odd that this challenge asks you to essentially repeat yourself. For the first part of the challenge I actually set ".main-nav {display:inline-block;}" because I kind of had a feeling that this would be the desired end result. Took me a couple minutes of head-scratching before I realized they actually wanted me to repeat myself.
chris barnhart
6,514 PointsI think this one has tripped a lot of people up! It took me 45 min to get it!
Kent Worthington
2,015 PointsThere shouldn't be any need to repeat it, but nevertheless, I tripped over it as well.
Gavin Mace
30,747 PointsI just did this one with the question:
"The <ul> with the class main-nav is a block-level element by default, so it takes up the full width of its container. Let's set .main-nav to be as wide as the content inside it. Change the display of .main-nav to the display value that generates a block element that doesn't take up a full line."
.... I kinda hit a dead-end when I assumed that the class was:
.main-nav ul { }
rather than just
.main-nav { }
Thorbjørn Bak Jensen
15,043 Points.main-nav li {display: inline-block} .main-nav {display: inline-block}
FINALLY worked for me
David Low
8,214 Pointswhy does this in no way work for me? every time I take the li off the code it goes "oops! looks like task one is no longer passing."
Brigette Eckert
16,957 PointsYou have to be reduntant and put
.main-nav li{
display: inline-block;
}
.main-nav {
display: inline-block;
}
at least I had to to pass this challenge.
Melvin Ho YK
Courses Plus Student 25,247 PointsJust add on .main-nav into existing code like... ''' CSS .main-nav, .main-nav li { display: inline-block; } '''
Melvin Ho YK
Courses Plus Student 25,247 PointsSorry about the syntax. Here you go Just add on .main-nav into existing code like...
.main-nav,
.main-nav li {
display: inline-block;
} ```
Motuma Kaba
11,960 Pointsit seems complicated but its just asking you to add " .main-nav, " to the one you did on the first question. which is ( .main-nav li{ display: inline-block; ).
so the final answer looks like this. /******** .main-nav, .main-nav li{ display: inline-block; } **********/
Faiz hamdan
1,648 PointsHere's the right answer to the question.
''' .main-nav{ margin: auto; display: inline-block; } '''
Peter B. Sims
Courses Plus Student 2,896 PointsThanks for the correct answer, Faiz!
Learning coding
Front End Web Development Techdegree Student 9,937 PointsCan someone tell why .main-nav works? I feel I understand the result somehow, but not really.
Leanne Millar
9,555 PointsMy understanding of it is:
The .main-nav is the class id for the navigation.
The li is the list item which in this instance is the individual navigation links.
So basically in the first instance, you are targeting the list item specifically.
In the second instance, you are selecting the navigation as a whole.
Hope this helps and explains things a little clearer.
Adriano Gomes
5,468 PointsI was able to solve it with the following code:
.main-nav li, .main-nav { display: inline-block; }
Midhun Chandran
9,414 PointsThis worked for me, .main-nav li{ display: inline-block; } .main-nav {display: inline-block}
Nicholas Murdock
2,115 PointsThey should redo this question. The wording is super confusing, I still don't fully think I understand what was trying to be taught.
Stu Cowley
26,287 PointsStu Cowley
26,287 PointsAh yes of course, as soon as I saw this I was like, duh. Thank you so much Jason Anders! I knew it'd be something like that, but I guess the most experienced CSS specialists forget simple concepts like this from time to time...
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsI know exactly what you mean. :)
Chanda Helms
10,790 PointsChanda Helms
10,790 Points.main-nav li {display: inline-block} .main-nav {display: inline-block} worked for me as well!!!!!!