If you don’t have textures or background images, a very "cheap" way to do it is to make the entire line dotted, and "cover" with the background of the end elements (the name and number).
The advantage in this case is the simplicity of the code:
li span { background: #fff }
li span+span { float: right }
li { position: relative }
li::before {
content: "";
display: block; position: absolute; z-index: -1;
top: 50%; width: 100%;
border-bottom: 1px dashed blue;
}
<h1>Índice</h1>
<ul>
<li><span>Introdução</span> <span>20</span></li>
<li><span>Metas</span> <span>20</span></li>
<li><span>Metodologia</span> <span>20</span></li>
</ul>
Basically what happens here is that the background of spans is painted white (obviously has to adapt to the color of the page), effectively hiding the traces.
The z-index
serves to ensure that the line is hidden by the bottom of the written part.
Styling a little better:
See one more example, this time giving an extra space between the line and the background, and doing with dotting:
li span { background: #fff; padding: 0 12px 0 0 }
li span+span { float: right; padding: 0 0 0 12px }
li { position: relative }
li::before {
content: "";
display: block; position: absolute; z-index: -1;
top: 67%; width: 100%;
border-bottom: 2px dotted #000;
}
<h1>Índice</h1>
<ul>
<li><span>Introdução</span> <span>20</span></li>
<li><span>Metas</span> <span>20</span></li>
<li><span>Metodologia</span> <span>20</span></li>
</ul>
In case I used 2px
in the border-bottom
, and dotted
(which is the dotted) in place of the dashed
of the first example. The space in the white parts is defined by the padding
. The position of the line was defined in top
.
Post your
html
, please– Kenny Rafael
Fountain:
http://stackoverflow.com/questions/1746491/how-to-draw-a-dotted-line-with-css
(Obs; replace dotted with dashed) Other Source:http://www.sovavsiti.cz/css/hr.html
– fsi
Very similar question to your http://stackoverflow.com/questions/3097851/fill-available-spaces-between-labels-with-dots-or-hyphens
– Marconi