QuestenaUn entraînement qui indique quoi revoir ensuite
Question 12

A <span> keeps its default display: inline and is not a replaced element such as an image. Which one of these declarations does the browser not apply to it?

  1. margin-left: 20px
  2. width: 200pxBonne réponse
  3. padding-left: 20px
  4. background-color: yellow

Explication

width (and height) simply do not apply to non-replaced inline boxes: such a box is as wide as the text it contains, and the declaration has no effect at all. The other three do take effect — a left margin pushes the start of the box along the line, left padding widens it and shifts the text, and the background paints behind the content and padding. Note the related trap that is not being asked here: vertical padding and borders are applied and painted on an inline box, but they do not increase the line box's height, so they overlap neighbouring lines. If you need width on the element, give it display: inline-block or display: block.

Continuer avec ce test

Commencer l’entraînement
Question 12: A <span> keeps its default display: inline and is not a… · CSS Fundamentals Readiness Check · Questena