What is the best way to ensure that two divs always maintain equal height regardless of their content?

Can someone help me solve a layout issue?

I had set the min-width and max-width properties of two images to be the same, but when I changed the image in one of them, it caused an overflow. I removed the max-width property and also tried using the flex-grow property without success. Is there another approach I can take to achieve my desired layout?

#section_body_6.main.container {
  padding-top: 6vw;
  /* padding-right: 3vw; */
  padding-bottom: 6vw;
  /* padding-left: 3vw; */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  background: linear-gradient(rgba(43, 48, 71, 0.4), rgba(43, 48, 71, 0.4)), url("/pix_builder/elements/images/makeup/1.png") fixed no-repeat center;
  background-size: cover;
}

#section_body_6.main .inner {
  height: 100%;
}

#section_body_6.main .inner .widget {
  padding: 1vw;
}

#section_body_6.main .width {
  width: 90%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

#section_body_6.main .inner.image {
  padding: 1vw;
  background-color: #fff;
  width: 45%;
  flex: 1 1 auto;
  text-align: center;
  min-height: 600px;
}

#section_body_6.main .inner.image .logo {
  width: 100%;
  max-width: 150px
}

#section_body_6.main .inner.image .main {
  width: 100%;
  max-width: 300px;
}

#section_body_6.main .inner.text {
  display: flex;
  flex-direction: column;
  background-color: #f7a885;
  padding-top: 2vw;
  padding-right: 3vw;
  padding-left: 3vw;
  width: 55%;
  flex: 1 1 auto;
  min-height: 600px;
  max-height: 600px;
}

#section_body_6.main .inner.text h1 {
  font-size: 56px;
  color: #fff;
  font-family: 'Karla', sans-serif;
}

#section_body_6.main .inner.text p {
  font-size: 20px;
  font-family: 'Karla', sans-serif;
  color: #fff;
}

#section_body_6.main .inner.text .signup {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

#section_body_6.main .inner.text .signup .sign {
  width: 100%;
  max-width: 200px;
}

#section_body_6.main .inner.text .signup .form {
  width: 70%;
}

#section_body_6.main .inner.text .signup form {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

#section_body_6.main .inner.text .signup input {
  padding: 0px 10px;
  color: #020020;
  border: 1px solid #ffffff;
  display: block;
  width: 100%;
  height: 40px;
  line-height: inherit;
  border-radius: 3px;
  font-family: "Karla", sans-serif;
  margin: 1vw;
}

#section_body_6.main .inner.text .signup button {
  background: #2b3047;
  color: #ffffff;
  align-items: center;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  transition: color 0.2s linear, background 0.2s linear, border-color 0.2s linear, text-shadow 0.2s linear;
  text-decoration: none;
  position: relative;
  width: 100%;
  font-weight: bold;
  min-height: 48px;
  min-width: 96px;
  padding: 14px 24px;
  font-family: "Karla", sans-serif;
  border: none;
}
<section id="section_body_6" class="main container">
  <div class="width">
    <div class="inner image">
      <div class="widget">
        <img class="logo" src="https://lh3.googleusercontent.com/uO-2GwlFxWnex3obmZmPi4xmZgdXofKigjih4aH_tmKswH-x56GfWFTB82Yquc6fJhWmNVwoCSDSjgH705-XWnQ=s0" data-image-upload-source="builder3" alt="" style="width:100%;max-width:150px">
      </div>
      <div class="widget">
        <img class="main" src="/pix_builder/elements/images/makeup/5.png" data-src="/pix_builder/elements/images/makeup/5.png" alt="" style="width:100%">
      </div>
    </div>
    <div class="inner text">
      <div class="widget">
        <h1>Look and Feel Perfect Every Day.</h1>
      </div>
      <div class="widget">
        <p>
          Subscribe to my newsletter to get my FREE Every Day Makeup Look guide, PLUS top secret tips and tricks used by the industry’s leading makeup artists.
        </p>
      </div>
      <div class="signup">
        <div class="widget">
          <img class="lp-image-react w-8cdb4d98-8e02-3986-a823-950a991fde05 css-1cg3cc6 sign" src="https://lh3.googleusercontent.com/dmY1Sjs5FSKW-wkI-McMrvHbxsIIzeKI38qUb20rnpXb_llEPPoCudG3xhzuYB12sCn8DpRM_GnUUjCMjsDMiw=s0" data-image-upload-source="builder3" alt=""
            style="width:100%;max-width:200px">
        </div>
        <div class="widget form">
          <form action="#" method="get" target="_top">
            <input type="email" id="email" placeholder="Email">
            <button type="submit" onclick="popup()">Sign-Up</button>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>

Answer №1

After analyzing your code, I noticed that you have a class called #section_body_6.main .inner.image .main where you set the max-width: 300px;, but the height changes automatically. Here is a solution:

#section_body_6.main.container{
    padding-top: 6vw;
    /* padding-right: 3vw; */
    padding-bottom: 6vw;
    /* padding-left: 3vw; */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    background: linear-gradient(rgba(43, 48, 71, 0.4), rgba(43, 48, 71, 0.4)), url("/pix_builder/elements/images/makeup/1.png") fixed no-repeat center;
    background-size: cover;
}
#section_body_6.main .inner{
    height: 100%;
}
#section_body_6.main .inner .widget{
    padding: 1vw;
}
#section_body_6.main .width{
    width: 90%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
#section_body_6.main .inner.image{
    padding: 1vw;
    background-color: #fff;
    width: 45%;
    flex: 1 1 auto;
    text-align: center;
    min-height: 600px;
}
#section_body_6.main .inner.image .logo{
    width: 100%;
    max-width: 150px
}
#section_body_6.main .inner.image .main{
    width: 100%;
    max-width: 300px;
    max-height: 390px;
}
#section_body_6.main .inner.text{
    display: flex;
    flex-direction: column;
    background-color: #f7a885;
    padding-top: 2vw;
    padding-right: 3vw;
    padding-left: 3vw;
    width: 55%;
    flex: 1 1 auto;
    min-height: 600px;
}
<section id="section_body_6" class="main container">
  <div class="width">
    <div class="inner image">
      <div class="widget">
        <img class="logo" src="https://lh3.googleusercontent.com/uO-2GwlFxWnex3obmZmPi4xmZgdXofKigjih4aH_tmKswH-x56GfWFTB82Yquc6fJhWmNVwoCSDSjgH705-XWnQ=s0" data-image-upload-source="builder3" alt="" style="width:100%;max-width:150px">
      </div>
      <div class="widget">
        <img class="main" src="https://www.fabmood.com/inspiration/wp-content/uploads/2020/11/eye-makeup-looks.jpg" data-src="/pix_builder/elements/images/makeup/5.png" alt="" style="width:100%">
      </div>
    </div>
    <div class="inner text">
      <div class="widget">
        <h1>Look and Feel Perfect Every Day.</h1>
      </div>
      <div class="widget">
        <p>
          Subscribe to my newsletter to get my FREE Every Day Makeup Look guide, PLUS top secret tips and tricks used by the industry’s leading makeup artists.
        </p>
      </div>
      <div class="signup">
        <div class="widget">
          <img class="lp-image-react w-8cdb4d98-8e02-3986-a823-950a991fde05 css-1cg3cc6 sign" src="https://lh3.googleusercontent.com/dmY1Sjs5FSKW-wkI-McMrvHbxsIIzeKI38qUb20rnpXb_llEPPoCudG3xhzuYB12sCn8DpRM_GnUUjCMjsDMiw=s0" data-image-upload-source="builder3" alt="" style="width:100%;max-width:200px">
        </div>
        <div class="widget form">
          <form action="#" method="get" target="_top">
            <input type="email" id="email" placeholder="Email">
            <button type="submit" onclick="popup()">Sign-Up</button>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>

Answer №2

One way to achieve this is by including display: flex in the parent element's styling.

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

Ways to automatically fill HTML code with a value from a input on the previous page stored in the URL parameters

Seeking assistance with incorporating a custom query string value from the URL into the default value of my HTML code. I need guidance on how to substitute the placeholder text "URL VALUE" with the actual value retrieved from the URL. https://i.sstatic.ne ...

Encountered a MultiValueDictKeyError in Django at /employeeUpdate/ after making changes to the data

Encountering a django error "MultiValueDictKeyError at /employeeUpdate/ 'id'" after making changes to the data. Here is the code snippet from my views.py: def employeeUpdate(request): id = request.POST['id'] emp_username = requ ...

Displaying both input fields and buttons side by side on mobile devices using Bootstrap

I am in the process of creating a navbar that includes select, input, and button elements. Below is the code I have written: <nav class="navbar sticky-top navbar-light p-0"> <div class="collapse navbar-collapse search-bar show p-4" id="navbarSupp ...

Sharing variables between server.js files - a step-by-step guide

I am currently in the process of creating a sleek weather webpage. I have successfully retrieved weather data from the Open Weather API through a Node.js server file. However, I have encountered an issue where I am unable to pass a variable, such as tempe ...

Learn how to interact with elements in Selenium ChromeDriver by clicking on them even if they have negative x and y pixel locations

I am currently dealing with a website that features pop-up tables triggered by user interaction. These pop-ups contain important data, but occasionally a technical issue arises where the top of the pop-up window is positioned off-screen, making it challeng ...

Tips for writing post loop code in a WordPress theme

I am currently in possession of an HTML theme that I would like to convert into a WordPress theme. The project section of this theme displays posts with a unique structure. My challenge lies in creating a PHP and WordPress function that can replicate the s ...

Alter div elements with jQuery based on the particular link that was selected

I'm struggling with updating a nav bar that has different divs based on the link clicked. <script> $(document).ready(function (){ $("#content").load("content/index_content.php"); $('a').click(function(){ $ ...

What is the process for uploading a text file into JavaScript?

I'm currently facing an issue with importing a text file from my local computer into JavaScript in order to populate HTML dropdowns based on the content of the file. Despite spending considerable time searching for solutions on stack overflow, I haven ...

Changing the cursor while the onDrag event is active in ReactJs

I want to implement Drag functionality on certain elements in my application, but I am facing an issue where the cursor changes during dragging. How can I change the cursor specifically when onDrag is active? ...

A guide on how to modify a CSS property to set the display to none upon clicking a radio button

Currently, I am attempting to display two input boxes in a table when I select specific radio buttons and hide them if I choose another option. The code I have does work but has a minor issue, function disappear() { document.getElementsByClassName("ta ...

Get rid of Sidebar on Product Category Page | Wordpress Ecommerce Theme

Is there a way to remove the sidebar only for specific Product categories "Slug" without affecting their child slugs? For example, when the URL matches the following - remove the side bar and make the page full width only for the slugs "sanitaryware" and ...

Calculate the number of rows in a table that contain identical values

I have a puzzling issue that has been on my mind. I currently have an SQL statement that selects specific rows from my database and displays them in an HTML table, which is functioning properly. However, I now need to determine how many rows have the same ...

Best approach for routing using express

My current project involves using Express to develop a small website. Here is the code snippet I am working with: var package_express = require('express'); var app = package_express(); app.get("/", function(req, res){ res.sendFile(__dirname ...

Is it a universal rule for embedded css to take precedence over external css?

In my previous studies, I had learned that embedded CSS always takes precedence over external CSS. However, I have discovered that the styles that come last in the code actually prevail. Consider the following code snippet where I have used color:green; i ...

Creating various iterations of a single CSS animation

Attempting to animate multiple instances of a cross mark animation can be tricky. The animation works well with one instance, but struggles when trying to create more than one. The challenge lies in controlling the size and position of each cross animation ...

Place text within SVG in alignment

There seems to be an issue with aligning text in Adobe Illustrator when exporting graphics to SVG. When the text is initially exported, it is aligned to the center, but if you change the text using JavaScript from "Default text" to "New text", the alignmen ...

My responsive gallery is malfunctioning. What steps can I take to ensure that the cards become more responsive

I've been following a tutorial from W3 to create a gallery view, but the layout looks terrible on mobile devices. It squeezes three cards into each row and shrinks them down. I checked out Bootstrap's documentation on containers and tried using ...

What is the best way to ensure my content is properly placed across all of my pages?

I could use some assistance, please. I am currently working on my website's structure, but I'm encountering some issues... I have created a file named "page-container.php" and its content is: <!DOCTYPE html> <html> <head> ...

Show singular array element upon click

I need help with a specific task. When a button is clicked, I want to display a random item from an array. Each array item should only be displayed once. Currently, my code is set up as follows: When the button is clicked, a random array item is displ ...

Manipulating the arrangement and alignment of div elements within a designated container

Here is the markup I am working with: <div class="container"> <div class="left-rect"></div> <div class="text">Lorem ispum</div> <div class="right-rect"></div> </div> .left-rect, .right-rect { ...