Flexbox Dynamic Line Separator

August 1, 2022
|
5
min read
Share
text
table of content
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/

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

LATEST ARTICLES

October 21, 2024
|
6
min read

What Does It Cost to Redesign a Website?

Discover the key factors influencing the cost of a website redesign, from design complexity to e-commerce functionality. Learn how to budget effectively and prioritize features for a successful, modern online presence.

by Konstantin Karpushin
UI/UX
Read more
Read more
October 18, 2024
|
6
min read

Building Scalable Solutions: Best Practices for Custom Software Development

Discover the best practices for building scalable custom software solutions. Learn how architecture, technology stack choices, and optimization strategies help businesses handle growth, enhance performance, and stay competitive.

by Myroslav Budzanivskyi
Read more
Read more
October 16, 2024
|
6
min read

The Impact of Digital Transformation on Traditional Financial Institutions

Explore how digital transformation is reshaping traditional financial institutions. Learn about shifting customer expectations, fintech disruption, AI integration, and strategies for banks to stay competitive in a rapidly evolving financial landscape.

by Konstantin Karpushin
Fintech
Read more
Read more
October 14, 2024
|
6
min read

Mobile Health Apps: Best Practices for User-Centered Design

Discover best practices for designing user-centered mobile health apps that prioritize usability, accessibility, and engagement. Learn how to create intuitive and secure mHealth apps that enhance user experience and drive better health outcomes.

by Ananga Thapaliya
HealthTech
UI/UX
Read more
Read more
October 11, 2024
|
7
min read

The Future of Online Learning Platforms: Trends and Innovations

Explore the future of online learning platforms as we delve into key trends and innovations shaping education. Discover how AI, immersive technologies, and personalized experiences are transforming the landscape, making learning more accessible and engaging than ever.

by Konstantin Karpushin
EdTech
AI
Read more
Read more
October 9, 2024
|
6
min read

Sustainability in E-commerce: How to Build an Eco-Friendly Online Store

Discover effective strategies for building an eco-friendly online store in the e-commerce sector. Learn how sustainable practices can reduce your carbon footprint, enhance customer loyalty, and contribute to a more ethical business model.

by Konstantin Karpushin
E-Commerce
Read more
Read more
October 7, 2024
|
7
min read

Custom Software for Startups: Accelerating Innovation and Growth

Explore how custom software development can drive innovation and growth for startups. Learn the benefits of tailored solutions and key considerations for successful development to achieve a competitive advantage in today's digital landscape.

by Myroslav Budzanivskyi
Read more
Read more
October 4, 2024
|
6
min read

How Neobanks Are Redefining Customer Expectations in Financial Services

Discover how neobanks are reshaping customer expectations in financial services with their mobile-first approach, transparency, and personalized banking experience. Learn how these digital-only banks are driving innovation in the financial sector.

by Konstantin Karpushin
Fintech
Read more
Read more
October 2, 2024
|
7
min read

The Future of Telemedicine: How AI and IoT are Revolutionizing Healthcare

Discover how AI and IoT are revolutionizing telemedicine, enhancing accessibility, efficiency, and personalized healthcare. Explore the future of remote healthcare delivery and its implications for patients and providers.

by Konstantin Karpushin
HealthTech
AI
IoT
Read more
Read more
September 30, 2024
|
6
min read

Understanding DevSecOps: Integrating Security into DevOps

Learn how to integrate security into your DevOps pipeline with DevSecOps. Discover key principles, benefits, challenges, and best practices for secure and efficient software development.

by Myroslav Budzanivskyi
DevOps
Read more
Read more

Let’s collaborate

Have a project in mind?
Tell us everything about your project or product, we’ll be glad to help.
+1 302 688 70 80
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
Our experts will analyse your requirements and contact you within 1-2 business days.
3
Our experts will analyse your requirements and contact you within 1-2 business days.
Oops! Something went wrong while submitting the form.

Flexbox Dynamic Line Separator

What Does It Cost to Redesign a Website?

A website redesign can be a significant investment, but it's often necessary to keep your online presence modern, functional, and aligned with your business goals. The cost of redesigning a website varies widely, depending on a range of factors including the scope of the redesign, the complexity of the site, the level of customization, and the experience of the design team. Whether you're looking to refresh a small business site or overhaul an enterprise-level platform, understanding the cost breakdown is crucial for budgeting and planning.

In this article, we’ll explore the key factors that influence the cost of redesigning a website, how to prioritize features, and what to expect in terms of pricing at different levels of redesign.

Building Scalable Solutions: Best Practices for Custom Software Development

In today’s competitive business environment, scalability is a critical component of custom software development. As businesses grow, the software that supports them must adapt to handle increased demand, new features, and greater complexity without compromising performance. Failing to build scalable solutions from the start can lead to costly rewrites, performance bottlenecks, and limitations that stunt business growth.

This article explores the best practices for building scalable custom software solutions, emphasizing the importance of architecture, development methodologies, technology stack choices, and testing strategies that enable long-term flexibility and success.

The Impact of Digital Transformation on Traditional Financial Institutions

The financial services sector has been undergoing significant changes, driven by rapid technological advancements. Digital transformation, a process that involves leveraging digital technologies to create new—or modify existing—business processes, culture, and customer experiences, is fundamentally reshaping the financial industry. For traditional financial institutions like banks, insurance companies, and credit unions, digital transformation has presented both challenges and opportunities.

This article explores the impact of digital transformation on traditional financial institutions, highlighting the opportunities for growth, the risks of falling behind, and strategies for successful implementation.

Mobile Health Apps: Best Practices for User-Centered Design

Mobile health apps, also known as mHealth apps, are transforming the healthcare landscape by offering accessible, user-friendly platforms for managing health and wellness. These apps allow users to monitor vital signs, track fitness goals, manage chronic conditions, and even connect with healthcare providers. However, the success of any mobile health app lies in its design. An app that fails to meet the needs of its users will struggle with adoption, usage, and effectiveness, ultimately leading to poor health outcomes.

This article explores the best practices for user-centered design in mobile health apps, focusing on how to create apps that are not only functional but also intuitive and engaging for users.

The Future of Online Learning Platforms: Trends and Innovations

Online learning platforms have transformed education by providing flexible, accessible, and personalized learning experiences for users worldwide. As technology continues to evolve, the future of online education is poised to see groundbreaking changes. With trends like artificial intelligence (AI), personalized learning, micro-credentials, and immersive technologies taking center stage, the landscape of online education is set for continued innovation.

In this article, we’ll explore the emerging trends and innovations shaping the future of online learning platforms, offering insights into how these developments are changing the way we learn.