CSS CSS Layout CSS Layout Techniques Display

Clare Yeadon
Clare Yeadon
4,541 Points

Display:

I have no idea what this question is asking nor what I need to put:

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

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

.main-list li{
  display: inline-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>
Zaid Khan
Zaid Khan
12,739 Points

Can you specify the challenge number?

2 Answers

Peter Vann
MOD
Peter Vann
Treehouse Moderator 31,465 Points

Hi Clare! :)

This:

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

is shorthand for

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

You need both to complete the challenge(s)

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

is a descendent selector. It is targeting the list items that are children of (meaning nested within) of the ul with the class of "main-list", which lines the list items up side-by-side (horizontally).

This:

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

targets the whole ul itself and is what shrinks the list to be only as wide as its content (instead of the default behavior, which would be stretch to fit the width of the parent container).

I hope that helps.

Stay safe and happy coding!

Peter Vann
MOD
Peter Vann
Treehouse Moderator 31,465 Points

This challenge is about understanding the difference between block and inline-block for the display property.

display: block takes up the whole line (the full width of its container)

display: inline-block "generates a block element that doesn't take up a full line" (only as wide as its content)

This passes all three:

/* Complete the challenge by writing CSS below */

header {
  text-align: center;
}
.logo {
  display: block;
  width: 60px;
  margin: auto;
}
.main-list,
.main-list li {
  display: inline-block;
}

More info:

https://css-tricks.com/almanac/properties/d/display/

https://www.w3schools.com/cssref/pr_class_display.asp

I hope that helps. Happy coding!

Clare Yeadon
Clare Yeadon
4,541 Points

Hello, thank you for your help. Why do you have to put .main-list twice?