🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

निम्न CSS का प्रभाव क्या होगा?

What will be the effect of the following CSS?

div[class^="box-"] {
    background-color: yellow;
}
A
All divs will have yellow background
B
Only divs with class starting with "box-" will have yellow background
C
No divs will be affected
D
Only divs with class ending with "box-" will have yellow background
Explanation

The selector div[class^="box-"] is a CSS Attribute Selector. Here is the breakdown of how it works:

  • div: This part targets only

    elements.

  • [class...]: This looks for the class attribute within those elements.

  • ^=: This is the "starts with" operator. It tells the browser to match elements whose attribute value begins with the specified string.

  • "box-": This is the specific string it is looking for.

Other Selector Symbols

For your exams, it is helpful to remember these three common attribute matchers:

  • ^= (Starts with): div[class^="box-"] matches

    .

  • $= (Ends with): div[class$="-box"] matches

    .

  • *= (Contains): div[class*="box"] matches

    .

Correct Answer: B) Only divs with class starting with "box-" will have yellow background

Latest Updates