Positioning: Relative/Absolute Badge
Solution idea
Absolute positioning within a relatively positioned parent keeps the badge anchored to the card corner while removing it from normal flow.
Public interview reports
These public, self-reported interview accounts informed this practice version. The exercise is modelled on reported rounds, not copied from them, and the reports are not verified official questions or endorsements.
- Taro: Tesla front end developer interview, 2022
A 2022 account lists positioning a set of given boxes with CSS among its tasks, without naming the stage. This item practises relative and absolute positioning on one component.
- Viblo: Shopee frontend engineer interview, Ho Chi Minh City, February 2025
The frontend round opened with CSS questions on the position values fixed, absolute and sticky. This positioning drill is a practice version of that topic, not the reported wording.
Reported in a public Tesla interview account. Tesla frontend interview questions
Reported in a public Shopee interview account. Shopee frontend interview questions
Solution
Overview
Absolute positioning within a relatively positioned parent keeps the badge anchored to the card corner while removing it from normal flow.
Approach — Relative Parent + Absolute Child
Use top/right offsets and a small translate if you want the badge to overlap the corner. Ensure the badge is readable (contrast, padding) and doesn’t shift layout because it’s absolutely positioned.
<div class='product'>
<img src='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="320" height="180">
<rect width="100%" height="100%" fill="%23ddd"/>
<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" fill="%23666" font-family="Arial" font-size="20">
Product
</text>
</svg>
' alt='Product'>
<span class='badge'>
NEW
</span>
</div>.product {
position: relative;
display: inline-block;
}
.badge {
position: absolute;
top: 8px;
right: 8px;
padding: 4px 8px;
border-radius: 6px;
background: #e63946;
color: #fff;
font-weight: 600;
letter-spacing: 0.5px;
}
img {
display: block;
max-width: 100%;
border-radius: 8px;
}Notes & Pitfalls
If .productisn’t positioned relatively,.badgewill be placed relative to the entire page.Avoid using large pixel offsets that break responsive behavior.
Relative positioning on the parent establishes a local coordinate system. Absolute positioning on the child allows fixed placement within that parent.
Resources
Similar questions
Guides
Preparing for interviews? Use Frontend Coding Challenges first, then move into a concrete Study Plan before targeted Company Prep.
Built in public
The code behind FrontendAtlas lives on GitHub. A star helps other frontend engineers find it.