Which combination achieves a full-width decorative underline on a block-level element using a pseudo-element?

Prepare for the CSS Mastery Test through study materials and mock questions. Enhance your CSS skills and get ready to ace your exam with detailed explanations and hints. Elevate your mastery in CSS design!

Multiple Choice

Which combination achieves a full-width decorative underline on a block-level element using a pseudo-element?

Explanation:
Using a pseudo-element to draw the underline is about adding a separate decorative layer that you control independently of the element’s content. The pseudo-element is created with content: '', then you absolutely position it at the bottom of the block and stretch it across the full width with width: 100% and left: 0; bottom: 0. The parent must have position: relative so the pseudo-element’s placement is tied to that block. A small height (like 2px) gives a clean line, and background: currentColor makes the underline automatically match the text color. This approach keeps the underline purely decorative, sits at the very bottom, and scales with the element’s width, unlike a text-decoration or a border on the element itself, which either isn’t a pseudo-element or can affect layout in other ways.

Using a pseudo-element to draw the underline is about adding a separate decorative layer that you control independently of the element’s content. The pseudo-element is created with content: '', then you absolutely position it at the bottom of the block and stretch it across the full width with width: 100% and left: 0; bottom: 0. The parent must have position: relative so the pseudo-element’s placement is tied to that block. A small height (like 2px) gives a clean line, and background: currentColor makes the underline automatically match the text color. This approach keeps the underline purely decorative, sits at the very bottom, and scales with the element’s width, unlike a text-decoration or a border on the element itself, which either isn’t a pseudo-element or can affect layout in other ways.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy