-
Hajipur, Bihar, 844101
CSS Attribute Selectors allow you to select elements based on the presence or value of an attribute. They are powerful for targeting elements without needing extra classes or IDs.
input[type="text"] {
border: 2px solid green;
}
Targets all
<input>
elements withtype="text"
.
[attr]
)a[target] {
color: red;
}
Targets all anchor (
<a>
) tags that have atarget
attribute.
[attr~="value"]
)[title~="help"] {
background-color: yellow;
}
Selects elements whose
title
contains the word "help" (whole word match).
[attr^="value"]
)a[href^="https"] {
color: green;
}
Matches elements where attribute starts with "https".
[attr$="value"]
)img[src$=".png"] {
border-radius: 10px;
}
Selects all images whose
src
ends with.png
.
[attr*="value"]
)a[href*="login"] {
font-weight: bold;
}
Selects anchor tags with
"login"
anywhere in thehref
value.
[attr|="value"]
)[lang|="en"] {
font-style: italic;
}
Matches
lang="en"
orlang="en-US"
, etc.
Q1. Style all input elements of type checkbox.
Q2. Select links that open in new tab (target="_blank"
).
Q3. Change color of all elements with a data-status
attribute.
Q4. Target <img>
elements with .jpg
at the end.
Q5. Make all buttons with disabled
attribute appear faded.
Q6. Apply bold style to links that contain “signup” in their href
.
Q7. Add padding to all inputs with a placeholder
.
Q8. Set a red border for inputs with type="password"
.
Q9. Italicize all elements where lang
starts with en
.
Q10. Add underline to links that start with "mailto:".
Q1: Which selector matches elements with a specific attribute present?
Q2: What does [type="submit"] target?
Q3: What does [href^="https"] select?
Q4: Which selector targets images ending in .jpg?
Q5: What does [title~="help"] select?
Q6: Which attribute selector matches a word with a hyphen (like en-US) and its base (en)?
Q7: Which selector targets any element with a data- attribute?
Q8: Which selector targets inputs with a placeholder?
Q9: Which symbol represents "starts with" in attribute selectors?
Q10: What does [href*="login"] do?