CSS

CSS Tips Vertical Line Rule

Cory Rylan

- 1 minute

Using CSS Flexbox, we can easily make vertical line dividers that can expand and fill the parent container. First, let's start with a basic horizontal rule between two paragraphs.

<div>
<p>some text conent</p>
<hr />
<p>some text conent</p>
</div>
Basic Horizontal Rule with HTML and CSS

To style our horizontal rule to a vertical style, we need to write some CSS for the parent div and the hr element.

div {
display: flex;
}

First, we make the div container a flex parent. This style will default the container items to flex-direction: row, which will place each item side by side.

hr {
min-height: 100%;
max-height: 100vh;
margin: 0;
}
Vertical Line Rule with HTML and CSS

Once our items are displayed horizontally, we can adjust our hr to expand vertically. Using a combination of min-height and max-height, we can fill the div. Min height of 100% will expand while the max height using 100vh will limit the hr not to grow more than the viewport height.

Check out the working demo below!

View Demo Code   
 

No spam. Short occasional updates on Web Development articles, videos, and new courses in your inbox.

Related Posts

Web Performance

Design System Performance with Clarity Core Web Components

Learn how to build high performance UI and Design Systems on the Web using Clarity Core.

Read Article
Web Components

State of Web Components in 2020

Learn a brief overview on Web Components and the latest tech available to build and distribute components across the Web.

Read Article
JavaScript

Wrapping DOM Text Nodes with JavaScript

Sometimes, due to CSS constraints, we need to find DOM text nodes and wrap them with a span or div. This post, we will see how to preserve any existing references safely.

Read Article