This is a quick CSS tutorial to show you how to create a menu list using either the CSS border style or a background image. The trick is to apply a bottom border to the <li>
element, then use the absolute position property to shift the nested elements down to cover the border. It is very flexible — you can easily change the layout by altering the border or background image. It even works when the browser’s font size is being scaled (increased or decreased).
Take a look at the HTML code and the diagram. They will help you understand how the CSS work.
<ul>
<li><strong>CSS Design</strong> <em>250<sup>95</sup></em></li>
</ul>
The key points are:
<li>
element to position:relative
and apply a bottom border style.position:absolute
with negative bottom
value to shift the <strong>
and <em>
element below the border..menu {
width: 500px;
list-style: none;
margin: 0 0 2em;
padding: 0;
font: 150%/100% Arial, Helvetica, sans-serif;
}
.menu li {
clear: both;
margin: 0;
padding: 0 0 1.8em 0;
position: relative;
border-bottom: dotted 2px #999;
}
.menu strong {
background: #fff;
padding: 0 10px 0 0;
font-weight: normal;
position: absolute;
bottom: -.3em;
left: 0;
}
.menu em {
background: #fff;
padding: 0 0 0 5px;
font: 110%/100% Georgia, "Times New Roman", Times, serif;
position: absolute;
bottom: -.2em;
right: 0;
}
.menu sup {
font-size: 60%;
color: #666;
margin-left: 3px;
}
You can easily change the style by editing the CSS border
and padding
for the <li>
element.
li {
border-bottom: dashed 1px #000;
padding: 0 0 2.3em 0;
}
You can also use a background image.
li {
background: url(images/circle.gif) repeat-x left bottom;
}
If you are still using the old and buggie IE6 browser, you may notice the layout doesn’t render properly. To fix the issue, simply add the clearfix trick to the <li>
element.
/* clearfix */
.menu li:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.menu li {display: inline-block;}
/* Hides from IE-mac \*/
* html .menu li {height: 1%;}
.menu li {display: block;}
/* End hide from IE-mac */
Righteous_Trespasser
That’s incredibly clever – thanks for that neat little trick.
Manuel
seems like there is no way around to learn CSS ;)
Marco
Clean, sweet, useful and well-explained. That’s what we expect and what we got – Well done Nick, thanks for sharing :) .
Oliver
Hey Nick!
I’ve used kind of the same trick a few month ago on a friends restaurants website.
Get a bit trickier, when it comes to two-lined List-Elements.
You can check out what I mean over at http://www.il-bistrorante.de
See the Source-Code for my solution…
All the best from bonn, germany,
Oliver
Manuel
(The restaurant is in Bonn, greetings from Cologne!;)
Fred Soler
Very interesting. Will see it later.
Greetings from France (Marseille, la famille !)
THEODIN
you’r attention to detail is outstanding, much appreciated!
Chris Praley
Neat trick! I will definitely be trying that out sometime soon.
Chris Hunt
Under section 5, if you’re only serving up the clearfix code for IE6, why bother with the
menu li:after
rule that IE6 won’t understand and other browsers (presumably) won’t need?In fact, all you need to do to make it work in IE6 (I don’t know what this does on IE-Mac, but does anybody really use that browser any more?) is this:
.menu li {display: inline-block;}
.menu li {display: block;}
That code should do nothing at all, but it clears the display bug that otherwise messes up IE6’s display of your clever code. God (and Bill) alone knows why.
Designer
thanks for the tut
Ryan S
Very nice! As always well explained tutorials.
Timothy
Very nice end product!
Brad Edwards
I was just describing to a client how this would not work in the web world. I enjoy eating my words. Excellent tutorial!
Henning
Well … just one remark on this otherwise great tut.
Tables are not dead.
Of course not as flixible as this one.
Just wanted to say there is still use for tables in displaying … tables :-)
Henning
Danny OUtlaw
great idea and tutorial as always!
Jason Evers
A weakness of this technique would be difficulty putting this on a page with an organic or pattern background because of the background color needed to offset the dotted line.
DKumar M.
Very Nice and Easy Tutorial Nick…. Thanks For sharing such a useful stuff !!
DKumar M.
lefiath
Can you explain why ur using :after on IE, when it doesnt understand it at all?
Josh Drake
Nice, simple effect. A bit of a beginner’s tutorial, but hey – they need tutorials too! Thanks!
Kit
On my IE7 browser, some of the numbers were being cut off at the bottom? They display find on Firefox and Chrome though, nice tutorial! Thanks :)
gareth hunt
You can achieve the same effect without absolute positioning and without setting padding to flesh out the list item.
Set the strong and em elements (which I think are used slightly inappropriately in your example) to position:relative and float the former left and the latter right. You can still shift elements using top / bottom / left / right and position:relative but there is the benefit, in this situation, that the “space” taken up by the elements before they are offset is maintained and so the list item will be equal in height to the height of the largest element. This negates the need to force the list item to have some kind of height that is divorced from the height of its child elements.
Since you have to float both child elements you need to apply the :after clearfix to the menu list items. You can achieve the same thing in IE just by setting a width, such as 100% in this example, because you only need to trigger hasLayout.
Then any additional inter list item spacing can be controlled with margins.
gareth hunt
@ Kit
That’s because this tutorial sets the line-height of the em element at 100%. Change the line height to something like 1.2em and your numbers will not be cut off in IE.
Samuel
Great example…..thanks!
Kim
Weirdly enough, I needed exactly this today. Thanks a bunch for this tut. =D
Sveatoslav
Very nice and great ideat,
Thank you ^:)^
Amu
Ha! Been looking for this like years ago, thanks!
kruz
Amazing! I can not imagine how. I want to use.
saki
thank!
Matt Wood
Thanks for the tutorial, Nick.
However, I agree with the commenter gareth hunt, that, in terms of semantics, the strong and em tags are used incorrectly. The same can be said for the sup tag.
Remember folks, we’re trying to write better code every day, and our tags should be describing the type of information, not how they should displayed (for example, just because you want the $.00 to be raised, it’s not a legitimate superscript, such as a footnote or mathematical equation.)
Si
if you want to keep semantics just swap the tags for spans and set a class. It adds codes but you are left with semantically correct code. good tip tho.
henry
it’s a good CSS tutorial. I do the same effect without absolute positioning.
Gary
Nice write-up on a cheeky little technique. I like it :)
Johan Lorentzon
Nice one! Will use for my next restaurant clients.
Brady J. Frey
I did something similar for the menu on my Kamalaspa site, though a background image to recreate the dots and get around IE 6’s crash on dotted border:
http://www.kamalaspa.com/spa-salon/
But I had to use Firefox specfic hacks (eek, I know) because the right side element was always 10 pixels up… thanks for tutorial, I’ll try and rework this old guy to be more universal on your method:)
izzat aziz
i may use it for my portfolio, to display skill level stuff..
nice tutorial though, thanks.
Thiago
muito bom!!!
adorei o post :)
TiS
@matt and garret:
As of the sup tag… In some languages is common to write smaller changes (eg cents) in superscript. Though, it’s semantically correct.
Also, for strong and em – why it’s semantically incorrect? Those parts have semantic value – the name of the dish/skill/etc and the price/time/level (something to emphasise). I think using Span tags will be worse, because it doesn’t semantically distinct two pieces of information in list entry – target and the price.
BTW, nice tutorial. Thanks.
RaphaelDDL
Great tutorial!
Even with IE6 trick, it fails because of the positioning. This one ( https://webdesignerwall.mystagingwebsite.com/demo/menu/menu-list-ie6-version.html ) opened in IE6 shows the big values with the bottom cut. So, in Spicy Hot Roll seems 20.99 and not 29.99
If we add conditional comments ( if lt IE7 etc) and reduce the em might work, don’t?
I’ll try it and tell you later.
See you :)
Regards
RaphaelDDL.com
Elizabeth K. Barone
I was just working on a menu and was trying to come up with a better way to display it. Thanks so much for this!
WPCult
Thanks for a great tutorial!
Max Weir
Great tutorial, its something that can be used for multiple purposes and is very simple to integrate. Raphael raised a good point regarding IE6’s issue with the prices, hopefully there will be a fix posted.
Thanks.
Patrick
thanks for the great fix for an age old problem for menu. You really helped me out. Danke!!
tekin
perfect css tutorial !
ralph
Thanks a lot for the tutorial, very useful. Best from Ralph http://www.deprowebs.com
printers in brisbane
this is good…very good!
Alex Vladoiu
Nice trick! Thank you!
CMHB
Thanks for the tutorial. Very helpful. I am sure I can think of ways to implement this method. Thanks again.
Dale Sande
While this solution is well written, I too ran into major issues with legacy browsers. To simplify the HTML, I choose to use the Definition Lists approach (DL, DT, DD) and a background image. The process is the same, lay in a background image and cover the desired areas with a color background.
Check out http://www.madisonmac.com/services_and_support/software-support/. The solution is solid and even worked in IE 5.5. Everything else goes to hell, but this works ;) If anyone wants more of an explanation, feel free to email me.
Jan
Very useful! Thank you, Nick!
Jonny Haynes
Nice tutorial. Was looking into this myself for a friend.
Issam
Very nice website… your are the best…
Organicum
There’s always a hater, (Dale Sande) Why are you still testing for IE 5.5 .. ?? are you kidding me… anyway… I love the extra fee for IE 6 support … LOL.. however 34% of the world unfortunately is still using this browser as far as IE 5.5 , 0% of the world is using this browser….
http://www.thecounter.com/stats/2009/February/browser.php
qishi87
woww..great blog! ur tutorial so useful..thx :)
gareth hunt
@Dale Sande – definition lists are not appropriate to mark up this information. The point of the tutorial was also to avoid using background images were possible. I’d also argue that you are wasting your time worrying about IE5 or other legacy browsers that make up <0.1% of the market and continue to shrink. However, I have already suggested in an earlier comment that there is a preferred method that doesn’t use absolute positioning.
@RaphaelDDL & @Max Weir – see comment 22
@TiS – em and strong can’t be used for presentational reasons or just to give you a hook to apply some css for positioning. This is simply a list and I don’t believe you can justify using these elements. The service / dish is not “important” and nor should the cost be “emphasised”. It is using these elements incorrectly. If you want to add appropriate semantics then you could use microformats with span tags. A further problem with this demo is that the cost is not represented with a currency (which is an actual problem because their is a failure to indicate the nature of the number) and the decimal place is missing.
Rob Wallace
I couldn’t grasp the demo image. However the areas of economy of code, blowing out IE5 and the approach is great. But, does this cdd work the same in FireFox, I wonder how many pros test in FireFox.
Dupe
You are my hero, your site is amazing! Your tutorials are so awesome!
Ralph
A nice idea to publish a price list on a website. Thank you for this tutorial. Ralph
bienB
Interesante técnica… gracias por compartirla
themisfit
Great tutorial, this will come in handy.
Dale Sande
Ok, I feel I need to clear my name here. I have taken a lot of flame here because I have posted an alternative solution that takes less IE counter actions. I do realize that this exercise was an attempt to solve this UI issue without images, but I also realize that there is a lot of additional effort needed in order to make this example work across different browsers.
I do not understand why using a Definition List in this example is such a bastardization of the HTML tag? I found this a simpler solution as in repeated execution I do not have to insert the additional tags?
Then the apparent bane of my post, IE5.5 support. I don’t know why this comment was taken with such harsh criticism. I simply stated that with the idea I proposed, without additional effort it also happened to work with IE5.5. If anyone had taken the opportunity to look at the site I posted in IE5.5, you will see that everything else pretty much goes to hell, but this one thing still works. I am a progressive developer and I maintain a clear sight on the horizon. I am not a IE zombie or a developer that unrealistically holds onto the past. So please, lay off.
@Organicum – “I love the extra fee for IE 6 support … LOL” What is that supposed to mean? Do I not use enough dramatic drop shadows and that is why you hate me?
John Dawson Photography
Good example – I agree that IE6 is still important since some clients still worry about it and check it. I find that when I ignore IE6 during coding, it comes back to bite me so I try my best to make sure my stuff renders in all major browsers.
Miss Blossom
I’m going to try this one for my next site. Actually I may even have one I can use it for now. How exciting! It would work really well for online beauty salon treatment menus and pricelists.
Peter
Great tutorial, I used something similar a while back on a project of mine (example: http://www.soccerkits.com/Barcelona-Azzure-White-p24.html)
The idea for it I got after looking at the BBC website, they used something similar on one of their lists of features.
Harris
Thanks for the tip. I may be working on a website for a yogurt place and this would be great for the menu.
gaijun
Thanks for you.This is I want.
Backbone
you know? i really love the way you provide tutorials on your site. Very very friendly and spoon feeding (well, as what newbies always wanted, feed them :) )…More power and God bless!
Joseph
nice one!
zeta
Thanks for this tutorial.
I’ve lots to do yet….
ciao!
tin
I am a newbie.Your tutorials really helped me a lot.Thank you!!!!!
Web Design Studio
This is a great quick tutorial that is very useful we work on a lot of restaurants and are implementing menus like this in to the text.
caina
Great! I had never seen anythink like this before
ótimo tutorial :)
beejamin
I would agree with Dale Sande that a definition list is the right way to go here – the menu itself is a list of items that need clarification (in terms of price), each list item is a term, and the price is its definition (in dollars). Other than marking up a page in a dictionary, I can’t think of a better application for DLs.
I’m sure it’s possible to make this imageless with DL’s too, using a couple of spans (one lining the DT, and one around the cents).
The SUP for cents is especially wrong, semantically. I’d almost be cheeky and use SMALL instead (not exactly correct to the spec, but it makes more sense to me).
jon
nice articles
more menu design visit. http://www.csshook.com/menudesign
Anne
Hi That’s awesome :)
nishant
Quite helpful. li tag is probably one of the most useful tags in html
John Pash
I really like this technique. I’ve come up with a similar solution in order to simluate the “legend” tag for display purposes outside of a form. Of course, I could just use “legend”, but it doesn’t validate.
Mat
A good tutorial, But John I would never consider using CSS tricks to simulate already existing HTML tags instead I would use the CSS to style and modify the tag to fit with the design.
Jobs
I like the way the menu was created. It was quite hard for me to find out how the dotted lines effect were created in a menu prior to this way. Thanks!
inregistrare domenii
thank you and keep up the good work!
web design gold coast
Brilliant! Thank you so much for sharing.
Keith D
Looks good
thganks for showing how in such a well presented fashion.
Keith D
Mary
Thanks for this. Works beautifully!
francisa
helpful. thanks!
Matthew Bruce
Very helpful tutorial!
Elizabeth K. Barone
I added a description beneath each li using a p tag. It worked great for me in FF, IE 7, Safari, Opera, but it broke on my client’s machine and can be duplicated when previewed in TopStyle. I’m working on a solution now, but I think I may end up just using dl tags to mimic what you’ve got. (My client needs each menu item to have a description.)
Anyone else running into this problem, by any chance? I wish I knew what the problem was. I’m thinking that it might just be a machine problem, since it looks fine on some machines but breaks on others.
ƒЯєє ςtγlє
oh this I have used…very good for pure css menu :)
cennet
Thanks What’s the problem here? Google could bury the meager profit number from even the biggest media conglomerates.
cennetevi
these are awesome!
thanks for putting in the effort to get this list together
cennetevi
Thank =)=)=) you http://www.cennet.gen.tr
cennetevi
Thank =)=)=) you http://www.cennet.gen.tr webdesignerwall Thanks
kpss
http://kpssdestek.blogspot.com/ good website
WAMPvn
these are awesome!
thanks for putting in the effort to get this list together, now i can fix my page
jatropha, jatropha seed
Very helpful tutorial!
cennet
:):)::))
Smashing Themes
Awesomeness :)
cennet
yha :):) Dont!
murat
islamsevdasi.com
LazyAndroid
Wouldn’t it be easyer and more semantic to use a definition list here?
KJL
I learned a lot here.
Johannes Booy
Agree that this would be a lot easier and more semantically accurate if you were using a definition list.
bagsin
these are awesome!
thanks for putting in the effort to get this list together
Cyrus
Great , CSS: Menu List Design
Great article. CSS saved web design
Cyrus
Visit http://www.psdtoxhtmlcoder.com
Itransition
I can note that using the relative value (em) to control the padding space can be the best way to prevent incorrect reflection of elements in browsers. But is it reasonable to use image as a border-background? I usually apply separately images as the visual borders and borders of the elements as separate elements. I can’t imaging using images in border attributes.
Mike
Agree that this would be a lot easier and more semantically accurate if you were using a definition list. Thanks
Fisker
good!
Andrew
We’ve been using the css li method to create menus on our pub website for a while now but could really do with some fresh ideas to bring the design to life. Thanks for the great tips.
kai
That’s cool.
ximumu
it is cool.thank you !
72color
4. Use Image as Border (see final demos)
very easy
Mipovia
thanks! it is exactly what I have been looking for <3
Software services
Great stuff thank you for sharing.
vincentdresses
喜欢你们的设计与技术,常来看看
shaojie
thank you!
veilig2000
How could you make something like this work in a nested ul list?
Web Design
very cool!! THANKS!
Hemi
I really loved the menu design of this page (Home, About, Jobs) and the mouse over. Can you send me the full CSS code for that? I would really appreciate it.
Thanks,
Hemi
Mr wu
Great feel with you are design Thanks for share
apple
fantastic and many cool
templateswork
very good and clean tutorial. thaks
Melvins
CSS has changed the whole scenario of web designing. The example and code shown here is really very useful to all the web designer.
Los Angeles Web Design
DrBenway
Fantascic blog and design! Thanks.
El garch
Thank you for this post, you’re doing a good job keep postiong plz |:-D
Shahid Saifi
Good use of positioning. NICE!
mr.deng
很强啊,虽然这些样式我也会,但是没想到还可以这样用,学习了,支持,顶!
Juno Mindoes
There’s no doubt that the white iPhone 4 has a much better camera than the iPhone 3G and the iPhone 3Gs, and the new HDR functionality makes it even easier to get good results during hard lighting conditions.
Henry Peise
With the most fashion designer, White iphone 4 Conversion Kit can be your new autumn/winter fashion piece for your favorite iphone 4. Why not make a little change for your iphone 4.
mikwillson
That is to be expected in a long-term, high-risk project like ours. So, we turned to the blogging community for help – and got it! We have published our problems, and the community responded with results!cheap ugg boots
mikwillson
That is to be expected in a long-term,ike ours. So, we turned to the blogging community for help – and got it! We have published our problems, and the community responded with results!cheap ugg boots
altın çilek
I always follow your site thank you
hcg damla
Thank you for this post, you’re doing a good job keep postiong plz
How To Put On A Condom | How To Get Taller
Easy and flexible tutorial that I can follow with just minute confusion. Thanks.
How To Get Taller | How To Put On A Condom
It is a quick CSS tutorial but showed a lot of good stuff.
panax clavis
I always follow your site thank you
hcg damla
I always follow your site thank you….
alex
Great post. Thanks
ORJİNAL PEMBE MASKE
good job congraculations
Andezit Taşı
nice share,thanks:))
pembe maske
I always follow your site thank you….
arnold ecubin
nice 1 good job
Moliva
I always follow your site thank you
sfg
fsdf
e-webtemplates
Nice explanation with an image .Great Thanks for it.
bitkisel
Thank you This is organized very nicely
Creative Hero
Nice Post….. thanks….. :)
Zahid
great ,
kamlesh
i want to saw more art work wallpaper
weblistings Inc
I get what i search, thanks
c
found this 9 years later, this is the best way to make simple css dot leaders, saved my day thanx !!