Column CSS can be enhanced by implementing a divider within the design

I need assistance in creating a row with 2 columns accompanied by a divider. Here is an illustration of what I am trying to achieve:

https://i.sstatic.net/Bv1c2.png

The row should contain a light divider and a white divider that adjusts its size based on the amount of text in each column, similar to this example:

https://i.sstatic.net/catZR.png

Is there a way to accomplish this using CSS? I would appreciate any guidance on how to make the white line divider adjust dynamically based on the text content in the columns.

Answer №1

One approach is to create a container for the long-stick border and then apply a short-stick border on text elements

.flexbox {
  display: flex;
}

.text-container {
  padding: 1rem 0; /*Add top-bottom padding for text container*/
  width: 50%;
}

.text-container span {
  padding: 0 1rem; /*Add left-right padding for text*/
  display: block;
}

.text-container:first-of-type {
  border-right: 1px solid #ccc; /*Set border on text container*/
}

.text-container:first-of-type span {
  border-right: 4px solid #ddd; /*Set border on text*/
  margin-right: -2.5px;
}
<div class="flexbox">
  <div class="text-container">
    <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span>
  </div>
  <div class="text-container">
    <span>Lorem ipsum dolor sit amet</span>
  </div>
</div>

Answer №2

@import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');
body {
  background: #111;
  display: flex;
  height: 100vh;
  width: 100vw;
  padding: 0;
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  font-size: 1.2rem;
  align-items: center;
  justify-content: center;
}

.container {
  width: 700px;
  box-shadow: 0px 0px 10px #000;
  background: #222;
  color: rgb(140, 140, 140);
}

.text {
  margin: 0;
  padding: 40px;
  width: 50%;
  display: flex;
  align-items: center;
}

.textcontainer {
  display: flex;
  align-items: stretch;
  margin: 0;
  padding: 0;
}

.divider {
  display: inline-block;
  width: 1px;
  background: #fff;
  align-self: stretch;
  margin-top: 40px;
  margin-bottom: 40px;
  z-index: 1;
}

.text:nth-of-type(even) {
  border-left: 0.5px solid #444;
}
<div class="container">
  <div class="textcontainer">
    <p class="text">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac fringilla est. 
    </p>
    <span class="divider"></span>
    <p class="text">
      Proin et efficitur ipsum. Nam nec justo commodo, vestibulum libero id, tincidunt dolor. 
    </p>
  </div>
</div>

Answer №3

Neither of the other answers adequately address the issue that either column A or B may contain variable content. Simply adding margins to one of the columns will not resolve the issue of the

white divider that should grow with the text length like this
and
white line divider that expands based on the text length in either column
.

Resolution

I struggled to find a pure CSS solution since CSS does not provide a way to determine element heights. I resorted to a small snippet of JavaScript to tackle the problem.

// calculate paragraph heights
let heightColA = document.querySelector('.col-a p').offsetHeight;
let heightColB = document.querySelector('.col-b p').offsetHeight;
// apply border after comparing heights of Col A and Col B
if (heightColA > heightColB) {
  document.querySelector('.col-a p').style = 'border-right: 5px solid #fff; margin-right: -5px;'
} else {
  document.querySelector('.col-b p').style = 'border-left: 5px solid #fff; margin-left: -5px;'
}
// console.log(heightColA, heightColB)
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.container {
  display: flex;
  width: 100%;
  background-color: #000;
  height: 500px;
  color: #fff;
}

.container>div {
  width: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container .col-a {
  border-right: 5px solid #d00;
}

.container>div>p {
  padding: 2rem;
}
<div class="container">
  <div class="col-a">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure, hic provident? Iste commodi neque corrupti debitis mollitia atque, eveniet iure!
    </p>
  </div>
  <div class="col-b">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure, hic provident? Iste commodi neque corrupti debitis mollitia atque, eveniet iure! Lorem ipsum dolor sit amet consectetur, adipisicing elit. Minima ipsum dolorem, nisi voluptates, rerum
      ipsa labore eius aliquam quas magni amet. Accusantium architecto perspiciatis, minus non voluptatibus totam sequi. Placeat sint error doloremque eveniet quibusdam quo delectus, laboriosam alias autem voluptatum unde eum, officiis omnis vel molestias
      dolorem distinctio nulla! Voluptatem qui explicabo corrupti autem consequuntur cupiditate sequi quos reprehenderit velit, porro, assumenda, officiis deserunt! Corrupti qui perspiciatis nemo. Repellendus qui facilis similique earum molestias distinctio
      quae sed, laboriosam laudantium corporis, suscipit, dolor accusamus pariatur iste nam. Exercitationem ab vitae eveniet. Blanditiis, facilis quidem eos ad aut quibusdam laudantium a!
    </p>
  </div>
</div>

By increasing the content in either column, the white divider will adjust accordingly.

I trust this adequately addresses the inquiries.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I incorporate custom text when hovering over dates on fullcalendar?

I'm looking to customize the mouseover text inside fullcalendar. Currently, the script only displays the event title on mouseover. You can see a working example here: JS Fiddle Example. How can I modify the code to show my own personalized text on mo ...

javascript An interactive accordion component created with Bootstrap

I have been searching for a solution to create an accordion-style collapsible set of panels where the panels remain separate and do not have headers. I want buttons on one side, and when clicked, a panel is displayed on the other side. Only one panel shoul ...

What are some methods for creating a tooltip or a similar quick information pop-up that appears instantly when hovered over?

I'm familiar with creating a basic tooltip by utilizing title="here's a tooltip", but I'm interested in having it appear instantly upon hovering instead of the usual delay. Is it feasible to achieve this using different tools such ...

Best approach for adding an image to an HTML help button: which semantic option is most effective?

Is there a way to create an HTML help button that appears as an image? What would be the most appropriate and semantic approach to achieve this? Below are three different solutions I have considered: 1st idea: Using HTML <button class='help&ap ...

Fluidly move through spaces where subsequent elements align to the top level

In the black container, there is an {overflow:hidden;} CSS property applied The yellow blocks are ordered in code according to the numbers and have {float:left;} I am aiming for the 5th element to align with the element above it: However, currently this ...

Tips for positioning your side navigation menu parallel to the page edge

Im looking to have the side navigation floated to the left as I scroll down the page. I tried using the sticky property, but it didn't work out. Here's a snippet of the code: .sticky-class { position: sticky; top: 30px; } This is how my HTML ...

Drop-down menu for every individual cell within the tabular data

I'm working with a large HTML table that looks like this: <table> <tr> <td>value1</td> <td>value2</td> </tr> <tr> <td>value3</td> <td>value4 ...

Choose different components that possess the X designation

Can X number of elements (h1, p, span...) be modified only if they have a specific class? I'm searching for a solution like this: (elem1, elem2, elem3, elem4).class { /* add customization here */ } I previously attempted using parentheses, curly b ...

Is there a way to insert a dot after every two digits in a text field using Javascript upon keypress?

When inputting a 4-digit number (e.g. 1234) in my text field with value format 00.00, I want it to automatically adjust to the 12.34 format. How can I achieve this behavior using JavaScript on keyup event? ...

Make the inner div fill the entire width within a container of a fixed width

On my blog page, I am currently using the col-md-8 class. Inside this column, my content is displayed. However, I want to stretch a particular div to occupy the full width within the col-md-8. Here is the section of my code: https://i.stack.imgur.com/uPS5 ...

Exploring the Interactive Possibilities of CSS3 with Background Tiles

I'm struggling to implement a flip effect where the content of a div changes, but I can't seem to prevent the text from disappearing after a few seconds. I've tried using backface-visibility:hidden with no luck! HTML <div class="cards" ...

Each container has its own div counter

Help needed to complete this code. The task is to count the number of .resp-containers in each container separately. Then, based on that count, assign a corresponding class to each element within the containers. Check out the code here $(document).ready(f ...

Navigating on Blogger can be a tricky task when it comes to searching and

I recently added a Table to my blogger post, along with an input form for readers to easily search data. After finding the code on W3Schools (link here), I implemented it successfully. However, I am looking to make some improvements. Here is my question: ...

Bootstrap 5.3 does not allow custom background colors to take precedence

Ever since the update to Bootstrap 5.3.1, I've been facing an issue where two custom background colors are not overriding the colors set by Bootstrap, even when using !important. Strangely enough, they were working fine before the update. Here are my ...

How can I use jQuery to vertically align an element?

Here's my website: Take a look here! I have a menu on the left column that I want to center. Take a look at the image below for a better understanding of what I'm trying to achieve. https://i.stack.imgur.com/ZzprT.png Here is the JavaScript c ...

The background image will expand to fill any available space

I'm currently working on rendering divs with a background image CSS property. The images have fixed sizes, and I want to display them in a grid layout. However, the divs with background images stretch when there is extra space available, which is not ...

The Bootstrap nav-link class functions perfectly in Firefox, smoothly guiding users to the appropriate section. However, it seems to be experiencing some issues

I am currently working on customizing a one-page web template and I don't have much experience with Bootstrap. The template can be found at . My issue is that the menu items are not functional in Chrome. When I click on any menu item, nothing happens ...

Unable to fix position: sticky issue following Angular 15 update

Following the angular material update to version 15, many of us experienced issues with CSS changes breaking. This also affected legacy code that included sticky headers. <div class="row"> <div class="col-12"> <di ...

An issue has occurred in NextJS - the HookWebpackError is indicating that a pseudo-class or pseudo-element was

When I run next build, I encounter the following error: HookWebpackError: Expected a pseudo-class or pseudo-element. at makeWebpackError (/Users/eliot/Developer/eliothertenstein.com/node_modules/next/dist/compiled/webpack/bundle5.js:28:308185) at / ...

Is there a way to continuously run jQuery code or reset it?

Can you help me create a loop that will continuously run this script after it finishes executing, repeating the process indefinitely? I want to keep running this code over and over again. This script is using jQuery version 3.5.1 // Title var title1 ...