Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
βΆ Do the exercisesExercise 1 β What's Missing From This Layout?
A developer is trying to create a navigation menu where all buttons appear side by side, but the buttons are stacking vertically instead.
What's the most likely missing CSS property to make the buttons display horizontally?
display: inline; or display: inline-block;display: block;position: absolute;float: left;Hint : Think about which display value allows elements to appear side by side in the natural document flow.
Exercise 2 β Complete the Card Layout
Complete the CSS to create a card with: - 20px spacing between the content and the border - 15px spacing between this card and other elements - Card should be centered horizontally on the page
Hint : Consider which property controls the space inside an element vs. outside it, and how to center an element horizontally using margins.
Exercise 3 β Match CSS Properties to Their Purpose
Match each CSS property with its correct description or purpose:
marginpaddingdisplay: blockdisplay: inlineExercise 4 β Interpreting Margin Shorthand
What does the following CSS rule do?
margin: 10px 20px 30px 40px;Hint : Remember the order for margin and padding shorthand properties: top, right, bottom, left (clockwise from the top).
Exercise 5 β Which Property Can't Be Applied?
A developer is styling a <span> element with display: inline;. Which of the following properties will NOT work as expected?
height: 100px;color: blue;padding-left: 10px;font-weight: bold;Hint : Consider which CSS properties have no effect on inline elements, particularly regarding box dimensions.
Exercise 6 β Fix the Layout Issue
You have two elements side by side. You want to set specific heights and widths on both of them, but they need to remain side by side. Complete the CSS to fix this layout issue:
Hint : Think about which display value allows elements to be placed side by side while still respecting their width and height properties.
Exercise 7 β Default Display Values
Match each HTML element with its default display value:
<div><span><h1><a>display: block;display: inline;display: block;display: inline;Exercise 8 β Horizontal Centering Issue
A developer is trying to center a div horizontally with this CSS, but it's not working. What's the issue?
.container {
margin: auto;
padding: 20px;
background-color: lightblue;
}Hint : Consider what's required for the margin: auto technique to work for horizontal centering.
Exercise 9 β Shorthand for Specific Spacing
Complete the CSS shorthand to create: - 20px top padding - 10px right and left padding - 30px bottom padding
Hint : Remember the order for the 3-value shorthand in CSS: top, right/left, bottom.
Exercise 10 β Hidden Element Behavior
What's the difference between these two CSS declarations?
/* Option 1 */
.hidden-1 {
display: none;
}
/* Option 2 */
.hidden-2 {
visibility: hidden;
}Hint : Think about how each property affects both the visibility of the element and its impact on the page layout.
Exercise 11 β CSS Shorthand Patterns
Match each CSS shorthand with what it sets:
margin: 10px;margin: 10px 20px;margin: 10px 20px 30px;margin: 0 auto;Exercise 12 β Margin Collapsing
What will be the vertical space between these two paragraphs?
p {
margin-top: 20px;
margin-bottom: 30px;
}Hint : Think about how vertical margins interact between adjacent elements (margin collapsing).
Exercise 13 β Hide an Element
Complete the CSS to hide an element completely and remove it from the layout flow:
Hint : Consider which display value completely removes an element from the page layout.
Exercise 14 β Understanding inline-block
What's the main advantage of using display: inline-block over display: inline?
Hint : Think about the limitations of inline elements and how inline-block addresses them.
Exercise 15 β CSS Results Matching
Match each CSS rule with its visual effect:
padding: 20px;margin: 0 auto;display: none;display: inline-block;Exercise 16 β Negative Margins
What effect will this CSS have?
.box {
margin-left: -20px;
}Hint : Think about how negative margins affect an element's position relative to its normal position.
Exercise 17 β Spacing a Card Layout
Complete the CSS to add proper spacing to this card. Add 20px of space inside the card (between content and border) and 15px of space outside the card (between this card and other elements):
Hint : Think about which property creates space inside an element versus outside it.
Exercise 18 β Button Layout Problem
A developer has created these buttons for a CodΓ©mon game interface, but they aren't displaying correctly. What's the issue?
.game-button {
background-color: #4CAF50;
color: white;
padding: 15px 30px;
margin: 10px;
border-radius: 5px;
width: 200px;
height: 50px;
display: inline;
}Hint : Consider which CSS properties are ignored on inline elements.
Exercise 19 β Setting Individual Side Spacing
Complete the CSS to create: - Padding only on the left side (20px) - Margin only on the bottom side (30px)
Hint : Think about which specific properties target individual sides of an element.
Exercise 20 β Visual Effects of CSS Properties
Match each CSS property with its visual effect:
margin-right: 20px;padding-bottom: 15px;display: block;visibility: hidden;Exercise 21 β Creating Space Between Elements
What's the best way to create equal spacing between multiple divs stacked vertically?
Hint : Think about which property creates space between elements rather than inside them.
Exercise 22 β Override Padding Values
Complete the CSS to override the padding for just the top side, we want 20px on it.
Hint : Think about which property can override just one side of the padding without affecting the others.
Exercise 23 β Preventing Margin Collapse
Which technique will NOT prevent margin collapse between two adjacent elements?
Hint : Think about which techniques create separation between elements and prevent their margins from collapsing together.
Exercise 24 β Display Property Behaviors
Match each display value with its behavior regarding width and height:
display: block;display: inline;display: inline-block;display: none;Exercise 25 β Parent-Child Display Issues
What happens when you put a block element inside an inline element?
Hint : Consider the HTML nesting rules and how block and inline elements should be properly nested.
Exercise 26 β Calculate the Total Width
What is the total width of this element including margins?
.box {
width: 300px;
padding-left: 15px;
padding-right: 25px;
border: 5px solid black;
margin-left: 20px;
margin-right: 30px;
}Hint : Remember to add up all components: content width + padding (both sides) + borders (both sides) + margins (both sides).
Exercise 27 β Centering with margin: auto
A developer tried to center an inline element with margin: 0 auto; but it's not working. Why?
Hint : Consider the requirements for the margin: auto centering technique to work.
Exercise 28 β Common HTML Elements and Their Display
Match each HTML element with its default display type:
<p>, <h1>, <section>, <article><span>, <a>, <em>, <strong><img>, <button>, <input><br>, <hr>display: block;display: inline;display: inline-block;display: block; (self-closing)Exercise 29 β Understanding Spacing Properties
Which property should you use to create space BETWEEN multiple elements?
Hint : Think about which property creates space outside elements, between them and other content.
Exercise 30 β Adding Space Between List Items
Complete the CSS to add 10 pixels of space between each list item:
Hint : Think about which property would create space between elements that are stacked vertically.
Exercise 31 β Understanding display: none
What is true about an element with display: none?
Hint : Consider how display: none affects both visual appearance and the document flow.
Exercise 32 β Margin vs Padding Use Cases
Match each scenario with the more appropriate spacing property:
Exercise 33 β Which Property to Use?
You want to increase the space between a button's text and its border. Which property should you use?
Hint : Think about which property creates space inside an element, between its content and border.
Exercise 34 β Advanced Margin Shorthand
Complete the CSS to create: - 20px top margin - 15px right margin - 30px bottom margin - 5px left margin
Hint : Remember the order for the 4-value shorthand in CSS: top, right, bottom, left (clockwise from top).
Exercise 35 β Identifying Display Issues
A designer created a navigation menu with list items but they're displaying vertically instead of horizontally. What's the most likely issue?
Hint : Consider the default display value of list items and what display value would make them appear side by side.