StackScholar
  • System Design Interview Preparation

    Beginner to advanced, with interactive simulators and full design case studies.

  • Python Full-Stack Interview Preparation

    Master backend + frontend questions with real-world cases.

  • AI/ML Engineer Interview Preparation

    ML, deep learning, LLMs, RAG, MLOps and system design - with mock interviews.

Rapid Review CSnewDSA VisualizerReviewBlog
Search⌘K
System Design Interview PreparationPython Full-Stack Interview PreparationAI/ML Engineer Interview Preparation
Rapid Review CSnewDSA VisualizerReviewBlog
CurriculumAll questionsFlashcardsGlossaryVisualizersDSA Visualizer

Navigate by Range

  • Q&A Python-1-5
  • Q&A Python-6-10
  • Q&A Python-11-15
  • Q&A Python-16-20
  • Q&A Python-21-25
  • Q&A Python-26-30
  • Q&A Python-31-35
  • Q&A Python-36-40
  • Q&A Python-41-45
  • Q&A Python-46-50
  • Q&A Python-51-55
  • Q&A Python-56-60
  • Q&A Python-61-65
  • Q&A Python-66-70
  • Q&A Python-71-75
  • Q&A Python-76-80
  • Q&A Python-81-85
  • Q&A Python-86-90
  • Q&A DB-MySQL-1-5
  • Q&A DB-MySQL-6-10
  • Q&A DB-MySQL-11-15
  • Q&A DB-MySQL-16-20
  • Q&A DB-MySQL-21-25
  • Q&A DB-MySQL-26-30
  • Q&A DB-MySQL-31-35
  • Q&A DB-MySQL-36-40
  • Q&A DB-MySQL-41-45
  • Q&A DB-MySQL-46-50
  • Q&A Django-1-5
  • Q&A Django-6-10
  • Q&A Django-11-15
  • Q&A Django-16-20
  • Q&A Django-21-25
  • Q&A Django-26-30
  • Q&A Django-31-35
  • Q&A Django-36-40
  • Q&A Django-41-45
  • Q&A Django-46-50
  • Q&A FastAPI-01-05
  • Q&A FastAPI-06-10
  • Q&A FastAPI-11-15
  • Q&A FastAPI-16-20
  • Q&A FastAPI-21-25
  • Q&A FastAPI-26-30
  • Q&A FastAPI-36-40
  • Q&A FastAPI-41-45
  • Q&A FastAPI-31-35
  • Q&A FastAPI-46-50
  • Q&A FastAPI-51-55
  • Q&A FastAPI-56-60
  • Q&A FastAPI-61-65
  • Q&A HTML-01-05
  • Q&A HTML-06-10
  • Q&A HTML-11-15
  • Q&A HTML-16-20
  • Q&A CSS-01-05
  • Q&A CSS-06-10
  • Q&A CSS-11-15
  • Q&A CSS-16-20
  • Q&A JavaScript-1-5
  • Q&A JavaScript-6-10
  • Q&A JavaScript-11-15
  • Q&A JavaScript-16-20
  • Q&A JavaScript-21-25
  • Q&A JavaScript-26-30
  • Q&A JavaScript-31-35
  • Q&A JavaScript-36-40
  • Q&A JavaScript-41-45
  • Q&A JavaScript-46-50
  • Q&A React-1-5
  • Q&A React-6-10
  • Q&A React-11-15
  • Q&A React-16-20
  • Q&A React-21-25
Loading…

Navigate by Range

  • Q&A Python-1-5
  • Q&A Python-6-10
  • Q&A Python-11-15
  • Q&A Python-16-20
  • Q&A Python-21-25
  • Q&A Python-26-30
  • Q&A Python-31-35
  • Q&A Python-36-40
  • Q&A Python-41-45
  • Q&A Python-46-50
  • Q&A Python-51-55
  • Q&A Python-56-60
  • Q&A Python-61-65
  • Q&A Python-66-70
  • Q&A Python-71-75
  • Q&A Python-76-80
  • Q&A Python-81-85
  • Q&A Python-86-90
  • Q&A DB-MySQL-1-5
  • Q&A DB-MySQL-6-10
  • Q&A DB-MySQL-11-15
  • Q&A DB-MySQL-16-20
  • Q&A DB-MySQL-21-25
  • Q&A DB-MySQL-26-30
  • Q&A DB-MySQL-31-35
  • Q&A DB-MySQL-36-40
  • Q&A DB-MySQL-41-45
  • Q&A DB-MySQL-46-50
  • Q&A Django-1-5
  • Q&A Django-6-10
  • Q&A Django-11-15
  • Q&A Django-16-20
  • Q&A Django-21-25
  • Q&A Django-26-30
  • Q&A Django-31-35
  • Q&A Django-36-40
  • Q&A Django-41-45
  • Q&A Django-46-50
  • Q&A FastAPI-01-05
  • Q&A FastAPI-06-10
  • Q&A FastAPI-11-15
  • Q&A FastAPI-16-20
  • Q&A FastAPI-21-25
  • Q&A FastAPI-26-30
  • Q&A FastAPI-36-40
  • Q&A FastAPI-41-45
  • Q&A FastAPI-31-35
  • Q&A FastAPI-46-50
  • Q&A FastAPI-51-55
  • Q&A FastAPI-56-60
  • Q&A FastAPI-61-65
  • Q&A HTML-01-05
  • Q&A HTML-06-10
  • Q&A HTML-11-15
  • Q&A HTML-16-20
  • Q&A CSS-01-05
  • Q&A CSS-06-10
  • Q&A CSS-11-15
  • Q&A CSS-16-20
  • Q&A JavaScript-1-5
  • Q&A JavaScript-6-10
  • Q&A JavaScript-11-15
  • Q&A JavaScript-16-20
  • Q&A JavaScript-21-25
  • Q&A JavaScript-26-30
  • Q&A JavaScript-31-35
  • Q&A JavaScript-36-40
  • Q&A JavaScript-41-45
  • Q&A JavaScript-46-50
  • Q&A React-1-5
  • Q&A React-6-10
  • Q&A React-11-15
  • Q&A React-16-20
  • Q&A React-21-25
StackScholar

StackScholar is your go-to destination for exploring technology from every angle - from bit to supercomputer.

Quick Links

  • Home
  • Search
  • Daily Review
  • Blog
  • About
  • Contact
  • Privacy Policy

DSA Visualizer

  • DSA Visualizer
  • Sorting Algorithms
  • Binary Search Tree
  • Dijkstra's Algorithm
  • A* Pathfinding
  • Dynamic Programming

Rapid Review CS

  • Rapid Review CS
  • Operating Systems
  • DBMS
  • Computer Networks
  • Data Structures & Algorithms
  • Computer Architecture

Interview Preparation

  • System Design Interview
  • System Design Toolkit
  • System Design Patterns
  • Python Full-Stack Interview
  • AI/ML Engineer Interview
  • ML Mock Interview
  • AI/ML Glossary

Get new lessons and visualizers in your inbox

Occasional email when something substantial ships. No spam, unsubscribe anytime.

© 2026 StackScholar. All rights reserved.

CSS Interview Questions 1-5 (Positioning, Specificity, Basics)

Welcome to the CSS portion of your interview preparation! While Python powers the logic of your application, CSS (Cascading Style Sheets) is what makes it usable and human. Many backend developers underestimate CSS, which makes it a fantastic area for you to stand out.

In this lesson, we are going to tackle the topics that often trip up developers: the invisible logic of positioning and the mathematical rules of specificity. These aren't just about making things look pretty; they are about understanding how the browser rendering engine makes decisions.

1. What is the difference between relative, absolute, and fixed positioning?

The position property changes how an element interacts with the document flow. Understanding the relationship between these three values is critical for layout design.

  • Relative:
    The element remains in the normal document flow. When you move it (using top/left/right/bottom), it moves relative to its original position. Crucially, the space it originally occupied is preserved (it leaves a "ghost" behind). Other elements do not shift to fill the gap.
  • Absolute:
    The element is removed from the normal document flow. The space it occupied collapses. It positions itself relative to its closest positioned ancestor(a parent with position set to anything other than static). If no parent is positioned, it defaults to the body/html.
  • Fixed:
    Like absolute, it is removed from the flow. However, it positions itself relative to the browser viewport (window). It stays in the exact same spot on the screen even when the user scrolls the page (like a sticky navigation bar or a "Back to Top" button).

Here is a practical comparison to help you visualize the difference.

/* 1. Relative: Moves down/right, but keeps its seat reserved */
.box-relative {
  position: relative;
  top: 20px;
  left: 20px;
}

/* 2. Absolute: Flies out of the flow, usually inside a 'relative' parent */
.parent {
  position: relative; /* The anchor */
}
.child-absolute {
  position: absolute;
  top: 0;
  right: 0; /* Sticks to the top-right of .parent */
}

/* 3. Fixed: Stuck to the screen glass */
.navbar-fixed {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 1000; /* Ensures it floats above everything */
}

2. Explain CSS specificity rules.

Specificity is the set of rules the browser uses to decide which style applies when multiple rules target the same element. It is essentially a score calculation. If two selectors conflict, the one with the higher score wins.

The Hierarchy (from highest score to lowest):

Selector TypeScore ValueExample
Inline Style1000style="color: red"
ID Selector100#navbar
Class / Pseudo-class10.btn, :hover
Element / Tag1div, h1

Calculation Example:

  • div p = 1 + 1 = 2
  • .container p = 10 + 1 = 11 (Winner vs div p)
  • #main .content p = 100 + 10 + 1 = 111 (Winner)

The Nuclear Option: The !important declaration overrides all specificity calculations. However, it is considered bad practice because it makes debugging extremely difficult. Use it only as a last resort.

3. Difference between inline, internal, and external CSS.

This question asks about the three ways to insert a style sheet into an HTML document. Interviewers want to know if you understand scalability and maintainability.

1. Inline CSS:
Written directly inside the HTML element using the style attribute.
- Pros: Quick testing, highest specificity (1000).
- Cons: Terrible maintainability, no code reuse, creates messy HTML.

2. Internal CSS:
Written inside a <style> tag within the HTML <head>.
- Pros: Good for single-page templates (like emails) where external files can't be loaded.
- Cons: Cannot share styles across multiple pages.

3. External CSS:
Written in a separate .css file and linked via the <link> tag.
- Pros: The industry standard. Keeps HTML clean, allows caching (faster load times), and enables one file to style the entire website.
- Cons: Requires an extra HTTP request (usually negligible).

<p style="color: red;">Hello</p>

<head>
  <style>
    p { color: blue; }
  </style>
</head>

<head>
  <link rel="stylesheet" href="styles.css">
</head>

4. What are CSS pseudo-classes?

A pseudo-class is a keyword added to a selector that specifies a special state of the selected element. It is not about "what" the element is, but "how" the user is interacting with it or "where" it is in the list.

They are always prefixed with a single colon (:).

  • User Action: :hover, :active (clicked), :focus (selected via keyboard).
  • Tree Structure: :first-child, :last-child, :nth-child(even).
  • Form State: :checked, :disabled, :invalid.
/* Change color when mouse is over the button */
button:hover {
  background-color: blue;
}

/* Style every even row in a table */
tr:nth-child(even) {
  background-color: #f2f2f2;
}

/* Style input when user clicks into it */
input:focus {
  border: 2px solid green;
}

5. What are CSS pseudo-elements?

While pseudo-classes style a state of an existing element, pseudo-elements allow you to style a specific part of an element, or generate new content that doesn't exist in the HTML.

They are technically prefixed with double colons (::) in CSS3 to distinguish them from pseudo-classes, though single colons often still work for backward compatibility.

  • ::before and ::after: Insert cosmetic content before/after the element. Requires the content property.
  • ::first-line: Styles only the first line of a paragraph.
  • ::first-letter: Styles the first letter (drop cap effect).
  • ::placeholder: Styles the placeholder text in an input field.
/* Add a graphical arrow after every link */
a::after {
  content: " →";
  color: grey;
}

/* Make the first letter of a blog post giant */
p.intro::first-letter {
  font-size: 200%;
  color: purple;
}

Sample Output behavior:
If you have a link <a>Read More</a>, the CSS above will make it look like "Read More →" on the screen, even though the arrow is not in your HTML text.

Check your understanding

3 questions · no sign-up, nothing stored

0/3 answered
Question 1

1.Order these by specificity, lowest first: class, inline style, element, id.

Question 2

2.What is position: absolute positioned relative to?

Question 3

3.What distinguishes a pseudo-class from a pseudo-element?

0 / 74 ranges

Progress is stored in this browser only - no sign-up, nothing sent anywhere.

PreviousNext