Prevent the responsive image from being cramped by the table cell

I am working with a table that has 1 row and 2 columns. The left cell of the table contains an image with its height set in em (em is defined as 2vh, so it will adjust based on the viewport height). The right cell contains text.

<html>
<head>
<style>
body{
font-size:2vh;
}
</style>
</head>

<body>
<table>
<tr>
<td>
<img src="some.jpg" style="height: 18em">
</td>
<td>
Some text, more text, even more text.
</td>
</tr>
</table>
</body>
</html>

In Firefox and Internet Explorer, the image displays with the correct width and height ratio while the text wraps in the right cell. However, in Chrome and Opera, the right cell adjusts its width to the text causing the image in the left cell to shrink. How can I ensure that the left cell adjusts its width according to the image's calculated width? (The aspect ratio of the image varies.)

The proposed solution discussed a different issue related to adjusting an image to fit a table cell. My concern is specifically about adjusting the cell size based on the image dimensions.

Answer №1

Check out this functional fiddle for a solution that may suit your needs
jsfiddle

CSS:

html. body, table {
    margin: 0px;
    padding: 0px;
}
table {    
    display: table;
    width: 100%;
    table-layout: fixed;
}
table tr {
    display: table-row;
    width: 100%;
}
table tr td {
    display: table-cell;
    width: 25%;
}
.imageTable {
    float: left;
    width: 100%;
}
.autoResizeImage {
    max-width: 100%;
}
<div class="imageTable">
    <table>
        <tbody>
            <tr>
                <td>
                    <img class="autoResizeImage" src="http://www.hhacademy.org/computer-lcd-monitor-vector.jpg" />
                </td>
                <td>
                    <img class="autoResizeImage" src="http://gatelyacademy.org/wp-content/uploads/2014/10/computer-156513_640.png" />
                </td>
                <td>
                    <img class="autoResizeImage" src="http://i.dailymail.co.uk/i/pix/2013/01/07/article-2258276-16C8FB51000005DC-20_638x476.jpg" />
                </td>
                <td>
                    <img class="autoResizeImage" src="http://www.computer-repair-service.co.uk/wp-content/uploads/2013/08/mac-computer.png" />
                </td>
            </tr>
        </tbody>
    </table>
</div>

Answer №2

I've figured it out: The issue lies elsewhere. It turns out that this line was causing the problem in my CSS:

img{
   max-width:100%
}

After some digging, I discovered that this was what caused the strange behavior in Opera and Chrome. For those curious, feel free to take a look at this jsfiddle and compare how Opera and Chrome behave versus Firefox and Internet Explorer: http://jsfiddle.net/martinvie/3moocskt/6/

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

Object vanishing beneath layers despite z-index: 4 (topmost layer)

Despite using z-index: 4 as the highest layer, the element keeps disappearing from the screen. I can confirm that it is correctly applied through the browser console. Any suggestions are appreciated. Please refer to the links below for images (I can' ...

showcasing the picture in the email is consistently

I have created an email system that sends a message to users when they are active in the database, but I am experiencing an issue with the image not displaying. It is important for the image to appear automatically, just like Facebook's logo always sh ...

How can I choose specific options by clicking based on the select name's value with web scraping?

I'm attempting to scrape the select dropdown menu below in order to retrieve its text content. Unfortunately, I can't rely on the name attribute as "P889O1" varies for each product from which I need to extract data. I considered using 'cont ...

Exploring the power of Bootstrap 5 for vertical alignment

I am currently utilizing the flexbox grid from Bootstrap 5 to create a mobile-first Angular web application that is responsive. For the home screen of my app, I want to incorporate these 3 elements : The title of the app displayed at the top A series of ...

Having trouble with the OpenID login functionality

I'm currently working on creating my own openID login for a GAE app, but I've encountered a small issue. Everything works smoothly when testing it on localhost, but as soon as I try to deploy it, things don't seem to run properly. My assumpt ...

Firebug displays the class name and location twice in the right panel

When examining a div labeled with .mlm-clearfix, I noticed that Firebug was displaying this class name and its URL twice in the right panel. The style declarations given for the Easy Clear Method in relation to this class are as follows: .mlm-clearfix:bef ...

Making adjustments to the Bootstrap CSS design by removing certain elements

I have inserted a styling link from Bootstrap into the header section of my page, but it is applying additional styles to my cards which I don't want. Is there a way to eliminate these unwanted styles without removing the Bootstrap CSS link? Below, y ...

Optimizing Bootstrap for Tablet Browsing in Internet Explorer

Hey there, I have a question regarding Internet Explorer and tablets. As I revamp this website and integrate Bootstrap into it, my focus is currently on the small-sized IE browser for tablets. My dilemma arises from not knowing if there are any tablets th ...

Utilize class attributes inherited from a separate SCSS file

I am attempting to inherit the characteristics of a class called AClass from a file named A.scss into another file, B.scss, and make some changes to its properties based on my needs Let's assume that A.scss contains: .AClass{ border-radius: 20px; ...

Retrieving the chosen item from an unordered list using jQuery

Hello, I am currently populating a list using the ul-li HTML tags dynamically. My goal is to retrieve the value of the selected li within the corresponding ul. Despite trying various jQuery methods, I keep getting 'undefined'. Here is how I popul ...

Divergence in image positioning with CSS on Firefox and Chrome

My struggle lies in achieving image alignment consistency across different web browsers: https://i.sstatic.net/367Dz.jpg I suspect it may be an issue with the borders? Query: Should I resort to using a media query to tackle this issue effectively? Curre ...

Monitor File Tool for JetBrains IDE - CSS Optimization Setup - Streamline CSS Automatically

Utilizing the File Watcher tool in Jetbrains IDE (Webstorm and Rider) to automatically minify .css files and generate corresponding .min.css files for the entire project has been my goal. However, a challenge arises when it starts minifying files that alr ...

What is the best way to incorporate transition effects into images as they appear on the screen?

I'm currently working on my React app and trying to add effects to images when they appear on the page. I have tried using the code below, but it doesn't seem to work as expected. I directly applied styles to the div tag because I couldn't g ...

How can text be concealed within an input field?

My degrees converter code is functioning well, but I have an issue. When I input a number for one temperature type, the conversion for the other two types is displayed correctly. However, if I then enter a number for another temperature type, the previous ...

Angular: Generating components dynamically in HTML is unsuccessful

I possess the capability to dynamically generate components: import { Component, ComponentFactory, ComponentFactoryResolver, ComponentRef, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; import { FilterComponent } from '../filter ...

Website experiencing issues with image sizing

On my website, in the Current Books section, I have a row of images. To ensure that all the images are the same height, I initially set the height of the HTML book image to 378 using: <img alt="HTML & CSS" height= "378" src="html.jpg"> Using ...

Finding and Selecting Dynamic CSS Elements with CSS Selector Techniques

Utilizing a tool called Stonly for adding tooltips, the CSS Selector is used to locate the HTML element for identifying the tooltip. Depending on the user input, a dynamic task list is generated. The challenge arises when trying to pinpoint a specific task ...

Transforming an HTML jQuery contact form into an ASP.NET solution

I have developed a contact form using HTML5, Bootstrap, and jQuery. The form includes hidden fields that are only displayed when the user selects a radio button. I have implemented validation to ensure that the hidden fields are not required to be filled o ...

What is the reason behind Flask's choice to return <embed> files for download rather than simply displaying them

When I try to render a template using Flask that includes images, the files are being downloaded instead of displayed. For example, <embed src="static/yes.svg" type="image/svg+xml"> If I place this code inside test.html and view it in Google Chrom ...

The image zoom function is malfunctioning when trying to adjust the image position

Having some trouble with a code for image zoom in/out. When I adjust the position of the image by applying margin left to either the image or the image container (#view), it affects the zoom functionality - causing the image to move to the left during zoom ...