I am facing very difficulty to understand these two different attribute in CSS [att|=val] and [att~=val]
. Can anyone simply give me explanation for it
thanks
I am facing very difficulty to understand these two different attribute in CSS [att|=val] and [att~=val]
. Can anyone simply give me explanation for it
thanks
[attr|=val]
matches a word in val
in any form, so [class=div]
would match .my-div
, .div
, but not .mydiv
.
[attr~=val]
matches a complete word in val
, so [class~=div]
would match .div
, but not .mydiv
or .my-div
.
Example:
HTML
<div id="myDiv"></div>
<div id="myDiv2"></div>
<div id="new-div"></div>
CSS
div[id|=myDiv] {
/* Matches the first div */
}
div[id|=my]{
matches first two divs
}
div[id|=new]{
/* Matches second div - the hyphen counts as a word separator */
}
div[id~=Div]{
/* Matches nothing - "Div" is not a separate word */
}