Home >Web Front-end >CSS Tutorial >How to Justify Text with Dots Using CSS Without Monospaced Fonts?

How to Justify Text with Dots Using CSS Without Monospaced Fonts?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-25 02:15:02975browse

How to Justify Text with Dots Using CSS Without Monospaced Fonts?

How to Justify Text with Dots Using CSS

Query

Seeking a way to uniformly display text with leading dots, such as:

Drug 1 ............  10ml
Another drug ......  50ml
Third ............. 100ml

without resorting to monospaced fonts.

Solution

A simple yet effective solution utilizes CSS and a dl (description list) element:

CSS:

dl { width: 400px }
dt { float: left; width: 300px; overflow: hidden; white-space: nowrap }
dd { float: left; width: 100px; overflow: hidden }

dt:after { content: " .................................................................................." }

HTML:

<dl>
    <dt>Drug 1</dt>
    <dd>10ml</dd>

    <dt>Another drug</dt>
    <dd>50ml</dd>

    <dt>Third</dt>
    <dd>100ml</dd>
</dl>

Limitations:

  • Not supported in Internet Explorer 8 and earlier.
  • Accepts only literal characters in the content property, excluding HTML entities like ·. However, UTF-8 characters should suffice for most practical scenarios.

The above is the detailed content of How to Justify Text with Dots Using CSS Without Monospaced Fonts?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn