Divs aligned horizontally with uniform height and vertical divider separating them

Seeking a method to create side by side, equal height divs (without resorting to table layout) with a single vertical line separating them. Attempted using flex container per row but the vertical line is fragmented which is not ideal... What would be the optimal solution for this issue?
Desiring a setup resembling the image below: https://i.sstatic.net/zXD5Z.png

Summary of attempted solutions:

<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<style type="text/css>
.flex-container{
display: -webkit-flex; /* Safari */
display: flex; /* Standard syntax */
}
.flex-container .column{
    background: #dbdfe5;
    width: 100px;
}
.vr {
background: red;
    width: 2px;
    margin: 0px 5px 0px 5px;
}
</style>
</head>
<body>
    <div class="flex-container">
        <div class="column">R1 - Col1</div>
        <div class="vr"></div>
        <div class="column bg-alt">R1 - Col2</div>
    </div>
    <div class="flex-container">
        <div class="column">R2 - Col1</div>
        <div class="vr"></div>
        <div class="column bg-alt">R1 - Col2</div>
    </div>
</body>
</html>  

Note: The number of rows is N and the content in each column is dynamic, determining the row's height based on the tallest content in that row. (No JavaScript allowed!)
Thank you!

Answer №1

Creating a Dynamic Divider

To create a seamless divider, utilize a wrapper element.

.col-item {
  width: 49%;
  margin-right: 2%;
  margin-bottom: 15px;
  border: 1px solid blue;
  padding: 5px;
  box-sizing: border-box;
}

.col-item:nth-child(2n) {
  margin-right: 0;
  padding-right: 0;
}

.col-item:nth-last-child(2),
.col-item:last-child {
  margin-bottom: 0;
}

.wrapper {
  display: flex;
  flex-wrap: wrap;
  position: relative;
}

.wrapper:after {
  content: "";
  position: absolute;
  top: 0;
  left: calc(50% - 1px);
  height: 100%;
  border-right: 1px solid red;
}
<div class="wrapper">
  <div class="col-item">
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
  </div>
  <div class="col-item">
    At vero eos et accusam et justo duo dolores et ea rebum.
  </div>
  <div class="col-item">
    Lorem ipsum dolor sit amet!
  </div>
  <div class="col-item">
    Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  </div>
</div>

Answer №2

Just like @fauxserious's response, there is no need to worry about multiple children within the column as long as you apply the pseudo selector to the parent container:

.container {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-wrap: wrap;
}

.container>* {
  flex: 0 1 auto;
  float: left;
  width: calc(50% - 40px);
  margin: 20px;
  border: 1px solid;
  height: 200px;
  box-sizing: border-box;
}

.container:before {
  content: "";
  position: absolute;
  left: 50%;
  top: 20px; /* Same as margin */
  bottom: 20px; /* Same as margin */
  border-left: 1px solid #ff6600;
}
<div class="container">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>

Answer №3

Create a container for two column children and position them side by side using float property. Utilize a pseudo element with absolute positioning to create a visual line separating the columns.

section{
  height:700px;
  box-sizing:border-box;
}

section > * {
  float:left;
  width:48%;
  margin:2%;
  border:1px solid #333;
  height:100%;
  box-sizing:border-box;
  position:relative;
}

section > :last-child:before {
  content:"";
  height:100%;
  position:absolute;
  left:-4%;
  margin-left:-3px;
  top:0;
  border:1px solid #333;
}
<section>
  <div></div>
  <div></div>
</section>

Answer №4

Here is an example that I have created for you to review.

I hope you find it interesting.

.content-left {
  width: 40%;
  height: 500px;
  border-right: solid 2px red;
  display: inline-block;
}

.content-right {
  width: 40%;
  height 500px;
  display: inline-block;
}
.content {
  margin-top: 10px;
  margin-left: 10px;
  margin-right: 10px;
  background-color: lightblue;
}
.left1 {
  height: 190px;
}

.left2 {
  height: 90px;
}

.left3 {
  height: 190px;
}

.right1 {
  height: 190px;
}

.right2 {
  height: 90px;
}

right3 {
  height: 90px;
}

right4 {
  height: 90px;
}
<div class="content-left">
  <div class="content left1"></div>
  <div class="content left2"></div>
  <div class="content left3"></div>
</div>
<div class="content-right">
  <div class="content right1"></div>
  <div class="content right2"></div>
  <div class="content right3"></div>
  <div class="content right4"></div>
</div>

Answer №5

Simplest method to generate a vertical line between two containers and ensure the line spans from top to bottom

.table_container.row{
       /* border: 0.5px solid #333;*/
        margin-top: -1px;
        display: flex;
     
    }
    .table_container .left_col{
       border-right:3px solid red;
    }
    
    
 <div class="row table_container">
          <div class="col-md-4 left_col">Lorem</div>
          <div class="col-md-8 right_col">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
 </div>
 
    

Answer №6

Do you like it this way? :

header, section, .sub_section, footer {
  float:left;
  width: 40%;
  border: 3px solid #000;
  margin-left: 6%;
}
header {
  height: 20vh;
}
section {
  height: 40vh;
  margin-top: 2%;
}
.sub_section {
  height: 20vh;
  margin-top: 2%;
}
footer {
  height: 20vh;
  margin-top: 2%;
}
<header></header>
<header></header>
<section></section>
<section></section>
<div class="sub_section"></div>
<div class="sub_section"></div>
<footer></footer>
<footer></footer>

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

What is the best way to align the logo image in the center of the header vertically?

I am trying to vertically center my logo, but I have not been successful with using margin: auto or margin: center. Here is what I have tried so far: ・text-align: center; ・margin: auto; ・margin: center: ・navbar-brand-center The logo currently app ...

Implementing a vertical tabindex change in Material UI Dialogue table

My material UI dialogue contains a table: <Dialog open={open} onClose={handleClose} maxWidth={'xl'} aria-labelledby='scroll-dialog-title' aria-describedby='scroll-dialog-description' disa ...

Is there a way to modify the background color of ::before when hovering over it?

I have a ul-li list and when i hover last li ::before element looks white and not so good. I want to change it when i hover the last li element. How can I achieve this? Here are my codes: <div className="dropup-content"> <ul> & ...

css determining the width through calculation

I am facing a challenge with a math problem. My content box is 700 pixels wide, and my hentry (inside content) is 100% wide with padding of 10 pixels. This causes the hentry to be wider than the content, resulting in an overflow... Does anyone have a so ...

Is it possible to align two buttons side by side on a webpage using only HTML and CSS?

Can you help me figure out how to align two buttons next to each other with some space between them using only css and html? If you take a look at my html code and css code, you'll see that the two buttons are not aligned properly. * { margin: 0 ...

Having trouble with cc email addresses causing problems in Outlook

I'm encountering an issue where there is a '&' symbol in one of the cc email addresses. Due to the default behavior of the browser, the complete email address is not being displayed properly in Outlook. Here's an example: let to='a ...

Is it possible to create a form inside a tooltip?

Looking to incorporate a jQuery feature into a form where a simple yes or no question appears upon hovering over it. However, encountering issues getting jQuery to recognize the dynamically created tooltip and submit alert function not working ("$('#w ...

Serve the mobile version to mobile visitors and the desktop version to all other visitors

Can someone please explain to me how I can display the Mobile Version of a website when visiting on my phone, and the Desktop Version when viewing on anything larger than 500px? I have separately created both a Mobile Website and a Desktop Website. Is it ...

Selenium's click() function is functioning properly, however, the submit() function is not working

During my Selinium Webdriver tests, I have encountered a puzzling issue where I am unable to submit a form by using the submit() method on the elements within the form. However, I can successfully submit the form by calling click() on the submit button. To ...

Unable to dynamically update properties in CSS and JavaScript without refreshing the page

I've tried applying active properties in my CSS and JavaScript, but it doesn't seem to be working as expected. I can click on each list item, but the active state is not being displayed correctly. Can someone please assist me with this issue? I w ...

What steps are involved in setting up a single form for entering orders, complete with both an order table and an order_item table that incorporates a foreign key

As I contemplate the best way to structure my page and forms for a customer ordering process, a few questions arise due to the tables' organization. To adhere to normalization standards, I have separated the order table and the order items table, link ...

Adjust the appearance of input fields that exclusively have the value "1"

When designing my website, I encountered a problem with the style I chose where the number "1" looks like a large "I" or a small "L." I am wondering if there is a way to use JavaScript to dynamically change the font style for input fields that only contai ...

How can the input value be transmitted along with the formArray values?

I am currently working with a FormArray in my project where I can add new fields and submit the entire form data on button click. However, I am facing an issue trying to display and send an input field that is connected to the 'name' attribute wi ...

Error: Identical div IDs detected

<div id="tagTree1" class="span-6 border" style='width:280px;height:400px;overflow:auto;float:left;margin:10px; '> <a class="tabheader" style="font-size:large">Data Type</a><br /> <div class="pane">Refine sea ...

Assistance needed to identify CSS issue specifically in FireFox browser

Working on a new webpage and encountered an issue with the HTML markup: <!DOCTYPE html> <html lang="en> <head> <meta charset="utf-8"> <title>TileTabs</title> <link rel="stylesheet" href="css/style.css" t ...

What could be causing my JavaScript/jQuery code to malfunction when dealing with checkboxes?

My code is supposed to select and disable checkboxes based on which radio button is clicked. For example, when Zero is selected, all checkboxes should be highlighted and disabled, except for the zeroth checkbox. However, this behavior does not consistent ...

Create a table by incorporating the information from the page along with additional content

I need to extract the data from a list and convert it into a table, add some additional content that I will provide, and then align the table accordingly. While I can easily align elements and already have the list, I am facing difficulty in converting it ...

What is the best way to adjust the CSS height of an HTML select element to 100% within a table cell in Internet Explorer

Is it possible to make a select (dropdown list) element fill out 100% of the table cell height? I was successful in getting it to work in Firefox and Chrome, but unfortunately not in IE (Internet Explorer). Here is the test HTML code: <table> & ...

Tips for reducing the JavaScript file size outputted by a liquid template generator

Currently, I am working on enhancing the performance of my Shopify website and GoogleSpeed Insights is suggesting that I minify css and js files. However, the recommended files are all created by the liquid template generator, making it challenging to uti ...

Get a list of all languages supported by browsers using JavaScript

Within my HTML user interface, I have a dropdown that needs to display a list of all installed browser languages except for the first one. I managed to retrieve the first language (en-us), but I also have the zh-CN Chinese pack installed on my operating s ...