the table image does not resize correctly in mobile view

I need to resize an image inside a table's <td> when the screen size is in mobile mode. Although I have already added a viewport, my mobile query works correctly for other purposes except for the image. Here is the HTML code:

<table class="table borderless">
      <tr>
      <td align="center" width="10%"> <img width="55%" class="img" src="images/save energy.png"></td>
      <td><h4>Save on Energy Costs</h4>
          <p class="pindent">TEST TEST TEST TEST TEST TEST TEST TEST TEST</p>
      </td>
      </tr>
      <tr>
      <td align="center" width="10%"> <img width="55%" class="img" src="images/save environment.png"></td>
      <td><h4>Save the Environment</h4>
          <p class="pindent">TEST TEST TEST TEST TEST TEST</p>
      </td>
      </tr>
      </table>

Below is the CSS code for my mobile query:

@media (max-width: 600px) {
    table {
        width:95%;
    }
    .custom-box{
        margin-left: 10px;
        margin-right: 10px;
    }
    .margin-box {
        padding-bottom: 10px;
    }
    .cust-box {
    margin-left: 0px;
    }
    .carousel-inner{
     max-height: 500px !important;
    }
    .img {
    max-width: 100% !important;
    height: auto;
    border-radius: 50%;
    -webkit-transition: -webkit-transform .8s ease-in-out;
    -moz-: -moz-transform .8s ease-in-out;
    transition: transform .8s ease-in-out;
    }
    .img:hover {
    -webkit-transform: rotate(360deg);
    -moz-: rotate(360deg);;
    transform: rotate(360deg);
    } 
}

Answer №1

Your query about resizing the image is a bit unclear to me, but it seems like you want to set it to 100% instead of the current 55% defined in the inline CSS.

To achieve this, simply add width:100% to the .image class within your media query. This will override the existing width:55% setting.

Alternatively, you can specify any custom width for the image based on your requirement.

Refer to the code snippet below or check the live demo for implementation.

@media (max-width: 600px) {
    table {
        width:95%;
    }
    .custom-box{
        margin-left: 10px;
        margin-right: 10px;
    }
    .margin-box {
        padding-bottom: 10px;
    }
    .cust-box {
    margin-left: 0px;
    }
    .carousel-inner{
     max-height: 500px !important;
    }
    .img {
    max-width: 100% !important;
    height: auto;
    border-radius: 50%;
    -webkit-transition: -webkit-transform .8s ease-in-out;
    -moz-: -moz-transform .8s ease-in-out;
    transition: transform .8s ease-in-out;
    width:100%!important;
    }
    .img:hover {
    -webkit-transform: rotate(360deg);
    -moz-: rotate(360deg);;
    transform: rotate(360deg);
    } 
}
<table class="table borderless">
      <tr>
      <td align="center" width="10%"> <img width="55%" class="img" src="http://placehold.it/350x150"></td>
      <td><h4>Save on Energy Costs</h4>
          <p class="pindent">TEST TEST TEST TEST TEST TEST TEST TEST TEST</p>
      </td>
      </tr>
      <tr>
      <td align="center" width="10%"> <img width="55%" class="img" src="http://placehold.it/350x150"></td>
      <td><h4>Save the Environment</h4>
          <p class="pindent">TEST TEST TEST TEST TEST TEST</p>
         
      </td>
      </tr>
      </table>

Another approach is to expand the size of the td element containing the image to make the image larger.

For detailed steps, check the code snippet provided or visit the live demo here.

@media (max-width: 600px) {
    table {
        width:95%;
    }
    .custom-box{
        margin-left: 10px;
        margin-right: 10px;
    }
    .margin-box {
        padding-bottom: 10px;
    }
    .cust-box {
    margin-left: 0px;
    }
    .carousel-inner{
     max-height: 500px !important;
    }
    .img {
    max-width: 100% !important;
    height: auto;
    border-radius: 50%;
    -webkit-transition: -webkit-transform .8s ease-in-out;
    -moz-: -moz-transform .8s ease-in-out;
    transition: transform .8s ease-in-out;
    width:100%!important;
    }
    .img:hover {
    -webkit-transform: rotate(360deg);
    -moz-: rotate(360deg);;
    transform: rotate(360deg);
    } 
    td:first-child { width:40%}
}
<table class="table borderless">
      <tr>
      <td align="center" width="10%"> <img width="55%" class="img" src="http://placehold.it/350x150"></td>
      <td><h4>Save on Energy Costs</h4>
          <p class="pindent">TEST TEST TEST TEST TEST TEST TEST TEST TEST</p>
      </td>
      </tr>
      <tr>
      <td align="center" width="10%"> <img width="55%" class="img" src="http://placehold.it/350x150"></td>
      <td><h4>Save the Environment</h4>
          <p class="pindent">TEST TEST TEST TEST TEST TEST</p>
         
      </td>
      </tr>
      </table>

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

Why is it that lists always begin outside of the enclosing element?

I've always found this incredibly frustrating. Why do lists behave this way? When you set the margin and padding to 0, you would expect them to align normally with the surrounding text on the left, right? But no. That's where the text within the ...

Unable to modify div style using a JS function

I am attempting to show different divs based on the button clicked, with all starting with a display style of "none" except for one default div called "atualizacoes". After clicking a button, all divs should be set to display="none", and then the specific ...

CSS for the root folder of an ASP.NET website

After deciding to venture into ASP.NET, I quickly encountered my first obstacle. The folder structure is as follows: \ ->Admin -->Admin.Aspx ->CSS -->Style.css ->Images -->bg.gif Default.aspx Default.master Both admin.aspx and ...

Numerous SVGs sharing identical IDs

Is it possible to include multiple SVGs on an HTML page and utilize the same IDs in each of them? <div> <svg height="0" width="0"> <clipPath id="svgPath"> ........ </svg> <svg height="0" width="0"> < ...

using an SVG mask declared in HTML to apply masking

I've been experimenting with masking using an SVG shape that I created in the HTML content. I've tried various options: mask, -webkit-mask mask-image, -webkit-mask-image different MaskUnits and MaskContentUnits mask-type: luminance or not Desp ...

Guide on aligning a non-fixed child within a fixed parent container

I am working on a project with a fixed container (div#popup) that has some CSS styling. The container is set to position:fixed, with specific dimensions, border radius, and background color. Within this fixed container, there is a form element that I am h ...

planning to append the author's name to the end of the title using CSS

Here is the HTML code I have: <div class='store_detail-level1'> <span class='book_name'>How To Avoid Climate Disaster</span> <br> <span class='author_name'>Bill Gates</span> < ...

Tips for placing images on top of each other without overlapping other sections using 'position: absolute' in HTML and CSS

Is there a way to position one image on top of another in a responsive manner? I tried using position: absolute and z-index, but the result is not responsive. When the screen size changes, the image ends up on top or behind another section instead of expan ...

Mapping an array in ReactJS based on the specific order of another array

In my experience with Unmitigated, the answer proved beneficial. If you're arriving from a Google search, please scroll down for more information. Order: [ "567", "645", "852", "645", "852", "852 ...

Adjust various text lengths to fit web browser content

I am using a web browser within my Windows Form. I am populating it with text each time, with almost the same text size in each loop. The size of my web browser is fixed, and I want to automatically adjust the text content to fit the browser. For example, ...

Emphasizing the chosen element in a list using angular

After retrieving an array of items from the database, my list is constantly changing, causing the HTML display to update dynamically. However, I am struggling with highlighting only the selected item in the list, as the entire list gets highlighted upon se ...

Guide on inserting a row into a table class without unique values using jQuery

I have gathered information on stackoverflow regarding how to use jQuery to add a row to a table. $('.myTable').find('tbody:last').append('WHATEVER CODE'); Although this method seems to be effective, I have come across the i ...

Is there a way to prevent the slide-out bar from automatically hiding when selecting an item from its list?

I am facing an issue with my dashboard that has a slideout sidebar. Whenever I press the toggle button, the sidebar slides out as expected. However, when I click on any tab within the sidebar, it hides again. I only want it to hide when toggled. My code is ...

Creating a Standard DIV Element (JavaScript Code)

Just a quick question here. http://jsfiddle.net/fkling/TpF24/ In this given example, I am looking to have < div>Bar 1</div> open as default... Any suggestions on achieving that? That would be all for now. Thank you so much! :D The JS script ...

Determine the prior location of an element using jQuery

Is there a way to track the previous location of an element before it is appended? I have 50 elements that need to be appended to different targets based on a certain condition. How can I determine where each element was located before being moved? $(&a ...

How to modify the styling of an input element in React without directly manipulating the input itself

I have collected responses from a survey I created and now I want to showcase the results. The responses are rated on a scale from 1 to 5, and I would like to display them similar to the screenshot. Each number should be presented within a square, with ...

Implementing Interactive Buttons

As a newcomer to JScript, I have been attempting to dynamically add textboxes and select menus to a form. While I have managed to make them appear on the page, I am facing an issue with JQuery not functioning properly. Although the textboxes are visible on ...

Steps for preventing a button from being enabled until all mandatory fields are completed

Is it possible to have a button disabled until all required fields are filled out, with the button appearing grey in a disabled state and changing color when all fields are completed? I am facing an issue where clicking on the previous button is causing ...

Prevent highlighting of empty spaces in HTML by disabling selection

My goal is to be able to identify the word that is clicked on screen using jQuery without selecting any white space. For example, if I click between the word "together" and the down arrow, it should not select anything in this scenario. To achieve this, I ...

To modify the color of the breadcrumb navigation bar from purple to #d6df23 using PHP

Can someone help me figure out how to change the color of the bar displayed in this link: I need assistance with modifying the breadcrumb navbar. Is there a way to change the color to yellow? I attempted editing the header file, but it didn't produ ...