5

I am working on a restaurant website. The design calls for the typical dotted line infill between a menu item and the price. I have been scouring the net and messing with it for an hour or so now and can't seem to find any good ways to do this with only CSS. I found a couple of other solutions on here that work great if you have a solid color background, however on this site it uses a background image and those solutions wouldn't work.

Example: Menu style "...." - fill in with periods has a good solution, but it sets the background colors to white of the menu item and price to hide the dotted lines behind them, but the page I am building has a background image so any solid color backgrounds would look bad.

I have tried using all kinds of combinations of table-row/table-cell or any other type of CSS display attributes and width settings on the elements, but no dice.

Here is some fake sample markup:

<ul> 
    <li><span>Soup</span><span class="dots">&nbsp;</span><span>$2.99</span></li>
    <li><span>Ice cream</span><span class="dots">&nbsp;</span><span>$5.99</span></li>
    <li><span>Steak</span><span class="dots">&nbsp;</span><span>$20.99</span></li>
</ul>

I have been trying to get this to work by using the "dots" class element with a bottom border to fill in the gap, but nothing I try works. I also just put a bottom border on the LI element all the way across the bottom of each row, but that is not what the designer wants. I can only think of doing it in javascript as a last resort, but wanted to see if you guys had any ideas. Or, I can just use tables, but really wanted to avoid that as well.

Thanks!

Community
  • 1
  • 1
davesters81
  • 384
  • 3
  • 10

2 Answers2

4

I can be achieved by using definition lists (fiddle):

HTML:

<div id="wrap">
    <div class="inner">
        <dl>
            <dt>$2.89</dt>
            <dd><em>Lorem ipsum dolor sit amet </em></dd>
        </dl>
        <dl>
            <dt>$21.89</dt>
            <dd><em>In porta nisl id nisl varius ullamcorper</em></dd>
        </dl>
        <dl>
            <dt>$5.99</dt>
            <dd><em>Suspendisse augue mauris, mattis ac, commodo quis, lobortis vel, mauris. Etiam dolor neque, iaculis sit amet, tincidunt nec, elementum ut, lorem.</em></dd>
        </dl>
        <dl>
            <dt>$8.99</dt>
            <dd><em>Donec sed felis sit amet risus</em></dd>
        </dl>
        <dl>
            <dt>$11.50</dt>
            <dd><em>Maecenas ante. Suspendisse pharetra, metus in tempus egestas, purus ante pellentesque purus, at gravida metus elit nec nunc. Etiam ante ligula, porttitor et, euismod commodo, pulvinar id, pede. Curabitur et magna. Vestibulum leo nibh, viverra sed, imperdiet non,</em></dd>
        </dl>
        <dl>
            <dt>$5.99</dt>
            <dd><em>Etiam ante ligula,</em></dd>
        </dl>
        <dl>
            <dt>$5.99</dt>
            <dd><em>Fusce condimentum</em></dd>
        </dl>
        <dl>
            <dt>$7.55</dt>
            <dd><em>Morbi nibh velit, sodales eu</em></dd>
        </dl>
        <dl>
            <dt>$6.50</dt>
            <dd><em>Etiam ante ligula,</em></dd>
        </dl>
        <dl>
            <dt>$11.50</dt>
            <dd><em>Fusce condimentum</em></dd>
        </dl>
        <dl>
            <dt>$2.50</dt>
            <dd><em>Morbi nibh velit, sodales eu</em></dd>
        </dl>
        <dl>
            <dt>$21.50</dt>
            <dd><em>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In porta nisl id nisl varius ullamcorper.</em></dd>
        </dl>
    </div>
</div>

CSS:

* {margin:0;padding:0}
h1,h2{padding:10px 20px 0}
#wrap{
    width:500px;
    border:1px solid #eff2df;
    margin:20px 20px;
    background:#809900;
}
* html #wrap {width:502px;w\idth:500px;}
#wrap .inner{
    padding:20px 40px;
    border:1px solid #4c7300;
    position:relative;
    left:-2px;
    top:-2px;
    background:#eff2df;
    color:#4c7300;
    width:418px;
}
* html #wrap .inner{width:500px;w\idth:418px;}
#wrap dl{
    position:relative;
    width:100%;
    border-bottom:1px solid #eff2df;
}
#wrap dd{
    line-height:1.2em;
    position:relative;
    padding:0 5em 0 0;
    text-align:left;
    border-bottom:1px dotted #000;
    clear:both;
    margin:0 0 .4em 0;
    min-height:0;
}
* html #wrap dd{
    border:none;
    background: url(images/dotted-leader.gif) repeat-x left bottom;
    height:1%;
}
#wrap dt{
    background:#eff2df;
    padding:1px 0 1px 5px;
    color:#809900;
    position:absolute;
    bottom:0px;
    right:-1px;
    z-index:99;
}
#wrap dd em{
    margin:0 ;
    position:relative;
    top:.25em;
    padding:0 5px 0 0;
    background:#eff2df;
}

Reference Link

josliber
  • 43,891
  • 12
  • 98
  • 133
Ahsan Khurshid
  • 9,383
  • 1
  • 33
  • 51
  • @A.K Unfortunately this still makes use of solid background-color and thus is most likely not applicable to the OPs problem. – Christoph Jul 26 '12 at 09:17
  • @A.K - Thanks for the answers, but yea, the example uses background-colors and this just won't work for my particular situation. I am definitely keeping this saved for when I need it again and can use solid background-colors. – davesters81 Jul 26 '12 at 19:24
4

I would go with something like this:

Example Fiddle

It uses the dotted border on the .dots element and shifts it some pixels to the top.

ul li {
    display:table-row;
    width:15em;
}
ul li span{
  display:table-cell;   
}
.dots{
    min-width:10em;
    position:relative;
    bottom:4px;
 border-bottom:1px dotted #777;   
}

Nice sideeffect - you dont need to float the elements. However this solution uses display:table-cell so this won't work in old IEs (<IE8).
Depending on the background, you could use the li-border solution and replace the solid colors on the span-elements with the background-image itself.

Christoph
  • 50,121
  • 21
  • 99
  • 128
  • `ul li span { float:left; position:relative;top:5px; background-color:white;}` Which is it? Float or positioning? – Kyle Jul 26 '12 at 08:14
  • In your fiddle you have both, I copy+pasted from the fiddle :) – Kyle Jul 26 '12 at 09:05
  • @Kyle yah, i know, but look again, i modified it a bit to get rid of the unnecessary stuff: http://jsfiddle.net/poikl/atXgr/ – Christoph Jul 26 '12 at 09:15
  • Ok, I took your idea so far and messed with it some more. It was really close to what I was looking for. Here is a new fiddle: http://jsfiddle.net/hVnXx/. Basically, I had to break them out into separate "tables" and have an encompassing CSS table. Then, I had to use non-breaking spaces in between the words to stop it from wrapping them. Then set the dots width to 100%. It works for me in Chrome, but is a pretty messy way to do it. Any ideas to clean it up a little? Seems like I may as well use tables with this solution. Also works in FF and IE9. Can't test in <=IE8 atm. – davesters81 Jul 26 '12 at 19:30
  • 1
    well, you can just use `white-space:nowrap` to avoid the nbs. Also, I find it more appealing if the border lines up with the words, so i added a position and `bottom`. But i guess that's a matter of taste - your designer says what's right and wrong. http://jsfiddle.net/hVnXx/1/ it works in IE8 for me, but IE7 breaks :( – Christoph Jul 26 '12 at 20:03
  • @Christoph - Awesome man! I didn't know about white-space: nowrap. I did add the position and bottom to my site already to align them up, just not in my example. I was only planning on testing in IE8, so that is good that it works. In IE7, I may just put a border along entire bottom of the row and call it done. Thanks again. – davesters81 Jul 26 '12 at 23:08
  • @dav just fyi, you can test ie8 and 7 in your ie9. You can switch browser- and documentmode in the developer tools. Have a nice day:) – Christoph Jul 27 '12 at 06:18