The size of Bootstrap 3 columns adjusts dynamically based on the width of the window as the page is being

I am facing an issue with the layout of my bootstrap site when resizing the 3 horizontal columns based on the window size upon page load.

Currently, I have a script that adjusts the height of each column to match the tallest one so they appear uniform when the page is resized. This method works perfectly if the user accesses the page from a large viewport or in full-screen mode. However, if the page is loaded in a smaller window, which triggers the collapsed layout, and then the window is expanded, the columns end up being shorter than the text content. A simple refresh of the window solves this problem.

To see this behavior in action, please refer to the JSFiddle link below and resize the window while running the script at a larger window size:

https://jsfiddle.net/ycs9psr3/1/

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Testing</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet"          href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">    </script>

<style>

    .well {
        background-color: #b2dcf7;
        border-radius: 10px;
    }

    .well > img {
        margin-bottom: 30px;
    }

    .well > h4, .well > p {
        color: #16405b;
    }

    .container {
        background-color: white;
        border-width: 0px 1px;
        box-shadow: 0px 3px 20px grey;
    }

    body {
        background-color: #f6f6f6;
        font-family: Verdana;
        min-width: 540px;
    }
</style>
</head>
<body>

<div class="container">
    <div class="row">
        <div class="col-md-4 text-center">
            <div class="well well-sm">
                <img src="Images/example.svg" alt="Example" width="128"   height="128">
                <h4>Box 1</h4>
                <p>How do we resolve this How do we solve this How do we address this How do we mend this How do we fix this situation?</p>
            </div>
        </div>
        <div class="col-md-4 text-center">
            <div class="well well-sm">
                <img src="Images/example.svg" alt="Example" width="128" height="128">
                <h4>Box 2</h4>
                <p>How can this be fixed How can this be rectified How can this be resolved How can this be amended How can this situation be addressed?</p>
            </div>
        </div>
        <div class="col-md-4 text-center">
            <div class="well well-sm">
                <img src="Images/example.svg" alt="Example" width="128" height="128">
                <h4>Box 3</h4>
                <p>What steps are needed to repair this What needs to be done to fix this What actions can be taken to correct this situation?</p>
            </div>  
        </div>  
    </div> 
</div>

<script>
$( window ).resize(function() {
    var heights = $(".well").map(function() {
        return $(this).height();
    }).get(),b

    maxHeight = Math.max.apply(null, heights);

    $(".well").height(maxHeight);
});
</script>

</body>
</html>

Your assistance with this matter would be greatly appreciated.

Answer №1

I have updated your fiddle with a CSS-only version to achieve equal height columns in Bootstrap without using any JavaScript. You can see the result here: https://jsfiddle.net/ycs9psr3/2/

Further Reading:

        body {
          background-color: #f6f6f6;
          font-family: Verdana;
          min-width: 540px;
        }
        
        .container {
          background-color: white;
        }
        
        .sameSize {
            display: flex;
            flex-wrap: wrap;
        }

        .sameSize > div[class*='col-'] {
            display: flex;
            flex-direction: column;
            background-color: #b2dcf7;
            background-clip: padding-box;
            border: 10px solid transparent;
            border-radius: 20px;
        }
        
        .well {
          background-color: #b2dcf7 !important;
          border:none !important;
        }
        
        .well > img {
          margin-bottom: 30px;
        }
        
        .well > h4,
        .well > p {
          color: #16405b;
        }
        
        
        
        
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row sameSize">
    <div class="col-md-4 text-center">
      <div class="well well-sm">
        <img src="Images/example.svg" alt="Example" width="128" height="128">
        <h4>Box 1</h4>
        <p>Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions </p>
      </div>
    </div>
    <div class="col-md-4 text-center">
      <div class="well well-sm">
        <img src="Images/example.svg" alt="Example" width="128" height="128">
        <h4>Box 2</h4>
        <p>Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions </p>
      </div>
    </div>
    <div class="col-md-4 text-center">
      <div class="well well-sm">
        <img src="Images/example.svg" alt="Example" width="128" height="128">
        <h4>Box 3</h4>
        <p>Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions Instructions </p>
      </div>
    </div>
  </div>
</div>

Answer №2

Ensure compatibility across all screen sizes by utilizing multiple responsive classes instead of just class="col-md-4". Consider using

class="col-md-4 col-sm-4 col-xs-4"
for optimal performance on small screens.

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

Interacting with my Rails API through JavaScript requests

Exploring the world of Rails and diving into creating a basic rails-api. Currently facing an issue while trying to incorporate user addition to my model using a JavaScript request... Let's take a look at my HTML file named add-user.html: <script ...

Issue with Bootstrap grid borders

I am currently working on a grid system that displays flight information in 10 columns, with a select button and price in 2 columns. I am facing an issue where adding a border to separate the select button section from the rest of the flight information on ...

Angular ng-repeat not populating the list properly, causing a collapse not to display

Currently, I am working on developing an app using Angular.js and Bootstrap UI, but I have run into a problem with a collapse navigation feature. The issue I am facing is that I have an ng-repeat that should be functioning properly. However, when I click ...

Using jQuery to assign unique identifiers to the following sibling elements

A piece of code I'm working with is causing all sibling divs to have the same ID: var d = 0; var newid = currentId.substring(currentId.length-8, currentId.length-1)+d; $.each(('table').next(), function() { $('table').find(&ap ...

CSS slideshow with automatic horizontal image transition that seamlessly restarts

I am facing an issue with my HTML & CSS automatic horizontal slideshow. Everything works fine, except for when the last image finishes sliding and the slideshow loops back to the first image, there is a sudden jump in the appearance of the first image. How ...

JavaScript appendChild method not functioning properly with dynamically created image elements in JavaScript code

I recently encountered an issue while working on a website project. I was trying to create an img element using JavaScript, but ran into a problem when I tried to add the src attribute and then use the appendChild function. I'm unsure if I am missing ...

Modify the values of an object by utilizing the setter function

How can I utilize the setter method to update existing values of an object and perform mathematical operations? var obj = { set model(object) { //method's logic } }; obj = {x:10, y: 20, p: 15}; obj = { x:10, y: 20, p: 15 set mod ...

Troubleshooting: Issues with MagicSuggest's dependent multiple dropdown functionality

Currently implementing MagicSuggest for a custom dropdown feature with two dropdowns: category and subcategory. The goal is to have the subcategories populate based on the selected category. However, after selecting a category and then a subcategory, if ...

Retrieve a value using the jQuery each() method

Hello, I am a beginner in JavaScript and I need help with extracting values from JSON and adding them to an array. My goal is to be able to parse this array using another function later on. However, I'm struggling with returning the array after adding ...

How can you handle undefined values in the query object parameter when using Mongoose's Find function?

Alright: Sound.find({ what: req.query.what, where: req.query.where, date: req.query.date, hour: req.query.hour}, function(err, varToStoreResult, count) { //perform some actions }); Let's consider a scenario where only req.query.what has a ...

Is it possible to toggle all parent targets in Bootstrap?

When trying to showcase my point, I believe it is best demonstrated by visiting Bootstrap documentation at https://getbootstrap.com/docs/4.0/components/collapse/ and viewing the "multiple targets section." In this section, you will find three buttons: togg ...

Ajax activates a slider

One element I have is a menu div, along with a content div Initially, when the slider (which is a jquery plugin) is placed in the index.php, everything appears to be working well, as shown in the image below However, my objective is to have each page&apo ...

Can you provide some guidance on accessing HTTP headers while using Promises to make AJAX requests?

Currently, I am working on resolving jQuery ajax requests using bluebird.js and I have found it quite challenging to access the HTTP headers of the request. Here is a snippet of the code I am working with: Promise.resolve($.get(...)).then(function(data){ ...

Verify if the user possesses legitimate Jira REST API credentials

I am currently using the npm module jira-client to send API requests to my Jira system. I need a way to verify whether the user has valid credentials before proceeding. Depending on the validation result, I plan to either: Inform the user that their use ...

The variables $invalid and $valid in my AngularJS form have not been assigned any values

I came across a post on StackOverflow discussing the issue of both "myForm.$valid" and "myForm.$invalid" being undefined on an Angular form. However, my problem is slightly different. I have defined a form like this: <form name="EntityForm" role="form ...

Can someone guide me on how to make an array filled with dates using Javascript?

I am working on developing a Javascript code that can identify all the days leading up to the current date. Here is what I have managed so far: var titleArray = [ "title1", "title2", ]; var pictureArray = today.toString(); var thumbArray = today.toString ...

Integrating the Google Translate tool onto a website

My goal is to integrate a translation tool like Google Translator or other reliable options onto my website. I am not looking to translate the entire content of my pages into another language, but instead want to add a feature similar to the one found on t ...

React - Paths of images converting to relative when directly accessed via the address bar

Whenever I click on a route link, everything works perfectly. The images have the correct path in the DOM and load successfully. However, if I manually type the URL into the address bar with the route suffix included, like example.com/services, the image ...

Is the treatment of __proto__ different in the fetch API compared to manual assignment?

When using fetch to retrieve a payload containing a __proto__, it seems that the Object prototype is not affected in the same way as when directly assigning to an object. This behavior is beneficial as it ensures that the Object prototype remains unaffect ...

ArangoDB's graph maxDepth setting causing excessive iterations

I am working on creating a substantial social network graph using ArangoDB. The database currently contains approximately 35,000 vertices connected by around 150,000 edges. Considering the extensive amount of data, I was looking to display only a portion ...