CSS: Ensuring a column consistently maintains maximum height

Here is an example of the HTML code I am working with:

<div style="height: 80px">
   ...
</div>
<div class="container-fluid">
  <div class="row">
    <div class="col-xs-2 col1">...</div>
    <div class="col-xs-10 col2">...</div>
  </div>
</div>

Currently, both col1 and col2 have a height of auto. However, col2 is always going to be larger than col1. I want col1 to always match the height of col2, while still allowing col2 to adjust its height dynamically.

Is there a way to achieve this using CSS/SASS?

Answer №1

Indeed, achieving equal height columns can be done using either flexbox or table:

.row.equal {
  display: table;
}
.row.equal .column {
  display: table-cell;
  
  /* Just for demo purposes */
  max-width: 5em;
  border: 1px solid #FFF;
  background-color: red;
}

.row.equal.flex {
  display: flex;
}
.row.equal.flex .column {
  /* Just for demo purposes */
  max-width: 5em;
  border: 1px solid #FFF;
  background-color: red;
}
<div class="row equal">
  <div class="column">
    Equal height column using the table property
  </div>
  <div class="column">
    Equal height
  </div>
</div>

<div class="row equal flex">
  <div class="column">
    Equal height column using the flex property
  </div>
  <div class="column">
    Equal height
  </div>
</div>

It's generally safe to proceed without prefixes, but it's always a good idea to consult caniuse for compatibility. Best of luck!

Answer №2

To ensure equal height, use the CSS property display: table-cell. Additionally, apply vertical-align: top to always position text at the top of the column.

For a visual example, check out this JSFiddle link.

CSS code:


.row {
  display: table;
}
.col1, .col2 { 
  display: table-cell;
  width: 300px;
  vertical-align: top;
}
.col1 { 
  background: red;
}
.col2 { 
  background: blue;
  height: 200px;
}

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

Changing the design of an animated button from CSS to styled-components

As I was searching the internet for a button style to use on my register form's button, I came across this awesome animated button code in simple HTML & CSS. I attempted to convert it to styled-components, but I couldn't quite get it to match the ...

Delete any content that is not enclosed in tags

I am struggling with manually rendering Django forms and it's producing the following code. Is there a way to remove text without HTML tags, such as "Currently:" and "Change:", which are difficult to style with CSS? <div class="row align-cente ...

Is it possible to integrate ngx Pagination with Bootstrap?

Is it possible to integrate Bootstrap's pagination with ngx Pagination? I'm interested in using the functionality of ngx Pagination but styling it with the CSS from Bootstrap. ...

Comparing querySelectorAll, NodeIterator, and TreeWalker: which is the quickest JavaScript DOM iterator?

Is there a way to transform a DOM tree into an Array, with the root being the first element? I'm looking for a solution using plain JavaScript. What is the most efficient method to accomplish this? Here is an example of the HTML structure: <div cl ...

Why is the value of the select element in AngularJS an object?

Here is a JSON object: { "9000A": { "LOCname":"A Place", "LOCid":"9000A" }, "2700C": { "LOCname":"C Place", "LOCid":"2700C" }, "7600B": { "LOCname":"B Place", "LOCid":"7600B" } } To ...

What is preventing me from using CSS to customize elements within InfoWindows?

I've been attempting to adjust the font-size of elements within my InfoWindows, but I'm facing some challenges. Here's a snippet of the code for my InfoWindow: <InfoWindow marker={this.state.activeMarker} visible={thi ...

What is the best way to retrieve nested objects in JSON using JavaScript and an Ajax request?

I am facing an issue with a nested JSON structure and trying to access the data through an ajax request to populate an HTML table. Here is a sample of the JSON structure: { sum: { total: 2, }, data: [ { id: '1', attribu ...

"Experience the stunning transformation of 3D objects from poor rendering to exceptional quality in the GLTF-Files Online

I am looking to showcase a model created in Blender on a webpage. The issue is that the rendered quality of the model seems poor, especially with the edges not being properly displayed. Interestingly, when viewing the model in an online viewer, the edges a ...

Problem with Background-sizing in Mobile Webkit

After applying these CSS rules, everything looks great on desktop and Firefox mobile: body{ background: url(../img/home-background.jpg) no-repeat center center fixed; -webkit-background-size: cover; background-size: cover; } However, when vie ...

Utilizing flexbox, absolute positioning, and 100% height in web design

While experimenting with a flexbox inside an absolute box within a div of defined height, I encountered a problem. Let me explain the issue step by step. Here is a link to a fiddle demonstrating the problem: https://jsfiddle.net/8ub9tyub/ When hovering o ...

`Fetching HTML content using a web browser``

Seeking a Linux browser, possibly console-based, with the capability to read an HTML page from standard input. For instance, I am interested in performing the following command: generate_html | browser Appreciate any suggestions! ...

What could be causing the defaultOpen feature to function on my code simulator but fail to work on my website?

I have a set of tabs on my website, and I want the first tab to be automatically selected when the page loads. I tried using some Javascript code from w3schools, which worked in a simulator, but now it's not working on my actual site, and it looks ter ...

Tips on using b-table attributes thClass, tdClass, or class

<template> <b-table striped hover :fields="fields" :items="list" class="table" > </template> <style lang="scss" scoped> .table >>> .bTableThStyle { max-width: 12rem; text-overflow: ellipsis; } < ...

Utilizing nested arrays in jQuery templates

I have a JSON object that looks like the following: [Object] 0: Object domains: Array[1] 0: "domain1.com" length: 1 __proto__: Array[0] name: "name1" 1: Object domains: Array[2] 0: "domain2.com" length: 2 __proto__: Arr ...

Is there a way for a DOMWindow popup to automatically resize to fit its

Currently exploring JQuery and learning on the fly, I'm wondering if there's a method to automatically adjust the size of a DOM window based on its content? I've successfully modified the parameters to accept % width and height instead of p ...

Need to adjust the layout of PHP form

Snippet of code: echo "<form method ='post' action='NextFile.cgi'>"; echo "<table>"; echo "<tr><td>Date: </td></td> <input type='date' name='Date' value =".$record['Date& ...

Tips on retrieving the value of every cell within a row and then transferring it to a corresponding text box within the same row

What is the process for extracting the value of each cell in a row and setting it as the value of the corresponding text box in that row? <tr> <td class="oridinal-number">1</td> <td class="number"> 123456 ...

Attempting to retrieve currentScript is causing a typeError to be thrown

I'm attempting to access a custom attribute that I added to my script tag: <script type="text/javascript" src="https://.../mysource.js" customdata="some_value"></script> To make this work on Internet Explorer ...

Embrace the strange quirks of each individual

I attempted to find a simple solution for creating a box within a class. However, I encountered an issue where it only displayed the first element in the array. Upon echoing out the $values variable, the entire CSS code was returned and I attempted to plac ...

Safari is experiencing issues with overflow-x functionality after a device rotation

I'm currently in the process of developing a website that requires a specific div element to be horizontally scrollable if its content exceeds the screen size. This functionality works smoothly on most browsers, except for Safari: Scenario: When the ...