Modify the height of an image within a container using the display property set to table-row

I'm working on a layout that includes a footer always at the bottom with a variable height. I have placed an image in the center div and I want it to adjust if the screen size is too small.

Here is an example:

CSS

html, body {
  width:100%;
  height:100%;
  margin:0;
  padding:0;
  text-align:center;
}

HTML

<div style="display:inline-block; height:100%;">
<div style="position:relative; display:table; height:100%;">
    <div style="position:relative; display:table-row; height:50px; background:#fc0;">header with fixed height</div>
    <div style="position:relative; display:table-row; height:100%; background:#FFC6C7;">
    <img src="https://s32.postimg.org/jhsgkm4o5/nuage_525x350.jpg" style="vertical-align:middle; max-width:100%; max-height:100%; width:auto; height:auto;">
    </div>
    <div style="position:relative; display:table-row; height:1px; background:#CDFFDD;">
    footer with variable content<br>can be multiline
    </div>
</div>

https://jsfiddle.net/usualuser/5pd5jmLv/

In the provided example, the image adjusts its width and height when the screen's width is too small. However, if the screen's height is too small, a scroll bar appears. Is there a way to make the picture smaller instead of having the scroll bar?

Is there a solution for this issue?

Answer №1

Inserting the following line into your code will adjust the width and height of your img based on the dimensions of the parent div. However, resizing your browser manually may cause the image to shrink and not look very appealing since the height is also set to 100%.

<img src="https://source.unsplash.com/random" style="vertical-align:middle; width:100%; height:100%;">

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

When I adjust the height to 100%, Google Maps fails to show up on the screen

When I try to set the height of the gmaps div to 100%, nothing appears on the screen. I am able to set the width to 100%, but for some reason, setting the height to 100% does not work. If I set a specific height like 400px, it works fine. Below is the cod ...

Updating the jQuery mobile webpage

I have set up a small demo with two pages - the Home page and the Team 1 page. By clicking on the navigation menu, you can navigate to the Team 1 page from the Home page. However, if you are already on the Team 1 page and click on the Team 1 button again ...

Tips for creating a 3D illusion by coding a div or object to rotate around another object or div

I have reached a technical and intellectual roadblock. The issue at hand is this: I need the text to encircle an image and create the illusion that it is moving in front of or behind the image, while keeping the image static. Currently, 1) the rotating te ...

Center the radio buttons regardless of the length of the text

My dilemma lies with 3 radio buttons and their corresponding labels - while 2 of them are aligned perfectly beneath each other due to their matching character lengths, the middle one extends further making it look misaligned. Check out this fiddle. Below ...

What crucial element am I overlooking in the React Transition Group Component while implementing it for a carousel design?

I'm trying to add a feature to my Carousel where the opacity changes between images. When clicking on the icons, the images should transition smoothly. I've been using React Transition Group, but for some reason, it's not working as expected ...

Unable to connect List to dropdown in angular

Having trouble connecting dropdown with a List in AngularJS: <select> <option ng-repeat="x in list">{{x}}</option> </select> app.controller('myCtrl', function($scope) { $Scope.list=[{id:1, name='name 1' ...

Asynchronously load an AngularJS controller from AJAX without altering the route

I am looking to dynamically load an Angular controller after making an AJAX call that generates a new view in HTML. Here is the setup I currently have: Example of a View: HTML Snippet From AJAX <!-- CVS Pharmacy Extracare - Add View --> <d ...

Media queries in JavaScript allow developers to adjust the styling

I'm facing an issue with reducing the size of a cube on smaller screens using media queries. I have implemented media queries in JavaScript because my cube size is defined in JS. However, the cube size remains the same even when I resize the browser w ...

CSS animations using keyframes to continuously move text from left to right

I've been experimenting with text animation, and I've noticed that at the end of the animation, there is a sudden transition cut. What I'm aiming for is to have the text continuously shifting. text { animation: scrollText 5s ...

When you zoom in or out, HTML5 elements styled with CSS will dynamically adjust

Hey everyone, I have a question about a problem I'm facing with my HTML and CSS page. The issue is that when I zoom in, the "Section" part moves underneath the nav bar, and when I zoom out, the footer moves next to the section part... Below is a sni ...

Execute functions during jquery's .animate() operation

This is a snippet of code I use to smoothly scroll the browser back to the top: $('html, body').animate({scrollTop: 0}, 500, "easeOutQuart"); Now, I am looking for a way to prevent the user from scrolling while this animation is running. Once t ...

Creating an HTML table with multiple styled images is a simple process that can greatly enhance the

I am experiencing difficulty with arranging images The primary goal is to achieve this layout: ---------------———————- Table header ----------------—————— | Img1 | | img4 | -------| Img3 |--————— | Img2 | ...

"Setting a maximum height for a div element, along with nested divs and paragraphs

.wrap { width:400px; height:200px; border:1px solid #000; } .content { width:300px ...

Guide on changing image source using a function

I am looking to dynamically set the img src="" attribute using a JavaScript function that changes the image based on a variable and checks its values: Here is the JavaScript code in the file: function myFunctionstatus(){ var ledactual = document.getE ...

"Enhance your website with a dynamic hover effect and striking letter spacing in

In the div below, there is a span with the following code: <div class="mission-button"><span class="mission">view our mission</span></div> Accompanied by this CSS: .mission-button::before { content:'&ap ...

Crafting an innovative horizontal CSS spotlight using conic-gradient styling

Seeking advice: I need to implement three spotlights on a webpage One shining directly downwards One angled from the left to the upper-top One angled from the right to the upper-top I managed to create a vertical spotlight using CSS conic-gradient, but I ...

How can I transfer a particular data value from a div to JavaScript within Laravel 5.0?

Displaying separate square divs based on integers retrieved from the database. This is the front-end view. I want to pass the room ID (code) to a JavaScript function when clicking on these div elements. https://i.stack.imgur.com/aIYTr.png Below is my cur ...

Locate/place name with AngularJS and Google Maps integration

I need help locating the user-selected location on a map. I currently have the latitude and longitude, but I'm struggling to obtain the location name. My project utilizes angularJS along with angular-google-maps 2.1.5. Below is the HTML code: <u ...

Tips for enabling resize functionality on individual components one at a time

Check out my Codepen link for the resizable event While using Jquery UI resizable, everything is functioning correctly. However, I am now looking to have the resizable event activate one block at a time. When another block is clicked, the resizable event ...

What is the best way to include a parameter in the current URL in Django using Paginator?

After setting up a page to display database data, I added a paginator and a search bar to my website. When a user searches for something, the URL changes to include the search query like this: .../search/?q=xyz However, when paginating the search results ...