Unit 3: Cascading Style Sheets - Practice Quiz

CSE326 — Internet Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary purpose of CSS in web development?

Introduction to CSS Easy
A. To define database tables
B. To store website data
C. To process server requests
D. To style web pages

2 Which HTML element is commonly used to link an external CSS file?

Introduction to CSS Easy
A. <link>
B. <style>
C. <script>
D. <meta> with several attributes for loading and applying an external stylesheet

3 Which CSS selector targets all elements with the class notice?

CSS Selectors and Specificity Easy
A. #notice
B. notice
C. *notice
D. .notice

4 Which selector generally has the highest specificity?

CSS Selectors and Specificity Easy
A. Universal selector
B. Class selector
C. ID selector
D. Element selector

5 Which property sets the background color of an element?

Colors and Backgrounds Easy
A. background-color
B. color
C. border-color
D. background-image with a generated image containing only the desired solid color

6 Which CSS unit is relative to the font size of the root element?

Units and Measurements Easy
A. em
B. cm
C. px
D. rem

7 Which CSS property selects the typeface used for text?

Typography Easy
A. font-style
B. font-family
C. font-size
D. font-weight

8 Which declaration centers text horizontally within an element?

Text Styling Easy
A. text-align: center;
B. align-text: middle;
C. text-style: center;
D. font-align: center;

9 Which part of the CSS box model creates space between an element's content and its border?

Box Model Easy
A. Margin
B. Padding
C. A transparent outer region that separates the element from all neighboring elements
D. Outline

10 Which position value keeps an element attached to the same place in the viewport while the page scrolls?

Positioning Techniques Easy
A. static
B. fixed
C. relative
D. absolute

11 Which declaration turns an element into a flex container?

Flexbox Layout Easy
A. display: flex;
B. display: block;
C. layout: flex;
D. position: flex;

12 Which property defines the columns of a CSS Grid container?

CSS Grid Layout Easy
A. grid-auto-flow
B. grid-layout-columns-and-responsive-tracks
C. grid-template-columns
D. grid-column-start

13 Which pseudo-class applies styles when the pointer is over an element?

Pseudo Classes Easy
A. :active
B. :hover
C. :visited
D. :focus

14 Which pseudo-element inserts generated content before an element's existing content?

Pseudo Elements Easy
A. ::before
B. ::after
C. ::first-line
D. ::selection

15 Which selector targets every element that has a required attribute?

Attribute Selectors Easy
A. required
B. .required
C. #required
D. [required]

16 Which selector targets only disabled form controls?

Form Styling Easy
A. :disabled
B. :checked
C. :required
D. :read-only applied to every control that cannot currently receive keyboard input

17 Which syntax correctly declares a CSS custom property named main-color?

CSS Variables Easy
A. --main-color: blue;
B. var-main-color: blue;
C. $main-color: blue;
D. @main-color: blue;

18 Which CSS feature applies styles based on conditions such as viewport width?

Responsive Web Design Easy
A. Attribute selectors
B. Keyframe rules
C. Media queries
D. Pseudo-elements

19 Which CSS rule defines the stages of an animation?

CSS Animations Easy
A. @supports
B. @font-face with multiple declarations describing the timing and movement of an element
C. @media
D. @keyframes

20 What is the purpose of a CSS transition?

CSS Transitions Easy
A. To smoothly change property values
B. To arrange items in grid columns
C. To create new HTML elements
D. To validate submitted form data

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?

Introduction to CSS Medium
A. Navy, because the first declaration has priority
B. Teal, because the later equal-specificity rule wins
C. The browser's default text color
D. The color inherited from its parent element

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?

CSS Selectors and Specificity Medium
A. Blue, because it uses a class selector
B. Green, because it uses two type selectors
C. Red, because the selector contains an ID
D. The color of the paragraph's parent

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);?

Colors and Backgrounds Medium
A. The gradient is painted over the image
B. The image is painted over the gradient
C. The solid color replaces both background images
D. The image and gradient are placed side by side

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?

Units and Measurements Medium
A. 160px width and 40px margin
B. 200px width and 32px margin
C. 200px width and 40px margin
D. 160px 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?

Typography Medium
A. 24px, based on the root font size
B. 30px, inherited as a fixed pixel value
C. 12px, equal to the child's font size
D. 18px, based on 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?

Text Styling Medium
A. white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
B. white-space: normal; overflow: auto; text-overflow: clip;
C. white-space: pre; overflow: visible; text-overflow: ellipsis;
D. white-space: wrap; overflow: hidden; text-overflow: fade;

27 An element uses box-sizing: content-box, width: 200px, padding: 20px, and border: 5px solid. What is its total border-box width?

Box Model Medium
A.
B.
C.
D.

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?

Positioning Techniques Medium
A. The document's body element only
B. The element's original static position
C. The nearest positioned grandparent
D. The immediate static parent

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?

Flexbox Layout Medium
A. 400px
B. 300px
C. 150px
D. 200px

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?

CSS Grid Layout Medium
A.
B.
C.
D.

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)?

Pseudo Classes Medium
A. Paragraph B
B. Paragraph A
C. No element
D. The span element

32 Which rule adds a red asterisk immediately after the content of every element with class required?

Pseudo Elements Medium
A. .required::first-letter { content: "*"; color: red; }
B. .required::before { content: "*"; color: red; }
C. .required::marker { content: "*"; color: red; }
D. .required::after { content: "*"; color: red; }

33 Which selector targets links whose href begins with https:// and ends with .pdf?

Attribute Selectors Medium
A. a[href^="https://"][href$=".pdf"]
B. a[href*="https://"][href^=".pdf"]
C. a[href$="https://"][href^=".pdf"]
D. 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?

Form Styling Medium
A. input[type="checkbox"]:checked + label
B. input[type="checkbox"]:checked ~ form
C. input[type="checkbox"] + label:checked
D. input[type="checkbox"]:focus > label

35 Given :root { --accent: blue; }, .card { --accent: green; }, and .card button { color: var(--accent, red); }, what color does a button inside .card use?

CSS Variables Medium
A. Red from the fallback value
B. Black from the browser default
C. Green from the card scope
D. Blue from the root scope

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?

Responsive Web Design Medium
A. One column
B. Four columns
C. Three columns
D. Two columns

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?

CSS Animations Medium
A. animation-play-state: finished;
B. animation-fill-mode: forwards;
C. animation-direction: forwards;
D. 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?

CSS Transitions Medium
A. .box { transition: width 0.3s; }
B. .box:hover { transition-delay: 0.3s; }
C. .box:hover { transition: width 0.3s; }
D. .box { animation: width 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?

CSS Selectors and Specificity Medium
A. The inherited color from #panel
B. Red, because the selector contains an ID
C. Blue, because the declaration is important
D. The browser's default text color

40 A grid has four equal columns. An item uses grid-column: 2 / span 2. Which columns does the item occupy?

CSS Grid Layout Medium
A. Columns 1 and 2
B. Columns 3 and 4
C. Columns 2 and 3
D. Columns 2 through 4

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; }

Introduction to CSS Hard
A. The initial color
B. green
C. navy
D. crimson

42 What is the specificity of the selector :is(#panel, .card) > p:not(:where(.muted))?

CSS Selectors and Specificity Hard
A. (0, 2, 1)
B. (1, 0, 1)
C. (1, 1, 1)
D. (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?

Colors and Backgrounds Hard
A. Images: content, padding, border; color: border
B. Images: content, padding, content; color: content
C. Images: content, padding, padding; color: padding
D. Images: content, content, padding; color: padding

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?

Units and Measurements Hard
A. 290px
B. 260px
C. 270px
D. 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"; }

Typography Hard
A. auto and normal
B. auto and "liga" 0
C. none and normal
D. none and "liga" 0

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?

Text Styling Hard
A. It gains a second transparent underline
B. It loses the underline because none overrides it
C. It becomes underlined only when the span inherits color
D. It remains underlined by the parent's decoration

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?

Box Model Hard
A. 130px
B. 190px
C. 210px
D. 150px

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?

Positioning Techniques Hard
A. Relative to the initial static position
B. Relative to its nearest scrolling ancestor
C. Relative to the transformed ancestor's containing block
D. Relative to the viewport in every case

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?

Flexbox Layout Hard
A. 150px and 150px, without overflow
B. 200px and 100px, without overflow
C. 250px and 100px, causing overflow
D. 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?

CSS Grid Layout Hard
A. 200px, 180px, 180px
B. 200px, 140px, 220px
C. 200px, 120px, 240px
D. 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)?

Pseudo Classes Hard
A. Elements 2 and 4
B. Elements 3 and 6
C. Elements 3 and 4
D. Elements 4 and 6

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; }

Pseudo Elements Hard
A. #post::before, producing red
B. article:where(.note)::before, producing green
C. All tie, so the last rule produces green
D. article.note::before, producing blue

53 Which element matches [lang|="en" i][data-tags~="css"]?

Attribute Selectors Hard
A. <p lang="en_US" data-tags="html css">
B. <p lang="english" data-tags="html css">
C. <p lang="en" data-tags="html CSS">
D. <p lang="EN-us" 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?

Form Styling Hard
A. Inputs B and C
B. Inputs B, C, and D
C. Inputs A, B, and C
D. Inputs A and B

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?

CSS Variables Hard
A. Text is black; border is transparent
B. Text is red; border is red
C. Text is red; border is blue
D. Text is invalid; border is blue

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?

Responsive Web Design Hard
A. 400px
B. 800px
C. 500px
D. 640px

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?

CSS Animations Hard
A. 1
B. 0
C. 0.5
D. The underlying opacity

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?

CSS Transitions Hard
A. It starts at 0.25 and finishes after 4s
B. It starts at 0.75 and finishes after 1s
C. It starts at 0 and finishes after 4s
D. It starts at 0.25 and finishes after 3s

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?

CSS Grid Layout Hard
A. Three tracks of 220px each
B. Two tracks of 220px each
C. Two tracks of 340px each
D. Two tracks of 330px 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?

Positioning Techniques Hard
A. A's child paints above B
B. The later DOM descendant paints above B
C. B paints above A's child
D. The result depends only on position values