The alignment issue persists when attempting to set 'relative' on the parent and 'absolute' on the inner element in a Bootstrap column for bottom alignment

Here is a snippet of my basic HTML code:

 <div class = "row">
    <div class = "col-xs-8">
        <p>long long long long text that generates a taller column</p>
    </div>
    <div class = "col-xs-4">
        <p>shorter text that generates a shorter column</p>
    </div>
</div>

To make the two columns reach the same height, I used the following CSS:

.row{
    overflow:hidden;
}

[class*="col-"]{
    margin-bottom:-99999px;
    padding-bottom:99999px;
}

However, when attempting to use the parent relative and child absolute trick for positioning, I encountered an issue where the inner element <p> wouldn't move down to its parent container <div>.

.col-xs-4{
     position:relative;
}
.col-xs-4 p {
     position:absolute;
     bottom:0;//Even though this setting should move it to the bottom of its 'relative' parent div, it doesn't work as expected.
 }

I eventually found a different solution, but I'm curious to understand why the previous approach didn't work. Could Bootstrap's grid system be causing this issue?

While I acknowledge that similar questions may have been asked before, I couldn't find a satisfactory answer. For reference, here is a CodePen example demonstrating my problem:example link

Answer №1

To optimize responsiveness and avoid disrupting rows and columns, consider utilizing JavaScript to dynamically adjust the height of elements. Here's a sample code snippet that demonstrates this:

<div class="row">
    <div class="col-xs-8 matchheightog">
        <p>long long long long text that generates taller column</p>
    </div>
    <div class="col-xs-4 matchheight">
        <p>shorter text that generates shorter column</p>
    </div>
</div>

Here's the corresponding JavaScript function:

$(window).on("load resize", function () {
   $(".matchheight").height($(".matchheightog").height());
});

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 keep a dropdown list menu next to the selected dropdown button as the user scrolls?

I recently encountered a problem similar to the one on this page within my App. Upon selecting the drop-down list, the corresponding menu opens as expected. However, when the user scrolls down the page, the drop-down menu remains in its original position. ...

Enhance Bootstrap modals by automatically adjusting the background shadow mask when resizing or changing the content within the modal window

Incorporated within my bootstrap modal window is a form alongside a link that triggers the jQuery functionality of .slideToggle(). By interacting with this link, a concealed div expands. Consequently, the size of the modal popover becomes fluid. Upon click ...

Using jQuery AJAX to Transfer Data to a PHP Script

There is a div element with a data-id attribute. The goal is to use jQuery to detect when this div is clicked and then send or store the corresponding data-id value in a PHP file. However, the code provided raises an error when trying to obtain the data-id ...

Display the image in a pop-up window before executing a jQuery script

Lately, I've been focusing on implementing zoom in and zoom out functionality for images. The plugin I've chosen to use is guillotine. It works flawlessly except for one small hiccup. My goal is to integrate it into a website built with angularJ ...

Unable to process Json response in CodeIgniter using JQuery Post

I'm a beginner with Jquery and I'm currently trying to retrieve data from Codeigniter. I used Fiddler to confirm that my controller is sending a valid Json response, but for some reason JQuery isn't triggering the function. Below is my Jque ...

Load jQuery core asynchronously with a backup plan

Exploring performance optimization and non-blocking scripts in the header, my focus has been on asynchronously loading jQuery itself. In my search, I came across a jQuery Loader script that can async load jQuery and then handle and queue jQuery document r ...

Encountering NPM Abortion Issue in Node.js

I am a beginner in node.js and have successfully installed it. However, when I try to initialize npm, I encounter an error that causes it to abort. My system has high memory capacity with 32GB RAM and 1TB HD. Although the 'npm -v' command works ...

Could converting a 47-byte JSON string into 340 MB be possible through JSON stringification?

var keys = [7925181,"68113227"]; var vals = {"7925181":["68113227"],"68113227":["7925181"]}; var temp = []; for (var i = 0; i < keys.length; i++) { temp[keys[i]] = vals[keys[i]]; } //alert(JSON.stringify(vals).length); alert(JSON.stringify(temp).le ...

Encountering a `ECONNREFUSED` error while attempting to dispatch an action in the

I have decided to convert my Nuxt application to SSR in order to utilize nuxtServerInit and asyncData. Below are the steps I followed during this conversion process. Removed ssr: false from nuxt.config.js Dispatched actions to initialize the store's ...

Creating an event listener with a dynamic name

I'm in the process of developing a customizable button bar where I need to attach onclick event listeners to each button dynamically. The functions to be assigned should have names provided by the button's data-function attribute. … <div cl ...

Incorporate a NodeJS express object into AngularJS 1.6

I am currently facing a challenge with passing parameters from a NodeJS API to AngularJS so that I can retrieve data for a specific page. My situation is an extension of the issue discussed in this question: How do I pass node.js server variables into my a ...

Utilize the bootstrap grid to align content into 4 columns evenly

I have the following code snippet: <div class="panel-body"> <div class="col-sm-6"> <label class="head6">Business Name : </label><span class="head9">'.$name.'</span> </div> <div ...

Tips for sending a large list as Ajax data in an MVC model

My morning was spent in vain as I attempted different "workarounds" that were suggested, usually for more specific scenarios than the one I am facing. My goal is to simply pass an ASP.NET MVC model using the JQuery load method. It seems promising when I us ...

Sending an ID from an array within a *ngFor loop to a different component in Angular: a step-by-step guide

I have a collection of items that I loop through using ngFor. My goal is to pass all its attributes to another component. I attempted to accomplish this with the following code: *ngFor='let item of postList [routerLink]="['/detailed-post&ap ...

How to retrieve XML data using the HTML method

This webpage is in XML format. To access the live status information, you can visit Since there is no server-side code available on this free hosting platform, you'll need to perform an HTML GET request to check if ls:islive is true or false. if ...

How to retrieve values/keys from a JSON object dynamically in JavaScript without relying on fixed key names

shoppingCart = { "Items": 3, "Item": { "iPhone 11 Pro": { "productId": 788, "url": "http://website.com/phone_iphone11pro.html", "price": 999.99 }, "Bose Noise Cancelling Headphones": { ...

Issue arising from the lack of direct communication between parent and child elements

I am facing an issue with indirect communication in a react native application. The situation involves a parent component, implemented as a class component, and a child component, which is a functional component. Here is the Parent component: constructor ...

Troubleshooting issue with setting variables in Firefox's JavaScript

I have created a small JavaScript script that defines a value (referred to as stock), which I want to set as the maximum in a dropdown list. It will be set as the maximum value if it exceeds 6. Below is the code snippet: <script type="text/javascript" ...

Vue.js - Exploring methods to append an array to the existing data

I am looking to structure my data in the following way: Category 1 Company 1 Company 2 Company 3 Category 2 Company 1 Company 2 Company 3 Below is my code snippet: getlist() { var list = this.lists; var category this.$htt ...

What is the best way to collapse a button in asp.net using javascript after setting it to hidden?

I have a scenario where I have 3 buttons in a row on my asp.net page. Using JavaScript, I am setting the middle button (ButtonSR) to invisible. However, I want the button below it to move up and take its place instead of leaving an empty space. ...