Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display text, a dotted line then more text spanning the width of the page?

Tags:

html

css

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.

like image 831
CodeClimber Avatar asked Feb 04 '11 13:02

CodeClimber


People also ask

How can I show dots in a span with hidden overflow?

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>.

How do I change the dotted line size in CSS?

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.

How do I make a dotted line in CSS?

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.


1 Answers

Simple solution with no image

DEMO

Output :

Responsive dotted line between text on the right and on the left

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;
}
like image 159
web-tiki Avatar answered Nov 16 '22 03:11

web-tiki