Questions
6 of 29
1What is the box model in HTML?
2Can you explain the components of the Box Model?
3What’s the difference between margin, border, padding, and content?
4How does padding affect the size of an element?
5How does margin differ from padding?
6What happens when you set negative margins?
7Does padding accept negative values? Why or why not?
8How can you visualize the box model in browser dev tools?
9What is the default box-sizing value for HTML elements?
10What does box-sizing: border-box do?
11Compare box-sizing: content-box and border-box.
12How can you make two boxes align perfectly side by side with consistent spacing?
13How do margin collapsing rules work in CSS?
14Give an example of when margin collapsing might cause layout issues.
15How can you prevent margin collapsing between parent and child elements?
16What is the difference between inline, inline-block, and block elements in terms of the box model?
17Do replaced elements (like <img>, <input>) follow the same box model rules?
18How do width and height interact with padding and border in the box model?
19Why might a layout break when switching from content-box to border-box?
20How would you fix an element that overflows its container due to box model miscalculations?
21How do you use the calc() function to compensate for padding or border widths?
22How does the box model interact with flexbox and grid layouts?
23Does the box model behave differently for absolutely positioned elements?
24How can you ensure consistent box sizing across all elements on a webpage?
25What’s the role of outline in the box model, and how is it different from border?
26How can you use the box model to achieve responsive layouts?
27How do you debug box model-related issues in a complex layout?
28Explain how min-width, max-width, and overflow affect the box model.
29How do borders affect element dimensions?
06 / 29

What happens when you set negative margins?

Understanding Negative Margins in CSS

In CSS, setting a negative margin moves an element closer to its neighboring elements or even causes it to overlap them. Unlike padding, which only adds space inside an element, negative margins can reduce or reverse the space outside an element, affecting layout positioning.

Example of Negative Margin
Effects of Negative Margins
  1. 1

    Can pull an element closer to or over neighboring elements.

  2. 2

    May cause overlapping content if values are too large.

  3. 3

    Can collapse with adjacent vertical margins, following CSS margin collapse rules.

  4. 4

    Does not affect the element's content or padding, only its position.

Difficulty: 5/10
Topics: box model, layout, overflow

Scenario Questions

0-2 years experience
  1. 1

    You have a button inside a card, and you want it to sit 10px higher than its normal position without changing the card's padding. How would you achieve that with CSS, and what would happen visually if you used a negative margin?

  2. 2

    If you apply margin-top: -20px to an element that follows a header, describe how the header and the element will be positioned relative to each other.

2-5 years experience
  1. 1

    A page you inherited uses margin-left: -15px on a list item to align it with the container's edge, but on some browsers the layout breaks and content overflows. How would you debug the issue and decide whether to keep the negative margin?

  2. 2

    During a redesign you replace a floated layout with Flexbox, but a component still uses a negative bottom margin to pull the next section up. Explain the trade‑offs of keeping that negative margin versus refactoring the component.

5-8 years experience
  1. 1

    Your design system includes a card component that uses negative margins to create a visual overlap effect on hover. At scale, this causes unexpected scrollbars and hit‑testing problems on mobile. How would you redesign the component to avoid negative margins while preserving the visual intent?

  2. 2

    In a large e‑commerce site, several pages rely on negative margins to achieve a 'tight' grid. When you introduce a new CSS-in-JS solution, you notice that server‑side rendering sometimes miscalculates the layout. Explain how negative margins interact with layout calculations and what strategy you would use to ensure consistent rendering.

8+ years experience
  1. 1

    Your organization is migrating a legacy UI built with tables and negative margins to a modern component library using CSS Grid. What architectural guidelines would you set to prevent future reliance on negative margins, and how would you handle existing components that depend on them without breaking downstream teams?

  2. 2

    A cross‑team initiative aims to standardize spacing tokens across all products. Some teams argue that negative margins are essential for certain visual tricks. How would you evaluate the long‑term maintenance cost versus the design benefit, and what policy would you propose?

Follow-up Questions

  • What are the risks of using negative margins for responsive designs?
  • Can you think of an alternative CSS technique that achieves the same visual effect without negative margins?
  • How does margin collapsing behave when one of the margins is negative?