Creating borders on columns of equal height using Bootstrap's flex feature

Utilizing Bootstrap along with a method to ensure equal column heights.

I am attempting to apply colored borders to the left and right sides of both columns, but I'm encountering limitations with Bootstrap. Initially, I had the border set on the inner DIV elements (rather than the col-sm-3/col-sm-9 ones), however, this approach did not work with equal height because it is the column DIV elements that need to be equal in height, not the DIV elements within them.

HTML:

<div class="container-fluid">
  <div class="row flex-row">
    <div class="col-sm-3" id="sidebar">
      <div>
        <p>menu item</p>
        <p>menu item</p>
        <p>menu item</p>
      </div>
    </div>
    <div class="col-sm-9" id="main">
      <div>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
      </div>
    </div>
  </div>
</div>

CSS:

.container-fluid {
  padding-left: 0px;
  padding-right: 0px;
}

@media only screen and (min-width : 481px) {
  .flex-row.row {
    display: flex;
    flex-wrap: wrap;
  }
  .flex-row.row > [class*='col-'] {
    display: flex;
    flex-direction: column;
  }
  .flex-row.row:after,
  .flex-row.row:before {
    display: flex;
  }
  .flex-row.row > [class*='col-'] > .box {
    display: flex;
    flex: 1;
  }
}

#sidebar {
  background: #B3D6B3;
  border: solid 10px #D6E9D6;
  margin: 0;
}

#main {
  background: pink;
  border: solid 10px #D6E9D6;
  border-left: 0px;
  margin: 0;
}

View the JsFiddle example here: https://jsfiddle.net/robertmarkbram/co6hnoc3/

Snippet by Gerard

I have copied the code from Gerard's answer into a basic HTML page and I am not observing the same layout as shown in the snippet view.

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

Answer №1

Can you provide more information about the borders issue in the CSS code? I have simplified it for better understanding.

.container-fluid {
   padding-left: 0px;
   padding-right: 0px;
}

/* Flexbox Equal Height Bootstrap Columns (fully responsive) */
@media only screen and (min-width : 481px) {
  .flex-row {
    display: flex;
  }
}

#sidebar {
   background: lightgreen;
   border: solid 10px red;
   margin: 0;
}

#main {
   background: pink;
   border: solid 10px red;
   border-left: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
  <div class="row flex-row">
    <div class="col-sm-3" id="sidebar">
      <div>
        <p>menu item</p>
        <p>menu item</p>
        <p>menu item</p>
      </div>
    </div>
    <div class="col-sm-9" id="main">
      <div>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
        <p>actual content</p>
      </div>
    </div>
  </div>
</div>

Answer №2

After implementing Gerard's suggestion here, I finally found a solution that works perfectly in a basic template. Many thanks!

.container-fluid {
   padding-left: 0px;
   padding-right: 0px;
}

#sidebar {
   background: lightgreen;
   border: solid 10px red;
   margin: 0;
}

#main {
   background: pink;
   border: solid 10px red;
}


/* STYLES FOR SMALLER DEVICES */

@media only screen and (max-width: 480px) {
   #sidebar {
      margin-left: 15px;
      margin-right: 15px;
   }
   #main {
      margin-left: 15px;
      margin-right: 15px;
      border-top: 0px;
   }
}


/* STYLES FOR LARGER DEVICES */

@media only screen and (min-width: 481px) {
   .flex-row {
      display: flex;
   }
   .flex-row>[class*='col-'] {
      display: flex;
      flex-direction: column;
   }
   .flex-row.row:after,
   .flex-row.row:before {
      display: flex;
   }
   #sidebar {
      margin-left: 15px;
      border-right: 0px;
   }
   #main {
      margin-right: 15px;
   }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
   <div class="row flex-row">
      <div class="col-sm-3" id="sidebar">
         <div>
            <p>menu item</p>
            <p>menu item</p>
            <p>menu item</p>
         </div>
      </div>
      <div class="col-sm-9" id="main">
         <div>
            <p>actual content</p>
            <p>actual content</p>
            <p>actual content</p>
            <p>actual content</p>
            <p>actual content</p>
            <p>actual content</p>
            <p>actual content</p>
         </div>
      </div>
   </div>
</div>

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

Concerning geoext

I am currently working on creating a framework for overlaying layers on the web. I am using geoserver to publish the layers and the geoext tree.js example to display all the layers in a tree-like panel. However, I'm encountering an issue with zooming ...

Is there a way for me to adjust column widths in bootstrap using only CSS, without being able to modify the HTML code?

<div class="col-12 col-md-7">column md-7</div> <div class="col-12 col-md-1">spacer md-1</div> <div class="col-12 col-md-4">column md-4</div> Recently, I took on a volunteering opportunity to revamp a webpage for an upco ...

Discover the status of appcache on a webpage even without a manifest file by utilizing an iframe

Looking to cache two important pages of my web application using Application Cache. Successfully implemented with the iframe technique to specifically cache those two pages without caching the manifest-calling page. However, encountering an issue where I ...

Using Javascript to iterate through and increase HTML code with values all the way up to 55

I am looking for a way to automatically generate a list of links in an HTML page using JavaScript. I have tried a few scripts, but none have worked for me. This is the current structure of my HTML... <a href="1.html"><img src="images/1.jpg" widt ...

Refreshing the current checkbox input field in React

I developed a unique custom weekdays check input field using React.js to display which days are open for customers. By looping through a hardcoded array, each day is rendered with its corresponding input checkbox. The first row shows Monday through Thursda ...

Is it required for IDs in CSS to always correspond to a single element? How should IDs be handled if the same element is repeated multiple times on

Is it possible to have a menu that is visible at both the top and bottom of an extensive HTML page using the following code: <div id="menu"><ul><li>Home</li><li>About</li></ul></div> Would it be appropriate ...

What is the best way to scale an image in headershot HTML without risking cropping and still preserving the aspect ratio?

In our Laravel project, I utilized browsershot to create A4 pdf files. In the headerHtml of browsershot, I wanted to display an image logo that would automatically adjust its size to fit a div container while preserving its aspect ratio. While following th ...

Having trouble relocating the navbar logo to the left side

I've been struggling to adjust the logo position by moving it slightly to the left, but all my attempts so far have failed. Initially, I thought the issue might be due to the .main_nav_container or the container and a <div col-lg-12> wrapping, ...

Is there a way to adjust the dimensions of individual pictures?

Dealing with a variety of images within a resizing container can be tricky. I have a solution for adjusting each image to a specific size without affecting the others. Currently, the container's CSS is set to resize images based on browser size: .con ...

Tips on presenting messages to users after clicking the submit button?

I am trying to extract data from a table. I am unsure if my current code is able to retrieve the value from the table. <script> function validateForm() { var x = document.forms["assessmentForm"]["perf_rating11"].value; var y = document.f ...

Ways to showcase contents inside a specific div when hovering with a mouse

I am working with a div structure that includes menus and items within each menu. <div id="navigate"> <div class="menu"> <div class="group">Mail</div> <div class="item">Folders</div> <div clas ...

I could use some help with understanding node.js scripts, running processes, and other related tasks

I'm currently trying to run a node.js script using CMD and I keep encountering an error. Here's the code snippet that's causing the issue: var mysql = require('mysql'); var log4js = require('log4js'); var io = requi ...

Elements styled as inline blocks with static dimensions, irregular in size

Is there a way to ensure that all three boxes are displayed at the same level? Currently, box 2 appears below box 1 and 3 due to having less content. I believe there must be some styling element missing to make each div display at an equal level regardless ...

Guide on how to apply an image map within a specific area of a background image

I have experience setting image maps for foreground images, but this time I need to set an image map for a specific area of an image that is used as the background image of a div. I have searched extensively online for a solution but have come up empty-han ...

What is the best way to store and recall user selections from a dropdown menu using PHP?

Newbie in the house. I managed to store my user's choice from a select menu, but now it seems like the validation is not working as expected. How can I resolve this issue? This is the snippet of code I'm using for validation: <?php $color ...

Consistent max-width applied to various items using full HTML and CSS styling

Can a CSS class be created where the width is dynamically set to match the width of the longest item? I know how to do this in jQuery by iterating through, but I need a solution using only CSS/CSS3. ...

Tips for changing a fullscreen HTML5 video appearance

I discovered a way to change the appearance of a regular video element using this CSS code: transform: rotate(9deg) !important; But, when I try to make the video fullscreen, the user-agent CSS rules seem to automatically take control: https://i.sstatic. ...

When using NVDA (Accessibility Screen Reader) on Google Chrome, chances are that the text in a Bootstrap Modal Dialog may not be

To Test Accessibility: Click here for the NVDA Screen Reader test For 508/accessibility compliance, I am running tests using the NVDA Screen Reader. Currently, I have implemented "Info Dialog" boxes through Bootstrap Modal. While Firefox correctly reads ...

Trouble Keeping the Bootstrap Navbar Sticky Throughout Different Sections

<!DOCTYPE html> <html lang="en"> <head> <!-- Head section --> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Jessica Kowalski</title> ...

How to dynamically adjust column width based on maximum content length across multiple rows in CSS and Angular

I am attempting to ensure that the width of the label column in a horizontal form is consistent across all rows of the form based on the size of the largest label. Please refer to the following image for clarification: Screenshot Example All label column ...