HTML Element Style How to - Style various anchor type by CSS Attribute Selectors








Question

We would like to know how to style various anchor type by CSS Attribute Selectors.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
a {<!-- w  w  w  . j  av  a2s  .  c o m-->
  display: block
}

a[href^="tel"] {
  color: red;
}

a[href^="mailto"] {
  color: green;
}
</style>
</head>
<body>
  <a href="http://google.com">Google</a>
  <a href="tel:0123456789"> Call 0123456789</a>
  <a href="mailto:admin@google.com"> Mail Admin at Google</a>
</body>
</html>

The code above is rendered as follows: