CSS3 Media Queries - Apply Email Addresses to Links

We will use four styles with this example:

      Viewport is less than 750 pixels - a list of email links,
      Viewport is 750 and 899 pixels wide - add email icons before each link,
      Viewport is 900 and 1100 pixels wide - add text "email" before each link,
      Viewport is wider than 1100 pixels - append the email address after each links

We will use the value of the data- attribute to add the email address after the person's name:

HTML file: Displayed by browser:
<style>
ul {
    list-style-type: none;
}
ul li a {
    color: green;
    text-decoration: none;
    padding: 3px;
    display: block;
}
@media screen and (max-width: 899px) and (min-width: 750px) {
    ul li a {
       padding-left: 30px;
       background: url(../html_beg/images/email.png) left center no-repeat;
    }
}
@media screen and (max-width: 1100px) and (min-width: 900px) {
    ul li a:before {
       content: "Email: ";
       font-style: italic;
       color: #666666;
    }
}
@media screen and (min-width: 1101px) {
    ul li a:after {
       content: " (" attr(data-email) ")";
       font-size: 12px;
       font-style: italic;
       color: #666666;
    }
}
</style>
<body>
<h1>Resize the browser window to see the effect!</h1>
<ul>
  <li><a data-email="[email protected]" href="mailto:[email protected]">John Doe</a></li>
  <li><a data-email="[email protected]" href="mailto:[email protected]">Mary Moe</a></li>
  <li><a data-email="[email protected]" href="mailto:[email protected]">Amanda Panda</a></li>
</ul>
</body>

Resize the browser window to see the effect!


Back button Table of Contents Next button