Sub Selectors

Sub-selectors, also known as combinators, are used to select elements based on their relationship with other elements in the HTML structure.

Descendant Selector ( - Space)

Selects all nested elements inside a parent, regardless of how deep they are.

div p {
  color: blue;
}

✔ This will select all <p> inside any <div>.

Child Selector (> - Direct Child)

Selects only direct children of an element.

div > p {
  color: red;
}

✔ This applies to <p> elements that are directly inside a <div>, but not nested deeper.

Adjacent Sibling Selector (+)

Selects the first immediately following sibling.

h1 + p {
  color: green;
}

✔ This styles only the first <p> immediately after an <h1>.

General Sibling Selector (~)

Selects all following siblings of an element.

h1 ~ p {
  font-weight: bold;
}
✔ This applies to all <p> elements after an <h1>.
Qus. 1 : Which of the following selector select sibling ?

  1. E.class
  2. E~F
  3. *
  4. E,F,G
Qus. 2 : What does the adjacent sibling selector (+) do

  1. Selects the first child of an element
  2. Selects all sibling elements
  3. Selects the immediately next sibling of an element
  4. Selects the parent of an element
Qus. 3 : What does the general sibling selector (~) do

  1. Selects all elements
  2. Selects all siblings after a specified element
  3. Selects only the first sibling of a specified element
  4. Selects only the last sibling of a specified element
Qus. 4 : Which selector targets only <li> elements that are directly under an <ul>?

  1. ul > li
  2. ul li
  3. ul + li
  4. ul ~ li
Qus. 5 : <p>Match the CSS Sub-Selector with Its Meaning</p><p><br></p><table class="table table-bordered"><tbody><tr><td><span style="font-size: 14px;"><b>CSS Sub-Selector</b></span></td><td><span style="font-size: 14px;"><b>Meaning</b></span></td></tr><tr><td><span style="font-size: 14px;">A. div p</span></td><td><span style="font-size: 14px;">1. Selects all &lt;p&gt; elements directly inside a &lt;div&gt;</span><div style="font-size: 14px;"></div></td></tr><tr><td><span style="font-size: 14px;">B. div &gt; p</span></td><td><span style="font-size: 14px;">2. Selects all &lt;p&gt; elements inside a &lt;div&gt;, at any level</span></td></tr><tr><td><span style="font-size: 14px;">C. div + p</span></td><td><span style="font-size: 14px;">3. Selects the first &lt;p&gt; element immediately after a &lt;div&gt;</span></td></tr><tr><td><span style="font-size: 14px;">D. div ~ p</span></td><td><span style="font-size: 14px;">4. Selects all &lt;p&gt; elements that come after a &lt;div&gt;, but not necessarily immediately</span></td></tr><tr><td><br></td><td><span style="font-size: 14px;">5. Selects only the first &lt;p&gt; inside a &lt;div&gt;</span></td></tr><tr><td><br></td><td><span style="font-size: 14px;">6. Selects all &lt;p&gt; elements inside a &lt;div&gt;, including nested ones</span></td></tr></tbody></table><p><br></p>

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

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