Pseudo Selector

In CSS, pseudo-selectors (or pseudo-classes and pseudo-elements) are used to style specific parts of elements or elements in particular states. They help in applying styles dynamically without needing to modify the HTML structure.

Pseudo-Classes (:)

Pseudo-classes target elements based on their state, position, or user interaction.

Pseudo-ClassDescription
:hoverApplies styles when the user hovers over an element.
:focusStyles an element when it gains focus (e.g., an input field).
:nth-child(n)Selects the nth child of a parent element.
:first-childTargets the first child of a parent.
:last-childTargets the last child of a parent.
:checkedStyles checkboxes or radio buttons that are checked.
:disabledTargets disabled form elements.
:not(selector)Excludes elements that match a specific selector.

Example:

button:hover {
  background-color: blue;
  color: white;
}

Pseudo-Elements (::)

Pseudo-elements target specific parts of an element.

Pseudo-ElementDescription
::beforeInserts content before an element.
::afterInserts content after an element.
::first-letterStyles the first letter of a text block.
::first-lineStyles the first line of a paragraph.
::selectionStyles text when selected.

Example:

p::first-letter {
  font-size: 2rem;
  color: red;
}
p::after {
  content: " ✨";
}


Qus. 1 : Which of the following selector selects the elements that are the default among a set of similar elements?

  1. :default
  2. :%
  3. :disabled
  4. None of these
Qus. 2 : Which of the following selector selects the elements that are currently enabled?

  1. :element
  2. :empty
  3. :enabled
  4. None of these
Qus. 3 : How to apply specific styles to h1 tag only when mouse points to it?

  1. h1.hover
  2. h1*hover
  3. h1:hover
  4. h1-hover
Qus. 4 : Which selector selects elements based on a certain state ?

  1. Combinator selector
  2. Pseudo Class selector
  3. Pseudo elements selector
  4. Attribute selector
Qus. 5 : The pseudoclass is activated when the user moves the mouse cursor over the specified element.

  1. mouse over
  2. mouse hover
  3. hover
  4. mouse move
Qus. 6 : Which of the following selector applied styles to elements that are valid per HTML5 validations set either with the pattern or type attributes ?

  1. :valid
  2. :required
  3. :optional
  4. :invalid
Qus. 7 : Which of the following selector selects the element that is the target of a referring URI?

  1. :target
  2. :selection
  3. ::selection
  4. URO
Qus. 8 : Which pseudo-class targets an input field while it is being typed in

  1. focus
  2. hover
  3. active
  4. checked
Qus. 9 : How do you target the last child of a parent element

  1. :nth-child(last)
  2. :last-child
  3. :only-child
  4. :nth-last-child(1)
Qus. 10 : How do you apply styles to all <input> elements that are checked

  1. input:checked
  2. input:focus
  3. input:hover
  4. input:active
Qus. 11 : Which selector applies styles to all <p> elements inside a <div> with the class .content

  1. content p
  2. p.content
  3. .content > p
  4. p .content
Qus. 12 : <p>Match the CSS User Action Pseudo-Class with Its Effect</p><p><br></p><table class="table table-bordered"><tbody><tr><td><span style="font-size: 14px;"><b>CSS Pseudo-Class</b></span></td><td><span style="font-size: 14px;"><b>Effect</b></span></td></tr><tr><td><span style="font-size: 14px;">A. :hover</span></td><td><span style="font-size: 14px;">1. Styles an element when the mouse leaves it</span></td></tr><tr><td><span style="font-size: 14px;">B. :focus</span></td><td><span style="font-size: 14px;">2. Applies a style when an element is clicked or focused</span></td></tr><tr><td><span style="font-size: 14px;">C. :active</span></td><td><span style="font-size: 14px;">3. Applies a style when an element is actively being clicked</span></td></tr><tr><td><span style="font-size: 14px;">D. :visited</span></td><td><span style="font-size: 14px;">4. Styles a link that has been previously clicked (visited)</span></td></tr><tr><td><br></td><td><span style="font-size: 14px;">5. Styles an element only when it is visible on the screen</span></td></tr><tr><td><br></td><td><span style="font-size: 14px;">6. Applies a style when an element is hovered over</span></td></tr></tbody></table><p><br></p>

  1. A → 4, B → 3, C → 2, D → 1
  2. A →5, B → 4, C → 3, D → 2
  3. A → 6, B → 2, C → 3, D → 4
  4. A → 5, B → 2, C → 3, D → 6

Programs

HTML code using CSS to create a job application

View Solution


Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad