StudyFox
कीमतेंब्लॉगएक्सटेंशनमुफ़्त टूल
  • कीमतें
  • ब्लॉग
  • एक्सटेंशन
  • मुफ़्त टूल
  • शुरू करेंसाइन इन
StudyFox

अपने नोट्स, PDF और स्लाइड्स को फ़्लैशकार्ड, क्विज़, नोट्स और माइंड मैप में बदलें।

StudyFox खोलें

स्टडी टूल्स

  • होमवर्क हेल्पर
  • नोट मेकर
  • फ़्लैशकार्ड मेकर
  • क्विज़ मेकर
  • माइंड मैप मेकर

प्रोडक्ट

  • कीमतें
  • Chrome एक्सटेंशन
  • मुफ़्त एक्सटेंशन
  • स्टडी सेट देखें
  • ब्लॉग

सहायता

  • सहायता केंद्र
  • संपर्क करें
  • गोपनीयता नीति
  • सेवा की शर्तें

तुलना करें

  • Chegg का विकल्प
  • Course Hero का विकल्प
  • Coursology का विकल्प
  • Photomath का विकल्प
  • Gauthmath का विकल्प
  • PhotoSolve का विकल्प
  • CollegeTools का विकल्प
  • Transcript का विकल्प
  • SmartSolve का विकल्प
  • Homeworkify का विकल्प
  • AnswersAi का विकल्प
  • StudyX का विकल्प
  • Quizlet का विकल्प
  • Anki का विकल्प
  • Knowt का विकल्प
  • Brainscape का विकल्प
  • सभी तुलनाएँ

© 2026 StudyFox AI. सर्वाधिकार सुरक्षित।

  • X
  • Discord
  • Instagram
ExploreEngineering & TechWeb DevelopmentHTML & CSS Advanced Quiz: Cascade Layers, Stacking Contexts & Layout Edge Cases

Quiz · Hard

HTML & CSS Advanced Quiz: Cascade Layers, Stacking Contexts & Layout Edge Cases

Harder questions on specificity math, @layer, stacking contexts, flex-shrink math, margin collapse, sticky and fixed pitfalls, and script loading.

by Kill h.20 questionsCreated Nov 20, 2026, 08:27 PM
Web Development· HTML & CSSTags#css#specificity#stacking-context#layout

20 questions

  1. 1

    What is the specificity of ul li:not(.done) a:hover as (ids, classes/pseudo-classes, elements)?

    • A

      (0, 1, 3)

    • B

      (1, 1, 3)

    • C

      (0, 3, 3)

    • (0, 2, 3)

    Elements: ul, li, a = 3. Classes/pseudo-classes: .done (inside :not(), which counts its argument) and :hover = 2. No ids. :not() itself adds nothing; only its argument counts.

  2. 2

    @layer base, components; is declared. components has a { color: red; } and base has #nav a { color: blue; }. What color is the link inside #nav?

    • A

      Blue

    • Red

    • C

      The browser default

    • D

      It depends on source order inside each layer

    Layer order is decided before specificity: later layers win regardless of specificity. components is later, so its low-specificity rule beats the id-based rule in base.

  3. 3

    A rule in a stylesheet with no @layer and a rule inside any layer conflict (both normal declarations, the layered rule has higher specificity). Which wins?

    • A

      The layered rule because of higher specificity

    • The unlayered rule

    • C

      The one that appears last in the file

    • D

      Neither; the browser throws an error

    Unlayered styles are treated as the last (highest priority) layer for normal declarations, so they beat layered ones regardless of specificity. That is why layers are good for taming third-party CSS.

  4. 4

    A modal with z-index: 9999 still appears behind a header with z-index: 10 that is outside the modal's ancestor. The ancestor has transform: translateZ(0) and no z-index. Why?

    • The transformed ancestor creates a stacking context, so the modal's z-index only competes inside it

    • B

      The header is position: fixed so it always wins

    • C

      z-index is capped at 1000 in browsers

    • D

      Transforms always render above positioned elements

    transform makes a new stacking context. The modal's 9999 is relative to that context, which as a whole sits at the ancestor's level (auto/0) and is painted below the header's z-index 10. The fix is to move the modal out (for example to the end of <body>) or remove the transform.

  5. 5

    A flex container is 400px wide. Two items have flex-basis: 300px; item A has flex-shrink: 1 and item B has flex-shrink: 3. What are their widths?

    • A

      A: 100px, B: 300px

    • A: 250px, B: 150px

    • C

      A: 200px, B: 200px

    • D

      A: 300px, B: 100px

    The deficit is 600 - 400 = 200px, shared in proportion to shrink factor times basis: 1 x 300 : 3 x 300 = 1 : 3. A loses 50px, B loses 150px, giving 250px and 150px. Equal shares would need equal shrink factors.

  6. 6

    What is the main difference between flex: 1 and flex: auto?

    • A

      flex: 1 makes the item fixed width

    • flex: 1 is 1 1 0% (ignores content size, tends to equal widths); flex: auto is 1 1 auto (starts from content size)

    • C

      There is no difference

    • D

      flex: auto does not allow shrinking

    With a basis of 0%, all free space is shared by the grow factors, so items become equal (unless min-content forces more). With auto, each item starts from its content width and only the leftover is shared, so items with more content stay wider.

  7. 7

    A child has margin-top: 40px inside a parent with no padding, border or overflow. What do you see?

    • The margin collapses through the parent, so the whole parent is pushed down 40px and no gap appears inside it

    • B

      A 40px gap inside the parent above the child

    • C

      The margin is ignored

    • D

      The parent becomes 40px taller at the bottom

    Parent-child top margins collapse when nothing separates them. Fixes: add padding or border to the parent, use display: flow-root or overflow: auto on the parent, or make the parent a flex or grid container.

  8. 8

    position: sticky; top: 0 on a table header does nothing. Which cause is common?

    • A

      Sticky only works with left

    • An ancestor has overflow: hidden (or auto/scroll), making it the scroll container

    • C

      Sticky needs z-index: -1

    • D

      Sticky works only on <div> elements

    Sticky is relative to the nearest scrolling ancestor. If an intermediate ancestor has overflow other than visible, the element sticks to that box (which does not scroll) instead of the viewport. Also, the sticky element must have room inside its parent.

  9. 9

    Why can height: 100vh hide content behind the toolbar on mobile browsers, and what is a modern fix?

    • A

      100vh is exactly 100px on phones; use rem

    • B

      100vh includes only the scrollbar; use min-height: 0

    • 100vh is the largest viewport (toolbars retracted); use 100dvh (dynamic viewport height)

    • D

      vh does not work on mobile; use %

    On mobile, the visible viewport changes as the address bar shows and hides. vh is based on the largest size, so a full-height layout can be cut off. dvh tracks the current visible size (svh is the smallest, lvh the largest).

  10. 10

    font-size: clamp(1rem, 4vw, 2rem) with a 300px wide viewport and 16px root font size gives what?

    • A

      32px

    • B

      12px

    • 16px

    • D

      4px

    4vw of 300px is 12px, which is below the minimum of 1rem (16px), so clamp returns the minimum: 16px. At 1000px, 4vw = 40px would exceed the maximum and give 32px.

  11. 11

    Which repeat() keyword keeps empty tracks, so items do not stretch when there are few of them?

    • A

      auto-fit

    • auto-fill

    • C

      auto-grow

    • D

      minmax

    auto-fill creates as many tracks as fit, even if they are empty. auto-fit collapses empty tracks to 0 so items stretch to fill the row. auto-grow is not a CSS keyword and minmax is a function for sizes.

  12. 12

    A grid column defined as 1fr is blown out wider than the container by a long unbreakable string. What fixes it?

    • A

      display: inline-grid

    • B

      grid-template-columns: 1fr !important

    • grid-template-columns: minmax(0, 1fr)

    • D

      flex-wrap: wrap on the grid

    1fr is minmax(auto, 1fr), and auto as a minimum means the track will not shrink below its min-content. minmax(0, 1fr) allows the track to shrink so the text can overflow or wrap with overflow-wrap.

  13. 13

    A block image shows a few pixels of extra space under it inside its container. Why?

    • Images are inline by default and sit on the text baseline, leaving room for descenders; use display: block or vertical-align: middle

    • B

      The container's line-height is 0

    • C

      Browsers add a default 4px margin to all images

    • D

      The image has a hidden border

    Inline replaced elements align to the baseline, so a line box makes room below it for descenders. Setting the image to display: block removes the line box effect.

  14. 14

    A position: fixed element inside a parent with transform: scale(1) scrolls with the parent instead of staying on screen. Why?

    • A

      Fixed elements ignore the viewport on mobile

    • A transformed ancestor becomes the containing block for fixed descendants

    • C

      scale(1) disables position

    • D

      fixed is not supported inside transforms

    Transforms (also filter, perspective, will-change: transform) create a containing block for fixed and absolute descendants, so fixed is calculated against the transformed ancestor, not the viewport.

  15. 15

    A user style sheet and an author stylesheet both declare color with !important. Which wins?

    • A

      The author stylesheet

    • B

      The one with higher specificity

    • C

      The one that loads last

    • The user stylesheet

    For !important declarations the origin order is reversed: user agent important beats user important, which beats author important, so users can override page styles that they need for accessibility (normal declarations: author beats user).

  16. 16

    You write <button onclick="cancel()">Cancel</button> inside a form and the page reloads when it is clicked. Why?

    • A

      Every button reloads the page

    • The button's default type is submit, so it submits the form; use type="button"

    • C

      onclick is not allowed on buttons

    • D

      The form needs method="get"

    A <button> in a form submits it unless type="button" is set (or the handler calls event.preventDefault()).

  17. 17

    a.js has async, while b.js and c.js both have defer (in that document order). Which execution order is guaranteed?

    • A

      c.js can run before b.js

    • b.js runs before c.js; a.js can run at any time

    • C

      All three run in parallel at the same time

    • D

      a.js, then b.js, then c.js

    Deferred scripts run after parsing, in document order. An async script runs as soon as it is downloaded, which may be before parsing finishes or after the deferred ones, so its position is not guaranteed.

  18. 18

    What does sizes="(min-width: 800px) 50vw, 100vw" on an <img srcset=...> tell the browser?

    • A

      Which image to hide on large screens

    • B

      How to crop the image

    • C

      That the image is exactly 800px wide

    • The width the image will occupy in the layout, so it can choose the best srcset file before CSS is applied

    The browser picks a file while parsing HTML, before layout, so it needs a hint about the rendered width. Here: half the viewport at 800px and up, the full viewport otherwise. The browser then selects the smallest candidate that satisfies the pixel density.

  19. 19

    Which selector styles a form group when any input inside it has keyboard focus?

    • A

      .field:has(:hover)

    • B

      .field:focus

    • C

      .field > input:focus-parent

    • .field:focus-within

    :focus-within matches an element if it or any descendant has focus. .field:focus only matches when the group itself is focused (rare). :focus-parent does not exist, and :has(:hover) reacts to hover, not focus (although :has(:focus) would work too).

  20. 20

    Why do display: inline-block items often show a small gap between them, even with margin: 0?

    • A

      The elements are floating

    • B

      inline-block adds default padding

    • C

      Browsers add 4px margin to inline-blocks

    • The whitespace between the elements in the HTML is rendered as a space character

    Inline-level boxes are laid out like text, so a newline or space between tags renders as a space. Use flexbox with gap, remove the whitespace, or set font-size: 0 on the parent (rarely recommended).