Unit 3: Cascading Style Sheets - Practice Quiz
1 What is the primary purpose of CSS in web development?
2 Which HTML element is commonly used to link an external CSS file?
<link>
<style>
<script>
<meta> with several attributes for loading and applying an external stylesheet
3
Which CSS selector targets all elements with the class notice?
.notice
notice
*notice
#notice
4 Which selector generally has the highest specificity?
5 Which property sets the background color of an element?
background-image with a generated image containing only the desired solid color
border-color
color
background-color
6 Which CSS unit is relative to the font size of the root element?
rem
em
px
cm
7 Which CSS property selects the typeface used for text?
font-style
font-family
font-size
font-weight
8 Which declaration centers text horizontally within an element?
text-align: center;
text-style: center;
font-align: center;
align-text: middle;
9 Which part of the CSS box model creates space between an element's content and its border?
10
Which position value keeps an element attached to the same place in the viewport while the page scrolls?
relative
static
absolute
fixed
11 Which declaration turns an element into a flex container?
position: flex;
display: flex;
display: block;
layout: flex;
12 Which property defines the columns of a CSS Grid container?
grid-layout-columns-and-responsive-tracks
grid-column-start
grid-template-columns
grid-auto-flow
13 Which pseudo-class applies styles when the pointer is over an element?
:hover
:focus
:active
:visited
14 Which pseudo-element inserts generated content before an element's existing content?
::after
::first-line
::before
::selection
15
Which selector targets every element that has a required attribute?
[required]
.required
#required
required
16 Which selector targets only disabled form controls?
:checked
:disabled
:read-only applied to every control that cannot currently receive keyboard input
:required
17
Which syntax correctly declares a CSS custom property named main-color?
@main-color: blue;
--main-color: blue;
$main-color: blue;
var-main-color: blue;
18 Which CSS feature applies styles based on conditions such as viewport width?
19 Which CSS rule defines the stages of an animation?
@supports
@media
@keyframes
@font-face with multiple declarations describing the timing and movement of an element
20 What is the purpose of a CSS transition?
21
A stylesheet contains .notice { color: navy; }, followed later by .notice { color: teal; }. No other color rules apply. What color will an element with class="notice" use?
22
Given the rules #app .note p { color: red; }, .note p { color: blue; }, and div p { color: green; }, what color is applied to a matching paragraph inside #app?
23
What is the visual result of background-color: #222; background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url(hero.jpg);?
24
The root font size is 16px, and a container has font-size: 20px. A child inside it has width: 10em and margin-left: 2rem. What are the computed width and left margin?
160px width and 32px margin
200px width and 40px margin
160px width and 40px margin
200px width and 32px margin
25
A parent has font-size: 20px; line-height: 1.5;. Its child sets font-size: 12px but does not set line-height. What line height does the child use?
18px, based on the child's font size
24px, based on the root font size
30px, inherited as a fixed pixel value
12px, equal to the child's font size
26 Which declaration set displays a single-line label with an ellipsis when its text exceeds the element's width?
white-space: wrap; overflow: hidden; text-overflow: fade;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
white-space: normal; overflow: auto; text-overflow: clip;
white-space: pre; overflow: visible; text-overflow: ellipsis;
27
An element uses box-sizing: content-box, width: 200px, padding: 20px, and border: 5px solid. What is its total border-box width?
28
An absolutely positioned element is inside a position: static parent, which is inside a position: relative grandparent. Relative to which box are its top and left offsets calculated?
29
A 600px-wide flex container has three items with flex: 1 1 0. The second item additionally has flex-grow: 2. Ignoring gaps, what width does the second item receive?
300px
400px
200px
150px
30
A grid container is 940px wide and uses grid-template-columns: repeat(3, 1fr) with column-gap: 20px. What is the width of each column?
31
A div contains, in order, an h2, a paragraph labeled A, a span, and a paragraph labeled B. Which element matches p:nth-of-type(2)?
span element
32
Which rule adds a red asterisk immediately after the content of every element with class required?
.required::first-letter { content: "*"; color: red; }
.required::marker { content: "*"; color: red; }
.required::after { content: "*"; color: red; }
.required::before { content: "*"; color: red; }
33
Which selector targets links whose href begins with https:// and ends with .pdf?
a[href$="https://"][href^=".pdf"]
a[href~="https://"][href|=".pdf"]
a[href^="https://"][href$=".pdf"]
a[href*="https://"][href^=".pdf"]
34
For markup where a checkbox is immediately followed by its label, which selector styles the label only while the checkbox is checked?
input[type="checkbox"]:focus > label
input[type="checkbox"]:checked + label
input[type="checkbox"]:checked ~ form
input[type="checkbox"] + label:checked
35
Given :root { --accent: blue; }, .card { --accent: green; }, and .card button { color: var(--accent, red); }, what color does a button inside .card use?
36
A layout uses .grid { grid-template-columns: 1fr; }, @media (min-width: 600px) { .grid { grid-template-columns: repeat(2, 1fr); } }, and @media (min-width: 900px) { .grid { grid-template-columns: repeat(3, 1fr); } }. How many columns appear at a viewport width of 920px?
37
An animation changes opacity from 0 to 1. Which property-value pair keeps the element at the final keyframe value after the animation finishes?
animation-fill-mode: forwards;
animation-play-state: finished;
animation-direction: forwards;
animation-iteration-count: infinite;
38
A box changes from width: 100px to width: 200px on hover. Which addition makes the width animate smoothly both when the pointer enters and when it leaves?
.box:hover { transition: width 0.3s; }
.box { animation: width 0.3s; }
.box { transition: width 0.3s; }
.box:hover { transition-delay: 0.3s; }
39
An element matches .msg { color: blue !important; } and #panel .msg { color: red; }. There are no other relevant rules. Which color is applied?
#panel
40
A grid has four equal columns. An item uses grid-column: 2 / span 2. Which columns does the item occupy?
41
Given the following cascade layers, what is the computed color of the element <div id="app" class="notice">?
@layer base, theme;
@layer base { .notice { color: navy !important; } }
@layer theme { #app.notice { color: crimson !important; } }
.notice { color: green !important; }
green
navy
crimson
42
What is the specificity of the selector :is(#panel, .card) > p:not(:where(.muted))?
(1, 0, 1)
(1, 1, 1)
(0, 2, 1)
(1, 2, 1)
43
An element has three background images and the declaration background-clip: content-box, padding-box;. Which clipping sequence is used for the images from top to bottom, and how is the background color clipped?
44
The root has font-size: 20px. A parent has a content width of 500px, and its child has font-size: 10px and width: calc(50% + 2rem - 3em). What is the child's used content width?
270px
260px
290px
250px
45
What are the computed values of font-kerning and font-feature-settings after these declarations?
.label { font-kerning: none; font-feature-settings: "liga" 0; font: italic 16px/1.5 "Inter"; }
auto and "liga" 0
none and normal
none and "liga" 0
auto and normal
46
Consider .parent { text-decoration: underline; } and .child { text-decoration: none; }, where .child is a normal inline span inside .parent. What happens to the text in .child?
none overrides it
47
A block is inside a containing block whose content width is 400px. The block uses height: 100px; padding-block: 10%; border-block: 5px solid; box-sizing: content-box;. What is its outer border-box height?
150px
190px
130px
210px
48
A non-root ancestor has transform: translateZ(0), and its descendant has position: fixed; top: 0; left: 0;. Assuming no other containing-block-generating ancestor intervenes, how is the descendant positioned?
49
A 300px-wide flex container has two items with flex: 1 1 0. Their unbreakable min-content widths are 250px and 100px, and neither item overrides min-width. What widths result under the default flex-item minimum sizing?
200px and 100px, without overflow
250px and 100px, causing overflow
150px and 150px, without overflow
225px and 75px, causing overflow
50
A 600px-wide grid uses grid-template-columns: 200px minmax(100px, 1fr) 2fr with a 20px column gap. Assuming no content-based expansion, what are the three track widths?
200px, 180px, 180px
200px, 120px, 240px
200px, 140px, 220px
200px, 100px, 260px
51
Six sibling <li> elements occur in order. Elements 1, 3, 4, and 6 have class active. Which elements match li:nth-child(2n of .active)?
52
An <article id="post" class="note"> generates ::before content. Which rule wins if all declarations are author-origin, unlayered, non-important rules?
#post::before { color: red; }
article.note::before { color: blue; }
article:where(.note)::before { color: green; }
#post::before, producing red
article.note::before, producing blue
article:where(.note)::before, producing green
53
Which element matches [lang|="en" i][data-tags~="css"]?
<p lang="english" data-tags="html css">
<p lang="en_US" data-tags="html css">
<p lang="EN-us" data-tags="html css">
<p lang="en" data-tags="html CSS">
54
A disabled <fieldset> contains input A inside its first <legend>, input B in a normal <div>, and input C inside a second <legend>. Input D is outside the fieldset. Which inputs match :disabled if none has its own disabled attribute?
55
Given :root { --a: var(--b); --b: var(--a); } and .box { color: var(--a, red); border-color: var(--missing, var(--a, blue)); }, what colors are used?
56
The browser's initial font size is 16px, but the document sets html { font-size: 10px; }. At what viewport width does @media (min-width: 40em) begin to match, assuming no zoom or user scaling?
400px
500px
640px
800px
57
An animation defines opacity 0 at 0% and opacity 1 at 100%. It has animation-iteration-count: 3, animation-direction: alternate-reverse, and animation-fill-mode: forwards. What opacity is retained after it finishes?
0.5
1
0
58
An element has transition: opacity 4s linear -1s. When its opacity changes from 0 to 1, what is its transition state immediately after the change, and when does it finish?
0 and finishes after 4s
0.25 and finishes after 3s
0.75 and finishes after 1s
0.25 and finishes after 4s
59
A 700px-wide grid has grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)), a 20px gap, and exactly two items occupying separate tracks. What visible track widths result?
330px each
220px each
220px each
340px each
60
Element A has position: relative; z-index: 1, and its child has position: absolute; z-index: 999. A later sibling B has position: relative; z-index: 2. The elements overlap. Which element paints on top?
position values
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →