Logo Codebridge

Flexbox Dynamic Line Separator

August 1, 2022
|
5
min read
Share
text
Link copied icon
table of content
photo of Myroslav Budzanivskyi Co-Founder & CTO of Codebridge
Myroslav Budzanivskyi
Co-Founder & CTO

Get your project estimation!

While working on a UI, we needed to add a line separator between two sections. Here it is:

On smaller viewports, the line will become horizontal:

Let’s take a look at the HTML.

We have a section, with two main child items. Between them, we will have a line separator.

In CSS, we will use flexbox to handle the layout.

We added a 1rem gap between each one, and also each child item should fill 50% of its parent. Here is the result:

Next step, we want to center the two items vertically, so we will use align-items on the parent.

Now the two items are centered (we added the red line to make it easy to spot that). You might be asking, what does that have to do with the separator?

Adding The Separator

We wanted to add this as a pseudo-element, so we wrote this CSS. Can you expect the visual result of this without scrolling down?

Oh, what is that little square doing over here? Since the pseudo-element is only a 1px border from all sides, the result will be 2*2` square.

Let’s focus a bit here. This is the core of this little CSS trick.

The square comes from using the same color for each border. With different colors, it can look like this.

Why the Separator Looks Like a Square?

Since we added align-items: center to center the child items vertically, we removed the default behavior of flexbox stretching child items (stretching vertically, in this case).

Now it looks like the following visual:

Next, we need to reorder the flex items to make the divider appears between them.

And we’re done!

To make this work on all screen sizes, we need to have the flex-direction: column mobile and flex-direction: row for larger screens.

Here is a video of changing the flex-direction. Notice how the separator changes!

This works like magic because it’s a flexbox behavior.

When flex-direction: row is set, the cross-axis is vertical thus the pseudo-element stretches vertically.

And when the cross-axis is set to flex-direction: column, it will be horizontal and so the pseudo-element stretches horizontally.

Isn’t that neat? No need to use width, height, or anything else! It’s just a border being stretching via flexbox.

The Separator Thickness

Since the border value contributes to the four directions, we need to use 0.5x of the thickness we want. For example, if we want a 1px separator, then the border should be like the following:

Gradient Separators

This is another reason for us to pick the border solution above others. We can use gradients via border-image.

Dashed Separators

Given that we’re using borders, we can also have a dashed separator.

Another Way of Doing It

If we haven’t taken the time to think about implementing this, then we might have used width and height. We are not saying the following is a bad solution, but it’s good to step out of solutions we took for granted and think of other ways of solving UI problems.

Source: https://ishadeed.com/

No items found.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

Rate this article!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
78
ratings, average
4.9
out of 5
August 1, 2022
Share
text
Link copied icon

LATEST ARTICLES

Product Discovery Process: A CTO’s Guide to Faster Delivery
August 28, 2025
|
8
min read

Product Discovery Process: A CTO’s Guide to Faster Delivery

Learn how the product discovery process helps CTOs reduce rework, speed up delivery, and align MVP scope with clear outcomes. A practical 30/60/90-day guide.

by Konstantin Karpushin
Read more
Read more
How to Implement AI to Boost Your Startup's Software Growth
August 14, 2025
|
11
min read

How to Implement AI to Boost Your Startup's Software Growth

Learn how to implement AI in your startup’s software: boost growth with smart automation, data-driven insights, and scalable solutions for long-term success.

by Dmytro Maloroshvylo
Automation Tools
AI
Read more
Read more
Best Technology Stack for Startup Growth and Success
August 14, 2025
|
10
min read

Best Technology Stack for Startup Growth and Success

Explore the best technology stack for startup growth: choose the right tools, frameworks, and architecture to scale efficiently, innovate, and stay competitive.

by Myroslav Budzanivskyi
Flutter
Read more
Read more
Telemedicine App Development Strategies for CEOs
August 14, 2025
|
11
min read

Telemedicine App Development Strategies for CEOs

Discover telemedicine app strategies for CEOs: market trends, compliance, tech stack, EHR integration and monetization to grow and scale in healthcare market.

by Konstantin Karpushin
HealthTech
Read more
Read more
August 14, 2025
|
7
min read

DevOps Implementation Strategies for Growing Startups

Learn core DevOps strategies for startups: CI/CD, IaC, containers, security, FinOps, and scaling practices to accelerate delivery speed, reliability, and growth

by Myroslav Budzanivskyi
DevOps
Read more
Read more
Top 10 MVP Development Company Options for Growing Startups
August 14, 2025
|
20
min read

Top 10 MVP Development Company Options for Growing Startups

Explore 10 MVP development companies for startups: services, pricing, processes, and tips to choose the right partner for rapid, successful product launches.

by Konstantin Karpushin
Read more
Read more
Creating a Music App: Essential Startup Guide
August 14, 2025
|
25
min read

Creating a Music App: Essential Startup Guide

Learn how to create profitable music app: key features, UX design, tech stack, licensing, costs, and monetization strategies for a profitable U.S. market launch

by Konstantin Karpushin
Media and Entertainment
Read more
Read more
Finance Mobile App Development: Building User Trust Through Security and Compliance
July 28, 2025
|
10
min read

Finance App Development: Security and Compliance First

Learn how to build a secure and compliant finance mobile app that earns user trust. Discover key strategies for ensuring security, privacy, and regulatory compliance in mobile finance apps.

by Konstantin Karpushin
Fintech
Read more
Read more
Tech Stack to UX: Guide to E-Learning Application Development That Scales
July 28, 2025
|
10
min read

Scalable E-Learning App Development: From Tech to UX

Explore the essential tech stack, design considerations, and strategies for developing scalable e-learning applications. Learn how to build robust e-learning platforms with excellent user experience (UX).

by Ananga Thapaliya
EdTech
UI/UX
Read more
Read more
Why Startup CTOs Are Turning to DevOps Service Providers
July 28, 2025
|
9
min read

Why Startup CTOs Are Turning to DevOps Service Providers

Explore why more startup CTOs are choosing DevOps service providers. Learn how partnering with experts in DevOps can improve efficiency, scalability, and the speed of product delivery.

Myroslav Budzanivskyi
DevOps
Read more
Read more
Logo Codebridge

Let’s collaborate

Have a project in mind?
Tell us everything about your project or product, we’ll be glad to help.
call icon
+1 302 688 70 80
email icon
business@codebridge.tech
Attach file
By submitting this form, you consent to the processing of your personal data uploaded through the contact form above, in accordance with the terms of Codebridge Technology, Inc.'s  Privacy Policy.

Thank you!

Your submission has been received!

What’s next?

1
Our experts will analyse your requirements and contact you within 1-2 business days.
2
Out team will collect all requirements for your project, and if needed, we will sign an NDA to ensure the highest level of privacy.
3
We will develop a comprehensive proposal and an action plan for your project with estimates, timelines, CVs, etc.
Oops! Something went wrong while submitting the form.