CSS Attribute Selector Part 1

Notes:

CSS - Attribute selector ([]):
Attribute selector is used to select HTML elements based on their attribute name and attribute value.

Syntax of attribute selector:
selector [attribute expression]
{
declaration list;
}
Where:
selector is optional, it can be tag, class, id selector etc…
attribute expression can be a valid combination of attribute name, value and associated operators.

Ex:
tag selector[attribute name=”value”]
{
declaration list;
}
It selects any HTML element targeted by the tag selector, which contains an attribute name where the attribute value exactly matches the value specified in attribute expression

Ex:
p[align=”right”]
{
border:2px solid red;
}
It selects any paragraph element, which contains an attribute align, where the align attribute value exactly matches the value right.

Interview Questions: