If you do not have background textures or images, a very "cheap" way to do it is to leave the entire line dotted, and "top" with the bottom of the stylus elements (name and number).
The advantage here 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 the 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 another example, this time giving extra space between the line and the background, and doing with dotted:
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 this case, I used 2px
in border-bottom
, and dotted
(which is the dotted) instead of dashed
of the first example. The space in the white parts is defined by padding
. Line position was set to top
.