How to Create a Beautiful Dropdown Blogroll Without JavaScript
215
Dropdown menus are a great way of including a long list of links without cluttering up your page. The issue though is that they can be hard to style, but look quite ugly if you don’t. There isn’t a lot of flexibility with HTML’s <select> tags.
Well, why not do it with plain HTML instead?
In this post, I’m going to walk you through how I’ve set up the blogroll in our upcoming redesign. Load up the example page to see how our final product will look.
By using CSS only, you avoid slowing down your page while visitor’s download an extra script. On top of that, you don’t need to worry about user’s having JavaScript disabled.
The only caveat is that this method won’t work on IE6 (At least, not without doing some tweaking specifically for IE6 users). But as you’ll see at the end, this could be much more accessible than if you used JavaScript.
1 – Create the Image
The HTML we use later won’t have any traditional <select> codes, so by itself, it’s not going to look anything like a dropdown. We need to take care of that ourselves.
The image you create can look any way you want it to, but since this is a dropdown menu, a little arrow pointing downwards is your best option for easy usability.
The size of the image is also important. It can be any height you like, but the width will be the width of your dropdown.
This is what I have ended up with:
2 – Set up The HTML
Now we set up our HTML. This is where the power of this method comes into play, you are using simple HTML that you can later style in any way that suits you.
We need an unordered list to store all of the links. We will then precede that with a paragraph (or a ‘h’ tag if you prefer) to title it, and finally, we wrap the whole thing in a div.
Your final markup should look like this:
<div class="blogroll"> <p>Blogroll</p> <ul> <li><a href="http://www.site.com/">Example Site</a></li> <li><a href="http://www.site.com/">Example Site</a></li> <li><a href="http://www.site.com/">Example Site</a></li> </ul> </div> |
Of course, you may want to use WordPress’ wp_list_bookmarks(); function to use the built in linkroll instead. Either will work.
3 – Style The Menu
For now we are going to forget about the dropdown functionality, and simply design the dropdown as it will be when someone’s mouse is over the image.
The first step is to replace the paragraph text with the image we created earlier.
.blogroll p { background:url(pbd-css-blogroll-rollover-img.png) 0 0 no-repeat; width:274px; height:21px; text-indent:-9999px; } |
As you can see, we apply the image as the background first. We then set the dimensions of the paragraph to be the same as those of the image, and finally, we use text-indent to hide the “Blogroll” text from our HTML.
Next we have to style the list. Because our HTML is so simple, you will have no problem styling this any way you like. For instance, you can set a background on the dropdown, or add other types of HTML (Like images).
All I am going to do here is set up a plain list of all the links, and change the background color of each link on rollover. The CSS I’ve used is as follows: (Feel free to adapt for your own site)
.blogroll ul { width:272px; background:#214868; border:1px solid #48758d; border-width:0 1px 1px 1px; padding:0; list-style:none; } blogroll ul a:link, .blogroll ul a:visited { display:block; width:252px; padding:2px 10px 2px 10px; text-decoration:none; color:#93b8d3; font-weight:normal; } .blogroll ul a:hover, .blogroll ul a:active {background:#366386;} |
The final thing to note is that we currently have a space between our image and our drop-down. We can remove this by amending our CSS:
.blogroll p, .blogroll ul {margin:0;} |

4 – Create the Dropdown
Now it’s time to create the dropdown. The trick is very straightforward – We are going to use the div to hide everything other than the image until the user’s mouse is over it.
To start with, let’s hide everything other than our image.
.blogroll { width:274px; height:21px; overflow:hidden; } |
And then we just use the :hover pseudo-class to allow the excess to be shown when the user scrolls over the image.
.blogroll:hover {overflow:visible;} |
5 – Fix The Issue of Pushing Content Down
We are almost done. The rollover works, but when the menu appears, it pushes all the content beneath it down. This jumping content looks poor.
We are going to fix that by using absolute positioning to put the dropdown menu above all the other content. That way, there will be no jumping when the menu comes into play.
The first step is to amend the blogroll div to be positioned relatively (So that the dropdown’s absolute positioning can be anchored by this div).
.blogroll {position:relative;} |
Now use CSS to position the menu right under the image.
.blogroll ul { position:absolute; left:0; top:21px; } |
6 – Issues with IE 6
This menu won’t work with IE6 because it does not support :hover on anything other than links.
There are some workarounds to this using JavaScript. For instance, you could use conditional comments so that IE6 users use JavaScript to see the menu. Or you could try to teach IE6 to use :hover properly.
But given that the whole point of this was to avoid extra scripts, the best solution might be to simply hide the menu altogether. It’s not crucial content and if as few of your reader’s use IE6 as this site’s does, your best bet may just be this:
.blogroll {display:none;} html>body .blogroll {display:block;} |
Conclusion
You can see the full code in working order on the example page. I love the control you have over it and the fact that you aren’t using any scripts so load times are as fast as they can be.
Not supporting IE6 is a drawback, but not as serious a one as it could be. For instance, 14% of this site’s visitors have JavaScript disabled, but only 2.6% are using IE6. That means that 5 times more people have a working blogroll than if I had used a JavaScript solution.
What do you think? Will you be using a CSS-only menu on your blog at some point, or do JavaScript effects still hold sway over you?
Enjoy this post? You should follow me on Twitter!


Comments discussion on "How to Create a Beautiful Dropdown Blogroll Without JavaScript"
Pingback: Create a Beautiful Dropdown Blogroll Without Javascript | Design Marketing Advertising Free Tips
Pingback: Rocking Links – KW 31 | Webdesign | News | Rock 'n' Roll
Pingback: Como crear un dropdown menu de tu blogroll sin javascript
Pingback: 3 tecnicas para hacer tu sidebar WordPress unica | Kernel Web
Pingback: 30+ New Useful WordPress Tricks & Hacks | Wordpress
Pingback: 30+ New Useful WordPress Tricks & Hacks - Programming Blog
Pingback: PT Ubuntu Blog » 30个+ WordPress的新的实用插件技巧
Pingback: 30+ New Useful WordPress Tricks & Hacks « test
Pingback: 30 Nuevos Hacks y trucos para WP
Pingback: 10 Useful WordPress Tricks « Professional Free Wordpress Skins
Pingback: 30+ New Useful WordPress Tricks & Hacks : CRshare.com
Pingback: 30+ New Useful WordPress Tricks & Hacks | Internet Marketing Tips and Strategy To Make Money Online
Pingback: 30+ New Useful WordPress Tricks & Hacks | Fulldigi
Pingback: 30+ New Useful WordPress Tricks & Hacks | Viikii - Rapidshare Megaupload Direct Links Blog
Pingback: 30+ New Useful WordPress Tricks & Hacks - Download 30+ New Useful WordPress Tricks & Hacks - Links download 30+ New Useful WordPress Tricks & Hacks | PAGE2BOOk.COM
Pingback: 30+ New Useful WordPress Tricks & Hacks | X Design Blog
Pingback: 30+ New Useful WordPress Tricks & Hacks | Mac Bargains
Pingback: 30+ Tips&Plugin per Wordpress | GeekTwice
Pingback: 30+ New Useful WordPress Tricks & Hacks | WEBDESIGN FAN
Pingback: 30 y más, Nuevos trucos útiles WordPress | rperey
Pingback: Recursos para la Creación de un Theme WordPress | Area Photoshop
Pingback: Unlimited New Useful Wordpress Tips,Tricks & Hacks - Themeflash : One Stop For All Your Web Resources
Pingback: 30+ New Useful WordPress Tricks & Hacks | MEN blog . net
Pingback: 30+ New Useful WordPress Tricks & Hacks | MEN blog . net
Pingback: 30+ New Useful WordPress Tricks & Hacks « Photoshop.vn – Your Design Resource
Pingback: 30+ New Useful WordPress Tricks & Hacks | Lunch Time Laugh
Pingback: 30+ New Useful WordPress Tricks & Hacks | My Tech way
Pingback: 30 Bad Practices of Web Designers | Pro Blog Design
Pingback: Blog – Velagapati - 300+ Resources to Help You Become a WordPress Expert
Pingback: CSSハックマニア その1 | Nutspress
Pingback: 30+ New Useful WordPress Tricks & Hacks | Digitalize Blog
Pingback: 300+ Resources to Help You Become a WordPress Expert « eBSPAD
Pingback: 30+ New Useful WordPress Tricks & Hacks | Online live
Pingback: 300+ Resources to Help You Become a WordPress Expert | LeVoltz - iPhone Games, Engineering Projects, Wordpress Themes
Pingback: 50 Fresh CSS Techniques, Tutorials and Resources - Noupe
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources | Graphic Design Pro
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources « Graphic Art Source
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources | SeanBurdick
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources | qface & sowmo sky
Pingback: CSS Lovers, Web 2.0 Directory and Resources » Blog Archive » 50+ Fresh and Awesome CSS Techniques, Tutorials and Resources
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources | Theme Center
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources | Gacik Design Blog
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources | Design-Tut+
Pingback: Extensii utile pentru WORDPRESS | iClip - Think simple !
Pingback: 25+ Tutoriais CSS e jQuery, Recursos e Técnicas | TimeDSG
Pingback: 37 Cool Wordpress Hacks And Tutorials You Should Try |
Pingback: 37 Cool Wordpress Hacks And Tutorials You Should Try | Afif Fattouh - Web Specialist
Pingback: 37个Wordpress经典教程 « Booto'Blog
Pingback: 37个Wordpress经典教程 | 尚7科技
Pingback: 37个Wordpress经典教程 | 第七日
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources « Oviyas Blog
Pingback: 37 个Wordpress经典教程 « 十年
Pingback: 30 Pure CSS Alternatives to Javascript - Speckyboy Design Magazine
Pingback: 30 Pure CSS Alternatives to Javascript | DesignerLinks | Home to Web design news, jQuery Tutorials, CSS tutorials, Web Designing tutorials, JavaScript tutorials and more!
Pingback: 30 Pure CSS Alternatives to Javascript « Royale9designs a web and graphic design studio – Web Design Services, Web Development Services, SEO Services, Graphic design services, kolhapur, India
Pingback: 30 Pure CSS Alternatives to Javascript « Film and entertainment
Pingback: Wordpress Plugins, Wordpress Tutorials
Pingback: Wordpress: Dropdown mini-loop and blogroll « Scar.form « this.isn't.it.
Pingback: 30+ New Useful WordPress Tricks & Hacks | Tut7
Pingback: 37个Wordpress经典教程[转] « GoTop’s Blog
Pingback: Top Css Techniques with Samples | Ulancer
Pingback: The Power Of CSS:40 Totally Pure CSS Solutions Without Javascript | DesignBeep
Pingback: 37个WordPress经典教程
Pingback: The Power Of CSS:40 Totally Pure CSS Effects With Demos | Afif Fattouh - Web Specialist
Pingback: 30 Bad Web Design Practices
Pingback: 30 New Useful WordPress Tricks and Hacks - E-Learning | Ecoz Labs
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources
Pingback: 37 Wordpress Hacks / Tutorials from Designbeep | Pixel Deep
Pingback: 50+ Most Wanted CSS Techniques, Tutorials and Resources | Webwibe
Pingback: cgiant » Blog Archive » How to Create a Beautiful Dropdown Blogroll Without JavaScript
Pingback: Wordpress教程大全 | 得失之间,谈笑自若
Pingback: New Useful WordPress Tricks & Hacks | How It Easy (HIE) Computing community
Pingback: Yasin Değirmenci Kişisel Blog'u » Blog Archive » 37 Cool WordPress Hacks And Tutorials You Should Try
Pingback: Around 50 Fresh Great CSS Techniques - Tuts and Resources
Pingback: Kill your Time - 300+ Resources to Help You Become a WordPress Expert
Pingback: 30+ New Useful WordPress Tricks & Hacks | Bhupal Magar Dot Com
Pingback: 40 Useful CSS Tutorials, Techniques and Resources | Free and Useful Online Resources for Designers and Developers
Pingback: 40 Useful layout by CSS Tutorials including Techniques And Resources « 68Design – (68ds.com) Creative Design Transmitter
Pingback: 50 + novas técnicas CSS, Tutoriais e Recursos | SajaNews - Informação a um Click!
Pingback: 50 FRESH CSS Techniques and Tutorials from Noupe - Internal Support
Pingback: Tutoriales Diseño y Programacion Web | Achocoza
Pingback: Designers Know Your Code: Web Design Tutorials
Pingback: Sacima鲨鳍马工作室 » Blog Archive » Designers Know Your Code: Web Design Tutorials
Pingback: 7Maximes-News For Designers & Web Developers
Pingback: Designers Know Your Code: Web Design Tutorials | Mirdita
Pingback: Designers Know Your Code: Web Design Tutorials | VapvaruN | Wp Experts
Pingback: Web Designer Blog » Blog Archive » The Power Of CSS: Pure CSS Effects With Demos-No Javascript - All About Graphics and web designing
Pingback: 50+ Fresh CSS Techniques, Tutorials and Resources | Designer Malaysia
Pingback: Blogging Well » Blog Archive » 30 Pure CSS Alternatives to Javascript
Pingback: Blogging Well » Blog Archive » 32 Javascript Alternatives with Pure CSS – Updated
Pingback: 30 Effective Alternatives of CSS to Javascript | DesDevWeb
Pingback: The Power Of CSS:40 Totally Pure CSS Effects With Demos-No Javascript : Web design
Pingback: 40 Eventual Throng of CSS3 Techniques and Tutorials | Dzinepress
Pingback: 10 Most Useful CSS Tutorial for Web Designers | Mystrious
Pingback: 37 Cool WordPress Hacks And Tutorials You Should Try : Web design
Pingback: 30 + Cool WordPress Hacks And Tutorials You Should Try | 1webdesigner.net
Pingback: 15 Best CSS Tutorials to Enhance Web Design Skills | Sky Tech Geek
Pingback: 32 Javascript Alternatives with Pure CSS - Updated - Speckyboy Design Magazine
Pingback: 300+ Resources to Help You Become a WordPress Expert | Mr.N design
Pingback: 300多种可帮你成为WordPress专家的资源 | 就赖猫
Pingback: All Design » Designers Know Your Code: Web Design Tutorials