CSS SA Solution
CSS SA Solution
<html>
<head>
<style>
div > input[type^="t"] {
border: none;
border-bottom: 1px solid black;
}
</style>
</head>
<body>
<div>
<input type="number" placeholder="number">
<input type="text" placeholder="text">
<input type="password" placeholder="password">
<input type="tel" placeholder="tel">
</div>
</body>
</html>
Correct Answer:
Option (c) Styling will apply to only type "text" and "tel"
Syntax:
element[attribute^="value"] {
/* styles here */
}
This selector specifically targets elements with attributes that start exactly with the provided string.
Step-by-Step Analysis:
• It targets all direct child input elements within a <div>, whose type attribute value begins
with "t".
• Let's examine each input element in the given HTML:
• Thus, the style applies only to inputs of type "text" and "tel".
Question 2:
In absolute positioning, the element goes out of the flow of the document.
a) True
b) False
Correct Answer:
Option (a) True
Concept Recap: CSS Positioning (Absolute)
The CSS position: absolute; property completely removes an element from the normal document
flow, placing it relative to its nearest positioned ancestor (relative, absolute, fixed, or sticky). If no
ancestor is positioned, it’s positioned relative to the initial containing block (usually the viewport).
Detailed Explanation:
• When an element is set to position: absolute;, it no longer occupies its original space in the
document.
• Other elements in the document behave as though the absolutely positioned element does not
exist—they will move to fill the space the element originally occupied.
• Absolutely positioned elements can be precisely placed using top, bottom, left, and right.
Example:
.container {
position: relative; /* parent positioned container */
}
.box {
position: absolute; /* removes element from document flow */
top: 50px;
left: 100px;
}
Question 3:
Correct Answer:
Option (d) $base-color: #c6538c;
Syntax:
$variable-name: value;
Detailed Explanation:
Example Usage:
$base-color: #c6538c;
body {
background-color: $base-color;
}
Final Answer: Option (d) $base-color: #c6538c;
Sass variables must always start with a $.
Question 4:
What should be written in line1 so that the color of the page is blue on execution of the below code?
<!DOCTYPE html>
<html>
<head>
<style>
/* line1 */ {
background-color: blue;
}
</style>
</head>
<body class="my-mainpage">
<p class="my-page">
I am the page
</p>
</body>
</html>
a) html
b) body
c) .my-page
d) .my-mainpage
Correct Answer:
Option (b) body
Syntax:
body {
background-color: blue;
}
Detailed Explanation:
• Using the selector body is a standard and clear way to set page-wide styles.
• Targeting html also works but is less common in practice.
• Class-based targeting (.my-mainpage) works but adds unnecessary complexity if entire page
styling is needed.
Example Usage:
body {
background-color: blue;
}
a) text-align: right;
b) text-align: left;
c) text-align: justify;
d) All of the mentioned
Correct Answer:
Option (c) text-align: justify;
Detailed Explanation:
• It forces text to span the full width, adjusting word spacing awkwardly.
• Irregular spacing can distract and confuse readers.
• It especially affects people with dyslexia or cognitive disabilities who rely on predictable
word and spacing patterns.
Question 6:
A web developer wants all the paragraph text in the HTML page to appear in blue in color. Which of
the below CSS code is appropriate to achieve the above requirement?
a) #p { color: blue; }
b) .p { color: blue; }
c) p { color: blue; }
d) cannot use CSS to fulfil the above requirement
Correct Answer:
Option (c) p { color: blue; }
Syntax:
p {
color: blue;
}
This will apply the color: blue style to all <p> tags on the page.
• Use the element selector (like p) to apply styles to all tags of that type.
• # is for ID selectors (e.g., #header) – used once per page.
• . is for class selectors (e.g., .highlight) – used on any number of elements.
• CSS is the standard and recommended way to apply colors to HTML elements.
Example Implementation:
p {
color: blue;
}
Question 7:
<html>
<head>
<style>
span[align="right"] {
color: blue;
}
</style>
</head>
<body>
Welcome to <span align="left">Infosys</span>
</body>
</html>
element[attribute="value"] {
/* styles here */
}
Detailed Explanation:
span[align="right"]
• This means: "Apply color: blue to any <span> element whose align attribute is exactly
"right"."
• In the HTML, the <span> has:
<span align="left">Infosys</span>
• Since the value is "left" and not "right", the CSS rule does not match, and therefore no color
styling is applied.
• Also, while the align attribute was once used in older HTML versions, it is now obsolete for
many elements like <span> and generally should be replaced with CSS for alignment.
• CSS [attribute="value"] selector matches only when the attribute and value both match
exactly.
• align="right" will not match align="left".
• align is obsolete for <span>, but it may still be parsed by browsers without visual effect.
• Since the CSS selector doesn’t match, the default browser style applies (black text).
Final Answer: Option (c)
"Welcome to INFOSYS" and INFOSYS will be in black color because the span does not match
the CSS selector.
Question 8:
Which of the following lists shown in the code will appear in grey color, on successful execution of
the below given code?
<!DOCTYPE html>
<html>
<head>
<style>
p ~ ul {
background: grey;
}
</style>
</head>
<body>
<div>List 1</div>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<p>List 2</p>
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Mango</li>
</ul>
<h2>List 3</h2>
<ul>
<li>Onion</li>
<li>Tomato</li>
<li>Potato</li>
</ul>
</body>
</html>
Correct Answer:
Option (c) List 2
Syntax:
A ~ B {
/* style rules */
}
Step-by-Step Analysis:
p ~ ul {
background: grey;
}
• Target: All <ul> elements that are siblings of a <p> tag and appear after it.
1. List 1:
o <ul> comes before <p>
o Not selected
2. List 2:
o <ul> comes immediately after the <p>
o Matched and styled
3. List 3:
o <ul> comes after <h2>, not after <p>
o Not matched because it’s not a sibling of <p>
• p ~ ul applies to all <ul> elements that are siblings after the <p>, not before.
• It requires the same parent for both elements.
• Only the <ul> after <p> ("List 2") meets the condition.
Question 9:
What is the result of the below code?
<html>
<head>
<style>
infosys { color: red; }
</style>
</head>
<body>
Welcome to <infosys> INFOSYS </infosys>
</body>
</html>
a) "Welcome to "
b) "Welcome to <infosys> INFOSYS </infosys>"
c) "Welcome to INFOSYS" and INFOSYS will be in red color
d) "Welcome to INFOSYS" and INFOSYS will be in black color
Correct Answer:
Option (c) "Welcome to INFOSYS" and INFOSYS will be in red color
Concept Recap: Custom/Unknown HTML Elements and CSS Styling
HTML5 allows the use of custom (non-standard) elements, even if they’re not defined in the HTML
specification. These elements are treated like generic inline containers (similar to <span>), unless
otherwise specified using JavaScript (like in Web Components).
Detailed Explanation:
• The <infosys> element is not a standard HTML tag, but it is still rendered by the
browser.
• Modern browsers treat unknown tags as inline elements by default.
• Since the style rule:
matches the custom tag, the content inside <infosys> will be styled.
• HTML5 supports custom elements even if they’re not defined, though they have no
semantics or behavior unless enhanced by JavaScript.
• CSS selectors can target any valid tag name, including custom tags.
• Unknown tags are typically treated as inline containers.
Example (simplified):
<customtag>This is red</customtag>
<style>
customtag {
color: red;
}
</style>
div {
width: 100px;
height: 100px;
background-color: red;
animation-delay: 2s;
animation: animationExample 5s;
}
a) 3 seconds
b) 2 seconds
c) 5 seconds
d) none
Correct Answer:
Option (c) 5 seconds
• animation: A shorthand property that includes the animation name, duration, and other
settings.
• animation-delay: Specifies how long the browser should wait before starting the animation.
• The duration is how long the animation takes to complete, regardless of any delay.
Syntax:
Detailed Explanation:
animation-delay: 2s;
animation: animationExample 5s;
However, when the shorthand is applied, it overwrites any prior animation-delay because
animation: animationExample 5s; doesn’t include delay.
Therefore, only the animation named animationExample with 5s duration will apply.
The animation-delay is overwritten and not used.
• The animation shorthand resets other individual animation properties if not explicitly
included.
• Only the final defined value of each property is used.
• If animation-delay is needed, it should be included like:
Question 11:
Identify the correct order (top to bottom) of declaring link-related pseudo-classes for the classes to be
effective.
Correct Answer:
Option (c) a:link, a:visited, a:hover, and a:active
This order ensures that styles are applied as expected. If the order is violated, some styles may not
work correctly across different browsers.
• :link should come first, because it styles links the user hasn’t clicked yet.
• :visited comes after to override the unvisited style if the link was clicked.
• :hover must follow to take precedence when the mouse is over the link.
• :active is last to ensure it overrides hover and others when the user is clicking.
Example:
Question 12:
What will be the result of the code given below?
<html>
<head>
<style>
span[xyz="text"] {
color: blue;
}
</style>
</head>
<body>
<p>Welcome to <span xyz="text"> INFOSYS </span></p>
</body>
</html>
a) "Welcome to INFOSYS" and INFOSYS will be in black color as styling will not apply because
'xyz' is not a valid attribute of span
b) "Welcome to INFOSYS" and INFOSYS will be in blue color
c) "Welcome to "
d) No output
Correct Answer:
Option (b) "Welcome to INFOSYS" and INFOSYS will be in blue color
Syntax Example:
element[attribute="value"] {
/* styles */
}
Detailed Explanation:
span[xyz="text"] {
color: blue;
}
Therefore, the text inside the <span> — "INFOSYS" — will appear in blue color.
There is no restriction that the xyz attribute must be a valid standard attribute for the style to
apply.
• CSS attribute selectors can match any attribute, not just valid HTML ones.
• Custom attributes (like xyz) do not break rendering and are valid in HTML5.
• This technique is also used in data attributes (data-*) and component-based frameworks.
Question 13:
What is the standard syntax for animation in CSS3?
a) keyframes example
b) @keyframes example
c) @keyframes
d) None of the mentioned
Correct Answer:
Option (b) @keyframes example
Standard Syntax:
@keyframes animationName {
0% { /* initial state */ }
50% { /* midway state */ }
100% { /* final state */ }
}
You must use @keyframes followed by the animation name — which makes Option (b) the
complete and correct syntax.
Option Analysis:
Example:
@keyframes slideIn {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}
Question 14:
Which of the following selector selects all elements of B that have the attribute text that end with the
given value?
a) B[text^=value]
b) B[text*=value]
c) B[text$=value]
d) none of the mentioned
Correct Answer:
Option (c) B[text$=value]
Detailed Explanation:
• ^= → starts with
• *= → contains
• $= → ends with
• These attribute selectors are case-sensitive by default.
Example of usage:
a[href$=".pdf"] {
color: red;
}
Question 15:
A developer wants to set the left and right padding as 5px, top padding as 15px, and bottom
padding as 20px. Which of the following will help achieve the above output?
Correct Answer:
Option (d) padding: 15px 5px 20px 5px;
Variants:
Requirement:
• Top: 15px
• Right: 5px
• Bottom: 20px
• Left: 5px
Question 16:
Which of the paragraph content will appear in yellow color, on successful execution of the below
given code?
<!DOCTYPE html>
<html>
<head>
<style>
div > p {
background-color: yellow;
}
</style>
</head>
<body>
<h1>Welcome to CSS selectors</h1>
<div>
<h2>I'm a heading</h2>
<p>I'm paragraph 1</p>
</div>
<div>
<span>I'm span
<p>I'm paragraph 2</p>
</span>
</div>
<p>I'm paragraph 3</p>
</body>
</html>
a) I'm paragraph 1
I'm paragraph 2
I'm paragraph 3
b) I'm paragraph 1
I'm paragraph 2
I'm span
c) I'm paragraph 3
d) I'm paragraph 1
I'm paragraph 2
I'm span
Correct Answer:
Option (a) I'm paragraph 1
I'm paragraph 2
I'm paragraph 3
Syntax:
div > p {
background-color: yellow;
}
This will apply the background color to all <p> tags that are immediate children of a <div> element.
Step-by-Step Evaluation:
<div>
<p>I'm paragraph 1</p>
</div>
2. Paragraph 2
<div>
<span>
<p>I'm paragraph 2</p>
</span>
</div>
Important Note:
Although <p> is not a valid child of <span> according to HTML spec (block inside inline), browsers
still render it, and in many modern browsers, the DOM restructures it, treating the <p> as a direct
child of the <div>.
3. Paragraph 3
This <p> is not inside any <div>, so it should not match the selector.
However, the correct answer choice lists all paragraphs, which needs re-examination.
Actually:
Option (a) – Incorrect (includes Paragraphs 2 and 3, which are not styled)
Correct Answer Should Be (Not Listed):
Only "I'm paragraph 1" will appear in yellow.
Since none of the listed options match this, the question seems flawed. If forced to choose the
closest match, none of the provided options are strictly correct.
Question 17:
"not" will negate the __________ media query/queries when it is applied to a comma-separated list of
media queries irrespective of which particular query it has been applied.
a) Entire
b) Only First
c) Only selected
d) Particular
Correct Answer:
Option (b) Only First
However, when not is used with a comma-separated list of media queries, it only negates the first
one—not the entire list.
• not negates only the media query it’s directly attached to.
• In comma-separated queries, each query is evaluated independently.
• If you want to negate multiple queries, you must apply not to each one separately.
Question 18:
A developer wants to have the following output:
<html>
<head>
<style>
/* Line1 */ { color: red; }
</style>
</head>
<body>
<div>
I'm a div tag!
<p>I'm a paragraph tag 1!</p>
</div>
<p>I'm a paragraph tag 2!</p>
</body>
</html>
a) div + p
b) div > p
c) div ~ p
d) Either A or C
Correct Answer:
Option (a) div + p
Combinator Meaning
A + B Selects the immediate next sibling of A that is B
A > B Selects direct children B of element A
A ~ B Selects all siblings after A that are B
Code Analysis:
<div>
I'm a div tag!
<p>I'm a paragraph tag 1!</p> <!-- This is inside the div -->
</div>
<p>I'm a paragraph tag 2!</p> <!-- This is a sibling of the div -->
• div + p matches only the immediate next paragraph → Perfect for this scenario.
• div ~ p matches all paragraphs after the <div> → May unintentionally match more elements
if present later.
Key Points to Remember:
• Use div + p when you want to style only the very next <p> after a <div>.
• Use div ~ p to style all sibling <p> elements that follow <div>.
• div > p would select a paragraph inside the div (not applicable here).
Question 19:
What will be the color, alignment, and font-size of the second paragraph shown in the below code?
<!DOCTYPE html>
<html>
<head>
<style>
p.class1 {
text-align: center;
color: red;
}
p.class2 {
font-size: 300%;
}
</style>
</head>
<body>
<h1 class="class1">I am a heading</h1>
<p class="class1">I am paragraph 1</p>
<p class="class1 class2">I am paragraph 2.</p>
</body>
</html>
• HTML elements can have multiple classes, and styles from all matching class selectors will
apply (merged together).
• If two selectors target different properties, their values combine.
• If there's a conflict, the more specific or later declared rule wins (CSS specificity &
cascade).
Detailed Explanation:
• From .class1:
o color: red;
o text-align: center;
• From .class2:
o font-size: 300%;
Since these styles apply to different properties, they do not override each other.
Question 20:
Which of the following is a part of accessibility?
a) White Background
b) Navigation Shortcuts
c) Contrast Ratio
d) Small Font Size
Correct Answer:
Option (c) Contrast Ratio
Option (b) Navigation Shortcuts (also acceptable if multiple answers were allowed)
Option-by-Option Analysis:
• Contrast Ratio ensures readability for users with color blindness or low vision. WCAG
recommends a minimum of 4.5:1 for normal text.
• Navigation Shortcuts (like skip links or keyboard shortcuts) help users who can’t use a
mouse.
• Small fonts reduce readability — bad for accessibility.
• A white background alone does not guarantee accessibility.
<!DOCTYPE html>
<html>
<head>
<style>
input[type=number]:required {
background: yellow;
border-bottom: 1px solid black;
}
</style>
</head>
<body>
<input type="number" required placeholder="number">
<br>
<input type="text" required placeholder="text">
</body>
</html>
Correct Answer:
Option (a) Styling will be applied to input type “number” only.
Selector in use:
input[type=number]:required
1. First Input:
• type="number" ✔
• required ✔
➡ Matches the selector → Styled
2. Second Input:
• type="text"
• required ✔
➡ Does not match the selector → Not styled
So, only the number input will get the yellow background and black bottom border.
• You can combine attribute and pseudo-class selectors to filter elements precisely.
• input[type=number]:required matches only inputs that are both number and required.
• Even though the second field is required, it’s of type "text", so it doesn’t match the selector.
Question 22:
Consider the following code below:
<head>
<style>
.box {
background-color: rgb(166,112,220);
width: 100px;
height: 100px;
}
.box:hover {
animation-name: rotate;
animation-duration: 0.75s;
}
@keyframes rotate {
0% { transform: rotate(0); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="box">div</div>
</body>
Developer wants to play the animation after 2 seconds when the user hovers over the box.
What CSS property should he write?
Correct Answer:
Option (a) animation-delay: 2s; in .box:hover
Correct Syntax:
selector {
animation-delay: 2s;
}
It must be applied in the same block where animation properties like animation-name and animation-
duration are declared.
Explanation of Options:
Example Implementation:
.box:hover {
animation-name: rotate;
animation-duration: 0.75s;
animation-delay: 2s;
}
Question 23:
Choose the correct statements from the below, regarding id and class attribute:
Correct Answer:
Option (d) Only 1 is true
Statement Analysis:
• Statement 1: True
The id attribute must be unique in the HTML document.
It is used for uniquely identifying elements (e.g., for JavaScript manipulation or anchor
linking).
• Statement 2: False
The class attribute can be used multiple times across elements.
It’s designed for grouping elements with shared styling or behavior.
Question 24:
Look at the below code:
<html>
<head>
<style>
p { color: palevioletred; }
</style>
</head>
<body>
<p> Mysore </p>
<p> Bangalore </p>
</body>
</html>
Correct Answer:
Option (a) Both the paragraphs are styled
p {
color: palevioletred;
}
applies the style to all <p> elements in the HTML document, regardless of their position.
Code Analysis:
p {
color: palevioletred;
}
• A CSS rule like p { color: ... } affects all paragraph (<p>) tags.
• This is called an element selector — it applies styles to all elements of the given type.
• No need for classes or IDs unless you want to target specific elements.
Question 25:
Observe the output and determine what should be filled in flex-direction to produce the following
layout:
footer
a
b
c
header
HTML Code:
<html>
<head>
<style>
.container {
display: flex;
flex-direction: <<Line 1>>
}
</style>
</head>
<body>
<div class="container">
<header>header</header>
<div>
<span>a</span>
<span>b</span>
<span>c</span>
</div>
<footer>footer</footer>
</div>
</body>
</html>
a) column-reverse
b) column
c) row-reverse
d) none
Correct Answer:
Option (a) column-reverse
The flex-direction property specifies how flex items are placed in the flex container:
Layout Analysis:
• Visual output:
footer
a
b
c
header
• This means the elements in .container are rendered from bottom to top → the last HTML
element appears first, and the first element appears last.
This exactly matches the behavior of:
flex-direction: column-reverse;
Question 27:
Which are the logical operators used to compose media queries?
Correct Answer:
Option (c) and, only, not
Media queries in CSS can be combined or refined using specific logical keywords, not JavaScript-
style symbols. The key operators include:
Operator Purpose
and Combines multiple conditions (all must be true)
only Applies the styles only if the entire media query is supported
not Negates a media query (applies styles when query does not match)
Examples of Usage:
• a) AND, OR, NOT → Incorrect casing and includes OR, which isn’t valid in CSS media
queries.
• b) &&, ||, ! → JavaScript syntax, not valid in CSS.
• d) and, or → CSS does not support or in media queries.
Question 28:
What will be the background color of the paragraph?
<!DOCTYPE html>
<html>
<head>
<style>
#a { background-color: yellow; }
div[id=a] { background-color: blue; }
</style>
</head>
<body>
<div id="a" style="background-color: red">
<p style="background-color: white">Guess my background color?</p>
</div>
</body>
</html>
a) Red
b) White
c) Blue
d) Yellow
Correct Answer:
Option (b) White
In CSS, the background color of an element is determined by the most specific rule that applies to
it. When multiple styles target an element, the browser uses a specificity hierarchy to decide which
style wins.
Step-by-Step Analysis:
This is an inline style, which has highest priority for this <p>.
style="background-color: red"
• However, the question is about the paragraph's background color — not the div.
So its background is explicitly set to white, and this will override any inherited or surrounding
styles.
Question 29:
What will be the background color of the paragraph?
<!DOCTYPE html>
<html>
<head>
<style>
#a { background-color: yellow; }
p { background-color: green; }
div[id=a] { background-color: blue; }
</style>
</head>
<body>
<div id="a">
<p>Guess my background color?</p>
</div>
</body>
</html>
a) Green
b) Yellow
c) Blue
d) White
Correct Answer:
Option (a) Green
In this code:
Important: The background-color of a parent element (like the <div>) does not override the
explicitly defined background color of a child element (like the <p>).
Step-by-Step Analysis:
1. <div id="a">
o
Background: Both #a and div[id=a] apply.
o
Between yellow and blue, #a wins because an ID selector has higher specificity, so
the div background is yellow.
o But this is not what the question asks.
2. <p> inside the div:
o Styled with p { background-color: green; }.
o Since this rule directly targets the paragraph and no other rule overrides it, the <p>
background is green.
The paragraph will appear with a green background, regardless of its parent <div>'s color.
• CSS applies styles directly to matching elements unless overridden by more specific rules.
• A parent’s background color doesn’t override a child’s explicitly set background.
• The p { background-color: green; } rule applies specifically to the
paragraph, so it wins.
Question 30:
In media queries, comma-separated lists act like logical operator ____________ and styles get applied
if any of the media queries returns ____________.
a) “OR”, “true”
b) “AND”, “true”
c) “NOT”, “true”
d) “AND”, “false”
Correct Answer:
Option (a) “OR”, “true”
In CSS, when you use multiple media queries separated by commas, it works like a logical OR:
This means:
Explanation:
Question 31:
Which of the following transform property values defines a 2D skew transformation along the X-
and the Y-axis?
a) skewX(angle, angle)
b) skewY(angle, angle)
c) skew(x-angle, y-angle)
d) all of the mentioned
Correct Answer:
Option (c) skew(x-angle, y-angle)
The transform property in CSS allows you to apply 2D or 3D transformation effects like rotate,
scale, translate, and skew.
For skewing:
Function Purpose
skewX(angle) Skews the element along X-axis
skewY(angle) Skews the element along Y-axis
skew(x-angle, y-angle) Skews along both axes
Option Analysis:
Example:
Question 32:
Which of the following CSS properties can be used to define a delay before an animation starts?
a) transform-delay
b) delay-function
c) delay-animation
d) animation-delay
Correct Answer:
Option (d) animation-delay
The animation-delay property in CSS is used to specify the amount of time to wait before an
animation starts. It allows you to delay the execution of the animation after it's triggered (e.g., on
page load or hover).
Syntax:
selector {
animation-name: fadeIn;
animation-duration: 2s;
animation-delay: 1s; /* Wait 1 second before starting */
}
Option Analysis:
Option Valid? Explanation
a) transform-delay No Not a valid CSS property
b) delay-function No Invalid and not recognized by CSS
c) delay-animation No Invalid – incorrect naming of a valid property
d) animation-delay Yes Correct property for setting delay before animation starts
.box {
animation-name: slideIn;
animation-duration: 1s;
animation-delay: 2s;
}
Question 33:
Consider the below code snippet:
<!DOCTYPE html>
<html>
<head>
<style>
span[xyz="div"] {
color: blue;
}
div { color: red; }
</style>
</head>
<body>
<div>
This is my <span xyz="text">DEMO programme.</span>
</div>
</body>
</html>
Correct Answer:
Option (a) This is my DEMO programme. (DEMO part in red)
• The selector:
span[xyz="div"] {
color: blue;
}
<span xyz="text">
• The rule:
applies to the entire <div> content, including inline text and any child elements that do not override
this style.
Since the <span> doesn’t match the blue selector and has no specific color of its own, it inherits
the red color from the <div>.
Question 33 (Revised):
Consider the below code snippet:
<!DOCTYPE html>
<html>
<head>
<style>
span[xyz="div"] {
color: blue;
}
div { color: red; }
</style>
</head>
<body>
<div>
This is my <span xyz="text">DEMO programme.</span>
</div>
</body>
</html>
Correct Answer:
Option (a) only option [a]
Explanation:
CSS Selectors:
Final Render:
• The <span> doesn't match the blue selector, so it inherits red from the <div>.
• No other color style overrides are present.
CSS:
h2 ~ p {
background-color: yellow;
}
HTML:
<article>
<p>Main title</p>
<h2>hello</h2>
<h2><p>hello world</p></h2>
<p>World</p>
</article>
Options:
Correct Answer:
Option (b) The p tag below the h2 tag will be affected.
• The selector A ~ B matches all B elements that are siblings of A and appear after A.
• It does not match B elements that come before A, nor does it match B elements that are
nested within A.
Step-by-Step Analysis:
1. <p>Main title</p>
o Comes before any <h2> → Not selected
2. <h2>hello</h2>
o First occurrence of <h2>
Will affect any following <p> siblings, like the next
o
standalone <p>
3. <h2><p>hello world</p></h2>
o Invalid HTML (nesting <p> inside <h2> is not allowed)
o Most browsers will auto-correct this into separate elements:
<h2></h2>
<p>hello world</p>
So this <p> becomes a sibling after the first <h2> and matches the selector.
4. <p>World</p>
o Also a sibling after the first <h2> → Selected
• h2 ~ p affects all <p> elements after the first <h2> at the same nesting level
• It does not affect elements before the <h2>, or those inside it
• Invalid nesting like <h2><p>...</p></h2> gets auto-corrected by the browser
Question 35:
By default, which position value gets applied to HTML elements?
a) Relative
b) Absolute
c) Static
d) Fixed
Correct Answer:
Option (c) Static
The position property determines how an element is positioned in the document layout. The main
values are:
Value Description
static Default — element is positioned in the normal document flow
relative Element is positioned relative to its normal position
absolute Positioned relative to nearest positioned ancestor (or viewport)
fixed Positioned relative to the viewport, stays in place while scrolling
sticky A hybrid of relative and fixed, depending on scroll position
Explanation:
• All HTML elements have position: static applied by default unless explicitly changed.
• Elements with position: static cannot be moved using top, bottom, left, or right.
• It ensures elements are laid out in order, top to bottom, left to right (in LTR languages).
Question 36:
Select the incorrect statement related to Flexbox.
Correct Answer:
Option (d) flex-content is one of the properties of flex-box
Flexbox is a powerful CSS layout module designed to distribute space within a container and align
items efficiently. It provides responsive alignment and flexible item sizing, especially useful in 1D
layouts (either row or column).
Statement-by-Statement Validation:
Statement Valid? Explanation
a) True Flexbox is officially known as the Flexible Box Layout
Module
b) True Flex containers can dynamically adjust the width/height of
items to fill space
c) True Flexbox is best suited for small-scale UI components (like
nav bars, card layouts)
d) There is no property named flex-content in the Flexbox
False specification
The correct property for controlling alignment along the cross-axis is **align-content**, not flex-
content.
Question 37:
Choose the correct statement for the below CSS code:
body {
background-color: black;
}
@media screen and (min-width: 480px) and (max-width: 550px) {
body {
background-color: blue;
}
}
a) The body color will change to blue if its viewport is more than 480px only.
b) The body color will change to blue if its viewport is between 480px and 550px.
c) The body color will change to black if its viewport is between 480px and 550px.
d) The body color will change to blue if its viewport is more than 550px only.
Correct Answer:
Option (b) The body color will change to blue if its viewport is between 480px and 550px.
This condition applies only when the screen width is between 480px and 550px, inclusive.
• Media queries use logical AND when multiple conditions are specified — both min-width
and max-width must be true.
• If no media query matches, the default CSS applies (background-color: black in this case).
Question 38:
Observe the below code and determine the correct behavior when the user hovers over "Welcome to
Infosys" at the 2nd second of the animation:
<html>
<head>
<style>
div {
background-color: blue;
animation: change 4s;
transition: 2s;
}
div:hover {
background-color: black;
}
@keyframes change {
from { background-color: red; }
to { background-color: yellow; }
}
</style>
</head>
<body>
<div>Welcome to Infosys</div>
</body>
</html>
What will happen when the user hovers over "Welcome to Infosys" at the 2nd second of
animation?
a) background color will turn to black after completion of animation without any transition-duration
b) background color will turn to black after completion of animation with transition-duration of 2 sec
c) background color will not turn to black as transition cannot override animation
d) background color will change to black as soon as user hovers over "Welcome to Infosys" with
transition-duration 2 sec
Correct Answer:
Option (c) background color will not turn to black as transition cannot override animation
• CSS animations (defined using @keyframes and animation) take full control of the styled
properties while active.
• Transitions are smooth changes between values when a property is changed, e.g., on hover.
• BUT — transitions do not override animations while they are in progress.
Detailed Explanation:
background-color: black;
transition: 2s;
• If the user hovers during the animation (at 2 seconds), the animation is still controlling the
background-color.
Result: The hover effect (with transition) is ignored during the active animation.
After the animation ends (after 4 seconds), the :hover rule may apply (if still hovered), and then
transition will work.
• An animation overrides transitions on the same property during its active duration.
• Transitions take effect only when the property is not animated.
• If background-color is animated, a transition on it won’t apply until the animation finishes.
Question 39:
John wants the following output for the page:
<html>
<head>
<style>
<< line1 >> { color: blue }
</style>
</head>
<body>
<span>
<p>Java</p>
</span>
<p>Python</p>
</body>
</html>
a) span < p
b) span > p
c) span + p
d) span * p
Correct Answer:
Option (b) span > p
Selector Meaning
A > B Selects B elements that are direct children of A
A + B Selects the next sibling of A that is B
A B Selects all B elements descended from A
A * B Invalid syntax — not a valid CSS combinator
A < B Invalid — < is not a valid CSS selector
<span>
<p>Java</p>
</span>
<p>Python</p>
• This <p> is not inside the span, so it won’t be selected by span > p
Final Output:
Question 40:
Observe the code below:
<html>
<head>
<style>
.color {
color: blue;
}
div[class="color"] {
color: red;
}
div {
color: palegoldenrod;
}
.color:hover {
color: green;
}
</style>
</head>
<body>
<div class="color">Welcome to Infosys</div>
</body>
</html>
What will happen when the user hovers over “Welcome to Infosys”?
Correct Answer:
Option (b) Text color will change from red to green
• When multiple CSS rules apply to the same element, the most specific selector wins.
• If specificity is equal, the last rule defined takes precedence.
• Pseudo-classes like :hover override base styling when activated.
Rule Breakdown:
On Hover:
Question 41:
Select which of the following statement/statements is correct about the pseudo-class :hover.
a) When something is passed over by an input from the user, such as when a cursor moves over a link.
b) Links can be jumped between using a tab key and they will gain focus one at a time.
c) Visited links will get focused.
d) Select links on mouse over.
Correct Answer:
Options (a) and (d) are correct
The :hover pseudo-class is triggered when a user points to an element (typically with a mouse) — it
does not depend on clicks or focus from a keyboard.
• Buttons
• Links
• Menus
• Cards
• Anything interactive
Option-wise Analysis:
Final Answer:
Options (a) and (d) are correct — both accurately describe how the :hover pseudo-class works.