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 CSS Layout CSS Layout Techniques Display

Kathryn Kassapides
Kathryn Kassapides
9,260 Points

Change the display of .main-list to the display value that generates a block element that doesn't take up a full line.

The <ul> with the class main-list is a block-level element by default, so it takes up its container's full width.

style.css
/* Complete the challenge by writing CSS below */

header {
  text-align: center;
}
.logo {
  width: 60px;
  margin: auto;
}

.main-list li{
display: inline-block;

}

.main-list ul{
display: block;

}
index.html
<!DOCTYPE html>
<html>
<head>
    <title>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="An illustration of a building">
            <ul class="main-list">
                <li><a href="#">Donuts</a></li>
                <li><a href="#">Tea</a></li>
                <li><a href="#">Coffee</a></li>
            </ul>
        </header>
    </div>
    </body>
</html>

2 Answers

Hi Kathryn!

You are correct on task 1:

/* Complete the challenge by writing CSS below */

header {
  text-align: center;
}
.logo {
  width: 60px;
  margin: auto;
}

.main-list li {
  display: inline-block; /*** Task 1 - Correct ***/
}

For task 2, just targeting .main-list is sufficient and you still want to use display: inline-block

Like this:

/* Complete the challenge by writing CSS below */

header {
  text-align: center;
}
.logo {
  width: 60px;
  margin: auto;
}

.main-list li {
  display: inline-block; /*** Task 1 - Correct ***/
}

.main-list { /*** Element with the class of "main-list" ***/
  display: inline-block; /*** Task 2 - Correct ***/
}

Although this also passes task 2:

/* Complete the challenge by writing CSS below */

header {
  text-align: center;
}
.logo {
  width: 60px;
  margin: auto;
}

.main-list li {
  display: inline-block; /*** Task 1 - Correct ***/
}

ul.main-list { /*** Unordered list with the class of "main-list" ***/
  display: inline-block; /*** Task 2 - Correct ***/
}

Note that this:

.main-list ul

Is a descendant selector and therefore would target an unordered list element that is a child/descendant of the element with the class of "main-list"

But/Also there is a shorthand way to pass both tasks 1 and 2, like this:

/* Complete the challenge by writing CSS below */

header {
  text-align: center;
}
.logo {
  width: 60px;
  margin: auto;
}

.main-list, /*** Note the comma ***/
.main-list li {
  display: inline-block; /*** Tasks 1 & 2 - Correct ***/
}

Note that (generally speaking, ignoring margins, padding, width, height, etc):

display: block sets the element to take up the full width of its parent container

display: inline-block set the element to only be as wide as its contents

More info:

https://www.samanthaming.com/pictorials/css-inline-vs-inlineblock-vs-block/

https://www.w3schools.com/html/html_blocks.asp

Hopefully, that's enough info that you should be able to pass task 3 on your own.

I hope that helps.

Stay safe and happy coding!

thank you so much! was stuck on this

if I do .main-list { display: inline-block; }

why does it bring the image next to the li? .main-list is the ul and img is outside the class then why is it tagging along?