I'd like to display some text then a dotted line then some more text on the same line on a HTML page e.g.
Name: .......................................................... (Engineer)
I want the "Name" to be left justified against the left border and "Engineer" to be right justified against the right border and then the browser to be able to fill the gap between the two with repeating dots.
I've tried a good few different ways to get this to work using CSS and HTML but can't quite get it right. I don't want to have to specify the width (actual or percentage) of each component so that the solution is re-usable with words of different lengths e.g. the same solution would work with:
Factory Location: .................................... (Not invoice address)
Hope this question makes sense, any advice appreciated, thanks.
To add an ellipsis in the HTML <span> element having the CSS overflow property set to “hidden”, you need to add the text-overflow property. Use its “ellipsis” value, which will add dots at the end of the content within the <span>.
you can just adjust the size with the background-size property, the proportion with the background-image property, and the proportion with the linear-gradient percentages. So, you can have several dotted borders using multiple backgrounds. In this example, we have a dotted line of 3px dots and 7px spacing.
Using hr created two lines for me, one solid and one dotted. Plus, because you can make the width a percentage, it will always have some space on either side (even when you resize the window). Save this answer. Show activity on this post.
DEMO
Output :
This solution floats both texts and the dotted bottom border expands to the remaining width. Here is the relevant code :
HTML :
<div class="left">Name:</div>
<div class="right">Engineer</div>
<div class="dotted"></div>
<div class="left">Factory location:</div>
<div class="right">not invoice address</div>
<div class="dotted"></div>
CSS :
div{
height:1em;
}
.left,.right{
padding:1px 0.5em;
background:#fff;
float:right;
}
.left{
float:left;
clear:both;
}
.dotted{
border-bottom: 1px dotted grey;
margin-bottom:2px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With