StylizedWeb is a web design trends and tutorials blog, maintained by Ross Johnson who also runs a web design company and design blog.

Categories Archive

Popular Posts
Advertisement
Premium WordPress Themes, Theme Galaxy Basecamp
Najbolje ponuda IT poslova u Srbiji na itposlovi.info Advertise on Stylized Web

Simple show/hide with CSS

add to Save to Delicious Save to Stumble Save to Digg

As the title says here's one way to have simple show and hide effect using just CSS and avoid JavaScript. Idea is to use some tag inside the link (for example bold, or span or what ever) which will hide it's content in normal state and show in hover state. Mostly it's used for creating interesting menu effects with some additional images.

So here's basic example code, and a few ideas where you can also use this, for example i've used it Gunmetal free WordPress Theme, you can see the demo here.

 
<ol id="nav">
<li><a href="#"><b>»</b>Menu Item</a></li>
<li><a href="#"><b>»</b>Menu Item</a></li>
<li><a href="#"><b>»</b>Menu Item</a></li>
 
        ...
</ol>
 
#nav a {
	display: block;
	margin: 0;
	border: none;
}
#nav a b {
	float: right;
	display: none;
}
#nav a:hover {
	background: none;
	border: none;
	text-decoration: none;
}
#nav a:hover b {
	display: inline;
}
 

As bold tag you can use what ever you want like span or italic... The thing I'm seeing a lot these days is like descriptive headline on menu hover. The idea is the same, you place some tag into your link with empty span that has background image and absolute position and show it on hover. Here's example code.

 
<ul id="menu">
<li id="one"><a href="#"><span></span>Menu Item</a></li>
<li id="two"><a href="#"><span></span>Menu Item</a></li>
<li id="three"><a href="#"><span></span>Menu Item</a></li>
 
        ...
</ul>
 
#menu span {
	display: none;
	position: absolute;
}
 
#menu a:hover span {
	display: block;
}
 
#one span {
	background: transparent url(one.gif) no-repeat scroll 0 0;
	height: 11px;
	width: 111px;
	left: 35px;
	top: -20px;
...
}
 
#two span {
	background: transparent url(two.gif) no-repeat scroll 0 0;
	height: 222px;
	width: 22px;
	left: 15px;
	top: -10px;
...
}
 

And here are some ideas where you could also use this. For example to show that some link has target blank, so you give that link some id and do the same thing here for it with some descriptive icon. Have in mind that if you're using it inside some paragraph rest of text is going to move, so you could add padding on regular state and remove it on hover to fix it.

And here's another example, you can also use this to show a new menu like i am on every post title (those share icons) just i'm using a Javascript for it, didn't think if this when i was coding this ;) Have fun!

Have some feedback? Leave a comment



What do you think?





11 Responses so far

By Web Buckets
on November 5, 2008

Nice post, I must try this one for sure… keep it up buddy.

By mikael christiansen
on October 7, 2008

great article thanks

By Paul Sanderson
on September 12, 2008

in feb this year i started this http://www.wscoop.com

But I need your help….

I need links to web design and development, site , articles links…… anything you think of….

Please are you able to help me make this into a great resource for developers and designers.

By nikola
on September 11, 2008

nice trick ;-)

By Dann
on September 10, 2008

Looking good, i would just like to see more examples…

By Mike
on September 10, 2008

Yes, good idea!

By Zach
on September 10, 2008

pretty cool ! thanks dude

  1. Feb 25, 2009: lowest price teen health online www triumph com corona ca
  2. Oct 7, 2008: cheap homeowners insurance quotes
  3. Oct 6, 2008: no deposit required bingo games
  4. Oct 2, 2008: homepage templates