Applications, CSS, Tutorials

Create a Twitter Box in Your Sidebar – Part II

My Sidebar Twitter box tutorial seems to have struck a chord with WordPress users and it has generated some interesting questions. One of them, from TheNext2ShineBlog posed an interesting problem I decided to look into in more detail:

the only thing I would like to change is the time aspect (23 days ago // 4 hours ago). Is there a css code to hide that link without taking away the links from the original twitter message?

What TheN2S is refering to is the tail end of each Twitter message that reads either “less than a minute ago”, “a few minutes ago” etc up to “X days ago”.

Careful inspection of the JavaScript that generates the Tweets for the application (found here) shows that the time information is a core function of the Twitter system so it is coded into the main structure of the application itself. Therefore it is hard to siply remove it unless you want to create your own custom JS. But TheN2S is on the right track in asking if it can be removed by way of CSS.

Lifting a random tweet off my own site I found that the main body the JS spits out is contained within a span tag while the tail end with the time info is not:

<li>
   <span>@<a href="http://www.twitter.com/webb_art">webb_art</a> DropBox works well for me and is platform independent: <a href="http://www.getdropbox.com/">	http://www.getdropbox.com/</a></span>
   <a href="http://twitter.com/mor10/statuses/1003495851" style="font-size: 85%;"> about 15 hours ago</a>
</li>

That means we can use CSS to hide the content not in the while maintaining the visibility of the content that is. That requires some additions to the original CSS code:

#twitter_div ul li span {
	visibility: visible;
}
 
#twitter_div ul li span a {
	color: #D78E42;
	visibility: visible;
}
 
#twitter_div ul li a {
	visibility: hidden;
}

The first two single out the regular and link contents within the span specifically and set their visibility to visible. This is done because the last style sets the visibility of all anchors within list items under the twitter_div ID to hidden. So we are really working backwards – first hiding everything and then unhiding it in particular cases.

By adding these three style elements the time information will be hidden by the CSS while everything else shows up normally.

21 Comments

Trackbacks / Pingbacks

Leave a Reply