<input type="text" placeholder="nothing" title="google" required>
**Inside CSS file: **
input[type="text"]{
border: 2px solid red;
}
input::placeholder{
color:green;
}
input[title="google"]{
background-color:black;
color:white;
}
Why the writting process is different for type,placeholder and title? Though the writting looks same inside tag. How to understand which are attribute and which are elements?
2
Answers
In CSS, we have attribute selectors and pseudo-elements that serve different purposes and have distinct syntax. Let’s understand their differences and how to identify them:
To differentiate between attribute selectors and pseudo-elements:
In your CSS code, the selectors input[type="text"], input[title="google"], and input::placeholder each target different aspects of the element:
By using these selectors, we can apply unique styles to specific elements or parts of elements based on their attributes or states.
input::placeholder
selects the placeholder of an<input>
, whereasinput[attribute="value"]
selects an<input>
whose attribute has a value of value. These do different things.Visualized example:
Note: This answer was converted from a comment as I can’t find any duplicate targets.