Ensure that two div elements are always aligned, regardless of the circumstances

Is it possible to ensure that my two divs are always aligned, regardless of the content inside them? Sometimes the left div may contain images of varying sizes, while the right div may have text with different lengths. I initially tried setting a min-height on both divs, but I'm not sure if this is the best approach.

You can view the code on JSFiddle here: https://jsfiddle.net/532cmwLb/

Here is the original code:

<div class="col-sm-6">
    <div class="alert alert-light border clearfix" role="alert">
        Modification de la photo - Taille de l'image : 592 * 398 pixels
    </div>

    ... (rest of the original code) ...

---------- Correction i used ----------

<div class="container-fluid pt-3 pb-3">
  <div class="row">

    <div class="col-sm-6 order-sm-1 mb-3">

      <div class="alert alert-light border h-100" role="alert">
        Modification de la photo - Taille de l'image : 592 * 398 pixels
      </div>

    </div>

    ... (rest of corrected code) ...

  </div>

</div>

(The HTML5 and Bootstrap 4 were used in this code)

Answer №1

If your row layout is dynamic, consider wrapping each element in a column class within the row layout to ensure equal heights for each column div in the current flex row.

The default order of your supplied code layout is as follows...

  1. alert 1 by default order-1
  2. biopic_post by default order-2
  3. alert 2 by default order-3
  4. text_post by default order-4

By wrapping each element in a column class, it will look like the example below:

https://jsfiddle.net/joshmoto/qw7eto3j/

Here's how you can use bootstrap's order classes to rearrange these divs within the current row.

https://getbootstrap.com/docs/4.5/layout/grid/#reordering

In this example, I've re-ordered the column divs as follows...

  1. alert 1 is now set to .order-sm-1
  2. biopic_post is now set to .order-sm-3
  3. alert 2 is now set to .order-sm-2
  4. text_post is now set to .order-sm-4

These orders will be used on screen size sm and above.

In the demo below, I've removed -sm from all classes for the ordering and column sizes to work properly in the live demo.

https://jsfiddle.net/joshmoto/eja0g4kh/1/

Check out this fiddle with the original responsive breakpoint classes and ordering classes applied.

https://jsfiddle.net/joshmoto/6zpu93tn/

Test this responsively to see the change from xs to sm window width.

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 update the page based on the user input from a prompt?

In my previous question, I was instructed to convert my variables into strings, which I did. However, despite making these changes, the code is still not functioning as intended. The purpose of this code is to prompt the user to select a mood from 1-10, wi ...

Show the form for user input

I have an HTML code for a form that requires input. Once the 'OK' button is clicked, the values are sent to a PHP script using $_POST. Is it possible to display the same form again if the input format is incorrect, but do so only within my PHP sc ...

Adjust the positioning of an element to the right within another element

Having some difficulties with my calendar app as I am unable to position the date square to the top right. I have tried using float:right and align-text: right but it has not worked. Here's a jsfiddle link along with the code: Styling (CSS) table.ca ...

Sequentially display and hide jQuery divs without any overlap

I'm in the process of developing a feature where a series of divs are displayed sequentially after clicking a button. Simultaneously, I am also enabling webcam capture and sending the picture to a server. The functionality is mostly working as intende ...

What could be the reason for the child element not occupying the full height of its parent container?

* { padding: 0; margin: 0; box-sizing: border-box; } body { margin: 50px; } .navbar { display: flex; align-items: center; justify-content: center; color: darkgreen; font-family: 'Vollkorn', serif; font-size: 1.2rem; font-w ...

Before beginning my selenium scripts, I need to figure out how to set an item using Ruby in the browser's localStorage

Before running my selenium scripts, I am attempting to store an item in the browser's localStorage. I attempted to clear the local storage using this command: driver.get('javascript:localStorage.clear();') This successfully cleared the lo ...

Creating a div overlay triggered by the addition of a child tag

Using the Paypal zoid feature, I have a button that opens an iframe in the parent div when clicked. However, the iframe causes the other contents of the website to shift around, making it look messy. I'm wondering if there is a way to make the parent ...

The process of redirecting a web page using htaccess and incorporating URL parameters

I have a directory where I store HTML pages. Using the PHP include function, I am adding these pages to my index.php file by referencing them with a URL parameter value. The URL parameter "xpage" corresponds to the page names stored in another folder, whil ...

How to centrally align the navbar-brand when the navbar is collapsed in Bootstrap 5

Is there a way to align the navbar Brand in the center when the navbar is collapsed, while keeping it on the left or right side when the navbar expands in Bootstrap 5? ...

Tips for adjusting the color using inline CSS

Currently, I have a div styled with blue color using CSS. However, I now require the ability to dynamically change this color. My plan is to retrieve the desired color from a database and use its hexadecimal code in place of the default blue. What is the ...

Experiencing difficulties with incorporating cURL data into MySQL using Simple Dom Parser

Hey there! I'm currently trying to figure out the best way to save my scraped data to a MySQL database. It seems like nothing is getting inserted into the database, and I suspect it might be due to the format of the data I'm passing. Should I con ...

What is the best way to combine a string with a variable in sass?

Is there a way to merge a string and a variable in Sass to form a variable name that is already present? $size: "sm"; $button-sm: 1rem; $buttom-md: 1.5rem; body { font-size: $button-#{$size}; } The desired output is: body { font-size: 1r ...

The navigation and title refuse to align in the center

Learning coding from scratch is a challenge, especially when tasked with creating a website for school. Right now, I'm gradually getting the hang of it, but I am struggling to center my navigation and title. Everything looks fine on my 13-inch laptop, ...

Utilizing button clicks to send fetch commands and extract data from websites

I need help with my Google Chrome extension. I have some fetch commands for an API, but I'm not sure how to send them when a button is clicked. Can someone guide me on the right approach? Is there a recommended method for a Chrome extension to extrac ...

Looking for a solution to toggle the visibility of a div based on whether search results are found or not using JavaScript

Running this code <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Searc ...

Is there a way to prevent the content in the <p> tag from wrapping and hiding its overflow?

Is there a way to use tailwindcss to ensure that the first <p> child truncates or hides overflow as its container shrinks? I've tried using classes like whitespace-nowrap and overflow-hidden, but the text always wraps regardless. Any suggestions ...

Employing jQuery, how can one assign attributes to appended HTML and store them

So, I am currently working on a backend page for managing a blog. This page allows users to create, edit, and delete articles. When the user clicks the "edit" button for a specific article named 'foo', the following actions are performed: The ...

The utilization of Server.Execute leads to inaccurate HTML rendering exclusively on IE9

Issue - I am encountering a problem with the rendering of a page in different versions of Internet Explorer. The page contains multiple nested div elements, and when calling server.execute within one of the child divs, the output is being displayed incons ...

What's the HTML counterpart to a CSS style sheet?

Is there a way to include a navigation div in all HTML documents without having to repeat it in each one? I'm looking for a solution that doesn't involve adding the entire div to every document, similar to how CSS stylesheets work. I am unaware ...

When hovering or mousing over, the text remains stationary and does not follow the scroll bar movement within the

A method I am using involves displaying additional data on hover for a shortened header, like this: Hover behavior However, the text shifts across the page when the scrollbar is used, as shown here: Scrollbar interaction This table showcases HTML, CSS, ...