Increase the height of the div to align with the height of the other div

Is there a way to use CSS to automatically adjust the height of both the right and left <div> elements so they fill the background-color based on the greater height, without setting a specific height for either?

The left <div> can vary in height depending on the content provided.

I attempted using height: 100%, but it did not produce the desired result.

It is necessary to utilize the float property and avoid table / table-cell properties.

I came across a discussion where suggestions involved defining a height value. However, my goal is to achieve this without specifying a fixed height.

Below is the structure of my HTML:

<div class="wrapper">
    <div class="photo">
        //image dimensions restricted by css rules
        <img class="photo_dimensions" src="{{ name_details_photograph_url }}" />
    </div>
    <div class="details">
        Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />
    </div>
</div>

Here is my corresponding CSS:

.wrapper {
    width:100%;
    height:100%;
    border:1px solid;
}
.photo {
    height: 100%; 
    background:blue; 
    float:right;
    vertical-align:top;
    text-align:center;
    padding:2px;
}
.photo_dimensions {
    max-height: 149px;
    max-width: 149px;
}
.details {
    width:auto;
    height:auto;
    background:red;
    overflow:hidden;
    vertical-align:top;
    text-align:left;
}

Current visual representation of the layout is as follows:

Answer №1

To make the background expand, apply it to .wrapper.

Check out the JsFiddle Demo here

.wrapper {
    background: yellow;
    overflow: auto;
}
.photo {
    float: right;
}
.details {
    background: pink;
    overflow: auto;
}
<div class="wrapper">
    <div class="photo">
        <img src="//dummyimage.com/100"/>
    </div>
    <div class="details">
        Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q<br />Q
    </div>
</div>

Answer №2

Creating a table-like layout using non-table elements is achievable:

<section style="display:table">
    <div style="display:table-cell"></div>
    <div style="display:table-cell"></div>
</section>

This method allows the contained divs to function as table cells with equal heights.

Answer №3

Adjusted the .wrapper height to take on a value from .details using jQuery Check out the updated code here: http://jsfiddle.net/0doo7L6L/1/

Does this meet your requirements? Remember to specify a height for html & body in order for 100% height to work correctly

html,body {
height: 100%; 
}

http://jsfiddle.net/0dL6L7o/

Answer №4

You should opt for a fixed height for the div. Please find below the revised code.

<!DOCTYPE html>

.wrapper { width:100%; height:100%; border:1px solid; } .photo { height: 150px; background:blue; float:right; vertical-align:top; text-align:center; padding:2px; } .photo1{ height: 150px; background:red; float:left; vertical-align:top; text-align:center; padding:2px; }

.photo_dimensions { max-height: 149px; max-width: 149px; } .details { width:auto; height:auto; background:red; overflow:hidden; vertical-align:top; text-align:left; }

//image has max-height: 149px & max-width: 149px; assigned in the css file Q
Q
Q
Q
Q
Q
Q
Q
</body>

On the right side, we have two divs considered: 1) One with full height and width with a specified background. 2) The photo and its child div positioned within the first one.

Answer №5

To achieve the desired effect, set the .wrapper to have a position: relative property.

You may also find this related article helpful: Tips on making a floated div occupy 100% height of its parent element

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

Is it possible to trigger a winform function from an HTML page?

Looking for assistance with my WinForm application that includes a C# WebBrowser control. The WebBrowser control loads an HTML page which features a button. I am seeking a way to trigger a function in the WinForm (such as Form1.cs) when this button is cl ...

Spinning an object using JQuery

I am currently working on a project to test my skills. I have set up a menu and now I want to customize it by rotating the icon consisting of three vertical lines by 90 degrees every time a user clicks on it. This icon is only visible on smartphones when t ...

Is there a way to keep track of changes in multiple dropdowns without having to create a separate JavaScript function for each one

I'm looking for a way to dynamically add more dropdowns as my website grows without having to keep adding new functions to the JavaScript code. Is there a solution for this? Currently, I can add additional functions to the JavaScript like this: ...

Adjusting the width of a <div> element based on window size changes

So I have this Vuejs application that has three divs using CSS grid: a sidebar, a config panel, and a preview. I want to dynamically set the width of the preview div in pixels based on the current screen size and when the screen is resized. To give a bett ...

Having trouble importing Google Fonts using Styled Components and Next.js?

I encountered an issue while attempting to load Google Fonts. I came across a solution that suggests adding the following code snippet in _document.js to import it within a head tag: import React from 'react'; import Document, { Html, Head, Main, ...

Building a dynamic mega menu using Bootstrap

Looking to enhance our ERP application with a mega menu feature. Does anyone have a link to a free Bootstrap mega menu template? I've searched on Google but haven't been able to locate the right one. ...

How to set up a multi-select box for tagging purposes

I tried to implement a multi select box to create tags using the code below. I downloaded select2.min.css and select2.min.js from https://github.com/select2/select2, then copied them into the project's css and js folders. Here is the HTML code snippe ...

Tips for resizing all HTML elements when adjusting browser window dimensions

I am working with the following HTML code snippet: <div id="sectionOne" class="container-fluid d-flex flex-column justify-content-center align-items-center" style="height: 80vh;"> <div class="row d-flex justify-content-center" style="color: #00 ...

Achieving a Photo Grid Layout with CSS

Looking for help with my CSS photogrid - it's close to what I want, but not quite there. Here's the layout I'm aiming for: 1 | 2 | 3 4 | 5 | 6 But currently, it displays like this: 1 | 3 | 5 2 | 4 | 6 I've tried tweaking the CSS but ...

Styling your content directly in the CMS using inline CSS

I can't help but wonder about this question. I take great pride in the cleanliness of my code and despise using inline styles, yet I have stumbled upon a situation where it seems unavoidable. Within my CMS, I am developing a feature that allows user ...

Managing jQuery cookies through the click actions of various elements

Can anyone assist me in setting and removing cookies with a simple click event? This is my HTML structure: <button id="listing_123" class="add-listing">Add to Itinerary</button> <button id="listing_456" class="add-listing">Add to Itiner ...

Rotating an object with the mouse in three.js without relying on the camera movements

I am working on a project where I need to create multiple objects and rotate each of them individually using the mouse. While I have been able to select an object with the mouse, I am facing challenges when it comes to rotating them with the mouse. Cur ...

Tips for selecting a value from <ul> <li> tags in Selenium with Java

I am encountering an issue with something. I am working on two equations within . The first equation is 2+2 and I validate it, then the second equation is 3+3 and I validate that as well. The validation for the first equation is successful and I use the f ...

If a popup is present on the webpage, be sure to close it

I'm facing the challenge of scraping data from a website. Sometimes, the web page displays a security dialog box before redirecting to the login page. To handle this scenario, I attempted to close the popup dialog using this code: Dr.FindElementByCss ...

Combining 2 rows in an HTML table: A step-by-step guide

Can anyone help me figure out how to merge the first row and second row of a table in HTML? I have already merged two rows, but I am having trouble merging the first and second rows together. This is how I want my rows to be merged: |-------------------- ...

Alignment of inner div within the footer

I'm struggling to align my footer navigation inline with my footer title. Check out this code snippet to see what I've tried so far: https://jsfiddle.net/nkzsufov/ I experimented with using absolute and relative positioning: .footerNav { margi ...

Executing PHP code from Javascript - Using AJAX to retrieve full HTML content of the webpage

As someone who is still getting to grips with PHP, I have been exploring ways to call a PHP method from a button. It seems that one approach involves assigning the button's onclick event to trigger a JavaScript function, which then uses Ajax to post t ...

Guide on transferring href parameter from the parent Vue component to the child component

Hey there! I've been working on creating a Vue page, breaking it down into components, and populating it with content from json. It all seems pretty straightforward, but I've hit a snag. Why is the href parameter not showing up in the right place ...

Styling for older versions of Internet Explorer (IE10 and earlier)

Could it be true that IE 10, 9, and others no longer support conditional statements? Is it also accurate to say that JQuery does not support the browser object above version 1.9? I am facing an issue with CSS rendering differently in Chrome and IE. A Goog ...

Adding AngularJS modules to an HTML file

Recently, I've been diving into the world of AngularJS, but I'm facing a roadblock - my HTML doesn't recognize the angular module I created. It's odd because the bindings work perfectly without involving the module... This is my HTML: ...