Câu hỏi phỏng vấn CSS
Câu hỏi

Describe floats and how they work

Câu trả lời

The CSS float property is used to position and format content on web pages, primarily by allowing elements to "float" to the left or right side of their container, causing surrounding inline content, such as text, to wrap around it. This property is derived from print design techniques where text wraps around images, creating a layout that integrates text with visual elements seamlessly.

Understanding the Float Property

When an element is set to float, it is taken out of the normal flow of the document but remains a part of the document flow. This is different from absolute positioning, where the element is completely removed from the document flow, and other elements behave as if the absolutely positioned element does not exist.

How Floats Affect Layout

  1. Positioning: By default, when you apply float: left; or float: right; to an element, it shifts to the specified side of its containing element. If there are multiple floated elements, they will line up side by side until there is no more space, and then wrap to the next line[3][4].

  2. Block Formatting Context: Floating an element creates a block formatting context. This means that the floated element will become a block-level element if it wasn't one already. This is crucial for understanding how elements will behave when floated[3].

  3. Impact on Following Elements: Elements that follow a floated element will flow around it unless they are explicitly cleared. The clear property can be used on subsequent elements to prevent them from wrapping around the floated element. For example, clear: both; will prevent an element from floating next to left or right floated el...

junior

junior

Gợi ý câu hỏi phỏng vấn

junior

What existing CSS frameworks have you used locally, or in production? How would you change/improve
them?

middle

How would you approach fixing browser-specific styling issues?

senior

Describe z-index and how a stacking context is formed

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào