Relax Breath of Solution.Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist/ Interactive Designer

Just I wanted.. Do you?…

How to Create a Block Hover Effect for a List of Links

Posted on April 1, 2011 | No Comments

The HTML is quite straightforward. Because IE only supports the :hover element for links, the link anchor needs to go around all the text in the list item. Therefore, we need to provide some additional hooks in order to style the content. We do this through the use of and tags.

<div id="links">
    <ul>
      <li><a href="#" title="Text">Link     Heading One
        <em>Description of link.</em>
        <span>Date   posted</span></a></li>     
      <li><a   href="#" title="Text">Link Heading One
        <em>Description of link.</em>
        <span>Date posted</span></a></li>
        </ul>
  </div> 

And now the CSS. In order for the block hover effect to work properly in IE, we need to make the width of the link the same as that of the list item.

Otherwise the hover effect will only display when you mouse over the text within the list item.

#links ul {
        list-style-type: none;
        width: 400px;
} 

#links li {
        border: 1px dotted #999;
        border-width: 1px 0;
          margin:  5px 0;
}

#links li a { 
        color: #990000;
        display: block;
        font: bold 120% Arial, Helvetica, sans-serif;
        padding: 5px;
        text-decoration: none;
}

 * html #links li a {  /* make hover effect work in IE */
	width:   400px;
}

#links     li a:hover {
        background: #ffffcc;
}

#links a em { 
        color: #333;
          display: block;
          font: normal 85%     Verdana, Helvetica, sans-serif;
        line-height: 125%; 
}

#links       a span {
        color: #125F15;
          font:   normal   70% Verdana, Helvetica, sans-serif;
        line-height: 150%;
}

It’s not necessarily the most semantic markup in the world, especially with those tags, but I’m not sure how else you’d do it.


Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

Comments

Leave a Reply

You must be logged in to post a comment.