Ensure that the image within the child div occupies the entire height of the parent div

I'm having a bit of trouble figuring this out and could use some input:

  • There's a parent div with an unspecified height, determined by its content.
  • Inside this parent div are two 'child' elements; however, I want only one to dictate the parent div's height.
  • The other child div contains an image that should occupy 100% of its container (height based on the parent div’s height) using the "inherit" value for the height property.

Here's an image for reference: https://i.sstatic.net/Ccb4d.png

Everything is working well as intended until I add the image. It either fails to fill the container's full height or causes overflow, altering the parent div's height (something I'd like to avoid).

This is the code without the image:

.parentDiv {
  width: 100%;
  background-color: grey;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.imageDiv {
  width: 50%;
  height: inherit;
  background-color: orange;
}
.contentDiv {
  width: 50%;
  background-color: lightgreen;
}
.contentDiv p {
  padding-left: 15px;
  padding-right: 15px;
}
<div class="parentDiv">

  <div class="imageDiv"></div>

  <div class="contentDiv">
    <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
      dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
  </div>

</div>

This is after adding the image:

.parentDiv {
  width: 100%;
  background-color: grey;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.imageDiv {
  width: 50%;
  height: inherit;
  background-color: orange;
}
.imageContainer {
  width: 100%;
  height: 100%;
}

.imageContainer img {
  width: 100%;
  height: 100%;
  
  object-fit: cover;
}

.contentDiv {
  width: 50%;
  background-color: lightgreen;
}
.contentDiv p {
  padding-left: 15px;
  padding-right: 15px;
}
<div class="parentDiv">

  <div class="imageDiv">
  
    <div class="imageContainer">
      <img src="http://www.unoosa.org/res/timeline/index_html/space-2.jpg">
    </div>
  
  </div>

  <div class="contentDiv">
    <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
      dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
  </div>

</div>

A solution might be setting the image as a background-image, but I prefer not to do it that way. Could someone kindly assist with achieving this approach instead?

Thank you!

Answer №1

Give this a shot,

.mainContainer {
  width: 100%;
  height:300px;
  background-color: grey;
}
.imageSection {
  width: 50%;
  height: inherit;
  background-color: orange;
  float:left;

}
.imageHolder {
  width: 100%;
  height: 100%;
}

.imageHolder img {
  width: 100%;
  min-height: 100%;
  }

.textSection {
  width: 50%;
  height:100%;
  float:left;
  background-color: lightgreen;
}
.textSection p {
  padding-left: 15px;
  padding-right: 15px;
}

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 your localhost contact form experiencing issues?

I am receiving an error even though I believe I have done everything correctly. I am currently using localhost, could that be the issue? If not, what else could it be? The error is occurring on this line: $name = $_POST['name']; Here is the co ...

Obtain Data for Visualizing Graph with JSON within a Database-connected Graph (highchart.js)

In the process of creating a database-driven graph, I am utilizing libraries from Codepen. These libraries include: THIS and Highchart.js The HTML file on display simply showcases the chart, while the main data processing is handled in an index.js file t ...

Using @font-face with Rails version 2.3.8

Hello, I am having trouble including a custom font in my Rails application. I am currently using Rails 2.3.8. I have placed my font folder in the public folder and below is my CSS code. However, it seems to not be working. Can anyone provide some assistan ...

How to make a static div adjust its size in the presence of a neighboring div

I am looking to create a feature where the user can click a button to reveal a new div to the right of an existing one. Check out this Fiddle for reference: http://jsfiddle.net/AV2mZ/. While the functionality works fine when both divs are visible, resizin ...

JavaScript fails to function properly on FireFox

I'm currently troubleshooting a script that works in Chrome but not in FireFox. I suspect it's due to the webkit syntax, so I tried converting it to a standard gradient without success. Can you help me identify what's causing the issue? Web ...

The buttons are not resizing to fit the entire table cell

I'm currently working with Bootstrap 4 and trying to place buttons in a table cell for each row. However, the buttons are not expanding to fill the available space and appear squished. This issue persists even when I switch to mobile view. From the p ...

Is there a way to modify a CSS class in Chrome that is only visible when I perform a drag action?

For the website project I am working on, I have an element that only changes its style when I drag something over it. This is achieved by adding a CSS class to it. However, editing this style has proven to be challenging because I cannot live edit it in C ...

Different methods for adjusting CSS properties that are dependent on other components

I'm currently working on a website using the React library. While I have made progress, I am stuck on how to adjust CSS properties that are interdependent. Specifically, I need help removing the blur filter from my text area .mirror-container which is ...

Error in HTML: The AgGrid component is missing the required 'col' attribute

Initially, I worked with the 2.3.5 version of Ag-Grid which had a "col" attribute showing the relative index of the column for each cell element. The "row" attribute still remains unchanged. However, after upgrading to version 4.0.5, the "col" attribute ...

Activate the textbox without utilizing `.focus()` method

I am encountering an issue with a small iframe on my page. The content within the iframe is larger than the window itself, requiring users to scroll around to view it in its entirety. Within this iframe, there is a button that, when clicked, triggers an an ...

What are some ways to maintain the aspect ratio of an image with two dimensions?

Issue: The image is taller than the img-box container https://i.stack.imgur.com/zDBLM.png I have identified two potential solutions, but I am not satisfied with them: Removing the img-box wrapper Applying max-height and max-width properties to the img t ...

What is the most efficient way to calculate the total sum of all product amounts without using Jquery?

I am working with a dynamic table where data is inserted and the total of each product is calculated by multiplying the price by the quantity. What I need now is to get the sum of all the totals for each product. You can see how the table looks here: htt ...

How about designing a button with a dual-layered border for a unique touch

Looking for a specific button: My attempted CSS code that's not working: button { font-family: 'Ubuntu', sans-serif; font-size: 1em; font-weight: bold; color: white; border: 3px double #f26700; background: #f26700; ...

Interactive pop-up window featuring a top section, main content, and bottom section

I have a situation where I've created a modal with sticky headers and footers, and the middle section scrolls based on the content. Everything looks great on Desktop, but when viewed on mobile or tablet devices, the footer is stretched and not fully ...

Can text automatically adjust its size based on the browser's dimensions using CSS?

Can text automatically resize as the browser size decreases for liquid-based design using percentages? While images and divs can rescale, text scaling in percentages seems impossible! When set in percentages, it only changes the unified em setting for tha ...

Is it possible to customize the arrow on a drop-down menu?

Here is an example of the page I am facing issues with: If you look at the right side of the bottom bar, you will notice a selection option for different themes. I have been attempting to replace the down arrow with an image. Below is the code I have used ...

Adding turbolinks to an HTML document can be achieved without the need for a

Recently delving into the world of turbolinks, I discovered that it can be employed independently without relying on a client-side javascript framework. Eager to test this out, I created a bootstrap 4 template and attempted to install it. Firstly, I downl ...

Managing both clicking and hovering events on a single element, ensuring that the popup modal remains open as long as it is being hovered over

After successfully implementing click and hover functionality on an element, I was able to position the popup relative to the mouse pointer based on a previous solution. However, I am now facing an issue where I want the popup modal to be fixed in a specif ...

Is there a method to iterate through an HTML quiz in order to extract text from "label for" with the value of "true"?

I need assistance with extracting all the correct answers from a multiple choice radio button quiz. The correct answers are identified by the attribute value="true" in the HTML code. Is there a way to iterate through and retrieve the text of all the corr ...

Delete the gridline of the column

I'm struggling to remove the border that is encircling my image thumbnail label. I attempted to create a new class "noborder" and added it under my .col-md-4.noborder css rule, setting the border to 0 none and box-shadow to 0 none but unfortunately it ...