Position Property Behavior
In CSS, when you set an element to position: absolute, what is it positioned relative to?
- Its closest ancestor element with any position other than static
- Its closest ancestor with position: relative only
- The first parent element in the HTML
- The viewport always
- The last child element
Centering an Element
Suppose you want to center an absolutely positioned element both vertically and horizontally within its parent, without using flex or grid. Which solution will correctly center it?
- Set top: 50%; left: 50%; and use transform: translate(-50%, -50%)
- Just set margin: auto
- Only set left: 50% and top: 50%
- Use position: static and text-align: center
- Apply display: block and margin: 0 auto
REM vs EM Units
What is the main difference between rem and em units in CSS?
- rem is relative to root font size, em is relative to parent font size
- em is relative to root font size, rem is relative to parent
- Both are absolute font sizes
- rem and em are exactly the same
- rem is only for colors, em is for size
Responsive Typography
Why might you prefer using rem units over px for font sizing in responsive layouts?
- rem units scale consistently by changing the root size
- px units automatically adjust for device size
- rem uses less memory than em
- rem is only for background colors
- px units respond faster in browsers
Box Model Elements
Which of the following are parts of the CSS box model?
- Content, padding, border, margin
- Only padding and content
- Content and margin only
- Padding and margin only
- Border and content only
box-sizing Property Impact
What does setting box-sizing: border-box do to an element?
- Includes padding and border in the element's total width and height
- Excludes border from the element's size
- Only sets border width automatically
- Makes the element display as an inline-block
- Hides padding and margin
Inline vs Inline-block
What is the key difference between display: inline and display: inline-block for an element?
- inline-block allows setting width and height; inline does not
- inline elements are always floated
- inline elements cannot have background colors
- inline-block removes all margins
- inline-block elements become block-level only
Default Position Value
What is the default value of the CSS position property for most elements?
- static
- absolute
- fixed
- relative
- block
Practical Use of EM
If a parent element has a font-size of 20px and its child uses font-size: 2em, what will the child’s font size be?
- 40px
- 10px
- 20em
- 2px
- 24px
Absolute Position with No Positioned Ancestor
If an absolutely positioned element has no ancestor with a non-static position, what is it positioned relative to?
- The HTML body element
- The nearest span element
- The browser window always
- The next sibling element
- The last child ancestor