code-snippets/docs/css/text-width-hr.md
Liam Pietralla 8ad5845efc
Some checks failed
Build, Test & Publish / Build and Publish Container Image (push) Has been cancelled
Build, Test & Publish / Deploy to Infrastructure (push) Has been cancelled
Build, Test & Publish / Build (push) Has been cancelled
initial commit
2024-09-05 13:54:08 +10:00

895 B

Text Width Horizontal Rule

Often times, you want to create a horizontal rule that spans the width of the text. This is a simple way to do that.

.hr {
    display: inline-block;
}

.hr::after {
    content: '';
    display: block;
    border-top: 2px solid black;
    margin-top: .1rem;
}

In the above snippet we create a horizontal rule that spans the width of the text. We do this by creating a block element with display: inline-block and then adding a pseudo element with display: block and a border. The margin-top is used to create some space between the text and the horizontal rule.

This is how it looks:

<p>
    This is some normal text
</p>
<h2 class="hr">This is a heading</h2>
<p>
    This is some more normal text
</p>

Which will render as:

Text Width Horizontal Rule Example