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 style web pages
B. To store website data
C. To process server requests
D. To define database tables

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. Element selector
B. ID selector
C. Universal selector
D. Class selector

5 Which property sets the background color of an element?

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

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

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

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. text-style: center;
C. font-align: center;
D. align-text: middle;

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

Box Model Easy
A. Padding
B. A transparent outer region that separates the element from all neighboring elements
C. Margin
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. relative
B. static
C. absolute
D. fixed

11 Which declaration turns an element into a flex container?

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

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

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

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

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

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

Pseudo Elements Easy
A. ::after
B. ::first-line
C. ::before
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. :checked
B. :disabled
C. :read-only applied to every control that cannot currently receive keyboard input
D. :required

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

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

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

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

19 Which CSS rule defines the stages of an animation?

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

20 What is the purpose of a CSS transition?

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

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. The browser's default text color
B. Navy, because the first declaration has priority
C. The color inherited from its parent element
D. Teal, because the later equal-specificity rule wins

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. The color of the paragraph's parent
B. Red, because the selector contains an ID
C. Green, because it uses two type selectors
D. Blue, because it uses a class selector

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 image and gradient are placed side by side
B. The image is painted over the gradient
C. The solid color replaces both background images
D. The gradient is painted over the image

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

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

Text Styling Medium
A. white-space: wrap; overflow: hidden; text-overflow: fade;
B. white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
C. white-space: normal; overflow: auto; text-overflow: clip;
D. 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?

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 immediate static parent
B. The nearest positioned grandparent
C. The document's body element only
D. The element's original static position

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. 300px
B. 400px
C. 200px
D. 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?

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 A
B. No element
C. The span element
D. Paragraph B

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::marker { content: "*"; color: red; }
C. .required::after { content: "*"; color: red; }
D. .required::before { 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"]:focus > label
B. input[type="checkbox"]:checked + label
C. input[type="checkbox"]:checked ~ form
D. 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?

CSS Variables Medium
A. Black from the browser default
B. Red from the fallback value
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. Four columns
B. One column
C. Two columns
D. Three 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-fill-mode: forwards;
B. animation-play-state: finished;
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:hover { transition: width 0.3s; }
B. .box { animation: width 0.3s; }
C. .box { transition: width 0.3s; }
D. .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?

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

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 2 through 4
B. Columns 1 and 2
C. Columns 2 and 3
D. Columns 3 and 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. (1, 0, 1)
B. (1, 1, 1)
C. (0, 2, 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, content, padding; color: padding
C. Images: content, padding, padding; color: padding
D. Images: content, padding, content; color: content

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. 270px
B. 260px
C. 290px
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 "liga" 0
B. none and normal
C. none and "liga" 0
D. 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?

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

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. 150px
B. 190px
C. 130px
D. 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?

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

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. 200px and 100px, without overflow
B. 250px and 100px, causing overflow
C. 150px and 150px, without 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, 120px, 240px
C. 200px, 140px, 220px
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 4 and 6
B. Elements 3 and 6
C. Elements 3 and 4
D. Elements 2 and 4

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. All tie, so the last rule produces green
B. #post::before, producing red
C. article.note::before, producing blue
D. article:where(.note)::before, producing green

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

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

Form Styling Hard
A. Inputs B, C, and D
B. Inputs B and C
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 red; border is blue
B. Text is black; border is transparent
C. Text is invalid; border is blue
D. Text is red; border is red

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. 500px
C. 640px
D. 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?

CSS Animations Hard
A. The underlying opacity
B. 0.5
C. 1
D. 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?

CSS Transitions Hard
A. It starts at 0 and finishes after 4s
B. It starts at 0.25 and finishes after 3s
C. It starts at 0.75 and finishes after 1s
D. It starts at 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?

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

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