Setting the maximum height for a div element

Struggling to understand how a div can occupy the entire height of a container. In this particular scenario, I am aiming for the "photo" div to take up the full height, with the yellow and green content appearing on the right side of the photo. Below is the code snippet:

#header {
  background-color:#7b88d2;
  text-align:center;
  height: 20px;
}
#container {
  max-width:800px;
  border-style: solid;
  border-width: 1px;
}
#main {
  width: 100%;
  height: 100%;
}
#photo  {
  float:left;
  background-color:#FF3366;
  padding: 10px;
}
#logo  {
  float:right;
  background-color:#FF3366;
  padding-right: 10px;
  height: 100%;
}
#footer {
  background-color:#669933;
  text-align:center;
  height: 20px;
}
#col1 {
  float: left;
  padding-left: 10px;
}
#col2 {
  margin-left:auto;
  margin: 0 auto;
}
#txt_container {
  padding-left: 10px;
  background-color:#ffffcc;
}
#col3 {
  display: inline;
  float: right;
  padding-right: 10px;
}

I'm hesitant to set the height in pixels since the exact height of the photo is unknown.

Check out the demo here: https://jsfiddle.net/wsfnqvyn/

Your assistance is greatly appreciated. Thank you.

Answer №1

It seems like the issue is a bit random. The size of an image may not always match up perfectly with your div container (whether or not this is important to what you're trying to convey). Consider using the css background method instead.

For example, define the attributes of your .photo class and then add this code snippet to your html file.

<div class="photo" style="background-image: url(image.jpg)"></div>

In this scenario, your .photo class should have at least one line similar to the following.

.photo {
background-size: cover;
}

Keep in mind that this technique may limit certain CSS functionalities in some cases.

Answer №2

I have made some updates to your jsfiddle. You can view the changes in the updated version here: https://jsfiddle.net/wsfnqvyn/6/

To achieve the desired layout, I have utilized display:table and table-cell properties.

#header {
   background-color:#7b88d2;
   text-align:center;
   height: 20px;
}
#container {
   max-width:800px;
   border-style: solid;
   border-width: 1px;
}
#main {
   width: 100%;
   height: 100%;
   display:table
}
#photo  {
   display:table-cell;
   background-color:#FF3366;
   padding: 10px;
}
#logo  {
   display:table-cell;
   background-color:#FF3366;
   padding-right: 10px;

}
#footer {
   background-color:#669933;
   text-align:center;
   height: 20px;
}
#col1 {
   float: left;
   padding-left: 10px;

}
#col2 {
   margin-left:auto;
   margin: 0 auto;
}
#txt_container {
  display:table-cell;
   padding-left: 10px;
   background-color:#ffffcc;
}
#col3 {
   display: inline;
   float: right;
   padding-right: 10px;
}   

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

Using setTimeout with drag and drop functionality in HTML

I need a setTimeout function to be triggered only after dragging and dropping an image into a division, not before the drop occurs. ...

What is the best way to conceal a bootstrap directive tooltip in Vue.js for mobile users?

Currently, I'm tackling a project with Vuejs and Laravel. There's a tooltip directive incorporated that relies on Bootstrap's functionality. Check it out below: window.Vue.directive("tooltip", function(el, binding) { // console ...

Switch to a different webpage based on radio button selections in a PHP script

On my webpage, I have two pictures that act as radio buttons, along with a "proceed" button. However, when I click on the button, it does not redirect to the desired page. Below is the code for my form and PHP processing page: <body> <fo ...

Unable to expand Bootstrap navbar due to collapsing issue

I recently implemented a collapsed navbar on my website using bootstrap. However, I'm facing an issue where it does not open when clicking on the hamburger menu. After researching various solutions for this problem and trying them out, none of them s ...

Information is not appearing in the dropdown menu

As a beginner in JavaScript, this is my first program. I have written HTML and JavaScript code to display data in a dropdown menu from a Python Django database. However, when I run it, the data is not showing up. Here is my code: <!DOCTYPE html> < ...

The mdSidenav service encounters difficulties locating a component within an Angular component

Trying to understand why an Angular .component(), which contains a <md-sidenav> directive, cannot be located from the component's controller. Angular throws the error message: No instance found for handle menu The complete component code is ...

Discovering a CSS value using jQueryUncovering the CSS value with jQuery

Currently, I have a script that allows me to change the color of an event in a calendar to red when clicked. eventClick: function(calEvent, jsEvent, view) { $(this).css('border-color', 'red'); } Now, I want to enhance this featur ...

converting an entire HTML layout into a PDF using JavaScript

I am attempting to convert an HTML design to PDF using the following script: <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.min.js"></script>. I have designed a table to my liking, here is how it looks in HTML: https://i. ...

Is there a way to keep my fixed footer container from moving while zooming in and out on a webpage

Is there a way to prevent the bottom text from shifting when zoomed in or out on the page? The rest of the content remains stable, but due to using position:absolute for this section to stay at the bottom of another div (content), it causes movement. #con ...

Scroll positioning determines the height of an entity

Here's a code snippet I'm working with: HTML: <div id="wrap"> <div id="column"></div> </div> CSS: #wrap { display: block; height: 2000px; width: 400px } #column { display: block; height: 20px; ...

Using jQuery to display the total number of div elements for the selected individuals

Hey there, I'm just diving into jQuery and could use some assistance. I'm attempting to achieve a specific outcome with my code, but I'm running into some difficulties. Hopefully someone can lend a helping hand! Here's the scenario: If ...

Using the onclick event with an image created through PHP code

I am currently in the process of developing a dynamic image represented as a graph displaying the number of documents generated each day. This interactive image is being created using PHP, and I aim to improve user engagement by enabling them to click on t ...

Issue with Angular 6 Animation not showing up

Looking to incorporate an animation spinner into my Angular app Found this spinner example: https://codepen.io/z-/pen/OPzNLz spinner.component.html import { Component, OnInit } from '@angular/core'; @Component({ selecto ...

Acquiring the PayPal callback variable with PHP

When using PayPal Standard HTML form, upon completion of the transaction, the user is directed to the return URL. To retrieve variables such as the user email, order number, and other available information using PHP, I need to utilize the GET method from t ...

What is the best way to determine the number of subchildren within a parent div using JavaScript or jQuery?

Can anyone assist me with counting the number of child divs inside a parent div using JavaScript or jQuery? I'm not very experienced in these languages. Below is my code snippet: $(function () { var parent = document.getElementById('parent& ...

Internet Explorer and Edge browsers are concealing box shadow behind the parent div

When using an input slider range, the box-shadow is being applied to the active thumb in all browsers except for IE & EDGE. In these browsers, the shadow is cutting or hiding behind the parent div #c. I have already tried setting overflow:visible on the p ...

Should I open the Intel XDK hyperlinks in the default web browser instead of

Lately, I've been developing an HTML5 app on the Intel XDK that includes buttons linking to external websites. However, I'm encountering an issue where the apps open in the same window, leading users to get stuck in the browser. Currently, I am u ...

Difficulty with animated presentations

As a developer with limited CSS experience, I am trying to create a CSS3 slideshow using only two images. After discovering some interesting code for this purpose, which can be found here, I decided to make a small change to the original code (specifically ...

Is there a variation in HTML/XHTML/XML code based on different geographic regions?

I have a question regarding the consistency of HTML, XHTML, and XML code across different localizations. If I write code on a system using the "en-us" localization, will it remain the same when rendered on a system with the "sv-SE" localization? For examp ...

Prevent parent from scrolling when hovering over a div in HTML5

Unfortunately, the scrolling attribute is not supported in HTML5. I'm facing an issue where I have an svg inside an iframe within a div, and I need to enable scroll functionality within the div while preventing the page from scrolling at the same time ...