CSS - The 'object-fit: cover' attribute isn't functioning properly within the HTML email content

Could you please assist me with my html email body issue regarding the "object-fit: cover;" parameter? It works perfectly when displayed on the web, but is not functioning correctly in an html email body.

EmailProvider: New Outlook in WIN PC Mobile: Also Outlook

Here is a sample of the code:

body {
  background-color: ;
  font-family: roboto;
}

.PanelPicture {
   ...
}

.PanelBackground {
   ...
}

.Scena1 {
   ...
}
<center>
  <div class="PanelBackground">
    <div class="PanelPicture">
      <img src="paris.jpg" alt="Paris" , class="Scena1">
    </div>
  </div>
</center>

You can test by changing "paris.jpg" to any picture you have or even try it here on w3schools - just swap codes and keep the image (image from that page).

Issue: When I receive this email, the picture does not fit within ".PanelPicture"; instead, it overlays outside.

I came across Can I Email - css object fit which states that my email client should support this feature.

I'm hoping for a code revision to help solve the issue of fitting the picture inside the panel within the email's html body as well.

Answer №1

Emails require a different approach compared to web design.

To ensure compatibility, I made adjustments such as inlining code, utilizing tables instead of divs, and cleaning up HEX colors from 8 characters to 6. While this resulted in the desired outcome, there were some limitations, such as lack of support for old Windows Outlook (conditional comments could be used as a workaround), and images not displaying properly on Yahoo/AOL clients.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
   <!-- START HEAD v5-->
  <head></head>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <!--[if !mso]><!-->
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <!--<![endif]-->
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title></title>
</head>
 <!-- END HEAD -->
<body>
<center style="font-family: roboto;">
    <table cellpadding="0" cellspacing="0" role="presentation">
      <tr>
          <td style="background-color: #2A2A2A;  max-width: 300px;  text-align: center;  border-radius: 8px;  border-style: solid;  border-color: #878787;  border-width: 2px;  margin-top: 30px;  margin-right: 20px;  margin-left: 20px;  margin-bottom: 30px;padding:5px;">
              <center>
                <table cellpadding="0" cellspacing="0" role="presentation"  align="center">
                    <tr>
                        <td width="300"  style="background-color: #878787;  height: 90px;  max-width: 300px;  border-radius: 9px;  border-style: solid;  border-color: #878787;  border-width: 2px;  margin-top: 5px;  margin-right: 10px;  margin-left: 10px;  margin-bottom: 5px;">
                  <img src="https://picsum.photos/id/237/400/300" alt="Paris" style="width: 100%; height: 100%; object-fit: cover; border-radius: 8px;">
                        </td>
                    </tr>
                </table>
              </center>
          </td>
        </tr>
  </table>
</center>
</body>

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

Guide on including the sequential images within the previous and next button of a carousel

Currently working on my portfolio website, I have managed to code a carousel for displaying my images. The only challenge I am facing now is how to make the 'Next' and 'Prev' buttons show the next and previous images respectively. Does ...

Themes in Next.js with a splash of color

Is there a way to implement theming with color picking for elements? Check out the example here. I've explored using CSS variables and changing the document classname, but I'm uncertain if this is the best approach. @tailwind base; @tailwind com ...

What are some strategies modern internet browsers use to address Sub-Pixel Issues in CSS?

In a vintage article dated from 2008 by the renowned John Resig, the challenges of sub-pixel rendering in older browsers were discussed. An interesting scenario was presented where 4 floated divs, each with a width of 25%, were contained within a parent di ...

Customize your radio buttons to display as stylish boxes with Bootstrap

Check out my Fiddle here... The radio buttons are displaying correctly in the fiddle. <div class="element-radio" title="Do you want to float the text to the left, right, or not at all?"><h4 class="title" style="font-weight: bold;">Float (left ...

Finding a specific section on a webpage using AngularJS

Is it possible to create in-page navigation to a specific section within an Angular application without triggering the routing service? For example: The section we want to jump to: <a name="tips"> <div>Tips and tricks...</div> < ...

Intelligent programming and innovative thinking to streamline template diversity

My goal is to create multiple child websites using a base HTML/CSS template. Each child website will have unique color schemes and image variations for elements like <h> tags and background colors. I am searching for ways to easily modify the base th ...

Add the onclick() functionality to a personalized Angular 4 directive

I'm facing an issue with accessing the style of a button in my directive. I want to add a margin-left property to the button using an onclick() function in the directive. However, it doesn't seem to be working. Strangely, setting the CSS from the ...

Finding the nearest span element with a selector in styled components

Currently experimenting with integrating Styled Components to target the nearest span element. <label> <span className="">Password</span> <input type="password" id="passwordInput" /> </label> ...

Looking to perform an Ajax call to update a Rails model using HTML5 contenteditable, but encountering an issue where it creates a new

I am in need of assistance to update the plots of a story using HTML5 contenteditable feature. Below is the code snippet: Refer to file# for editing multiple plots <div id="editable" contenteditable="true"> <%= simple_format p.description %&g ...

Is there a way to add a child to a div with a randomly generated id number?

Don't miss the update at the end! :) I'm developing a small website where users can input data into multiple text boxes, and when they return later, their information is still there (essentially a basic helpdesk system using local storage). The ...

The PHP DOM feature is inserting an additional <p> element along with <html> and <body> tags

When it comes to displaying different images for desktop and mobile users based on their device, I have implemented a function in my index.php file. The code snippet from my index.php file: <!DOCTYPE html> <html class="no-js" lang="en"> <h ...

Manipulating Vue.js data within HREF attributes using PHP

Does anyone know how to successfully pass the data from Vue into PHP? I've attempted a few methods, but when I try to use the resulting link in the href attribute (href = $ where $ name), it shows a strange string instead of the expected URL from the ...

Eliminate gaps between items when using the flex-wrap:wrap attribute

Check out my code on Plunker. Is there a way to eliminate the vertical spacing when using flex-wrap: wrap; #main { width: 200px; height: 200px; border: 1px solid #c3c3c3; display: flex; flex-wrap: wrap; } <div id="main"> < ...

Issue with displaying elements at intended layering order when parent element has fixed positioning

My web app features both upper and lower elements (div) with a position: fixed. Each element has child popups also with position: fixed. Even though I want to position the popup above its parent element, using z-index doesn't work due to inheritance ...

`The value of an element within an array changes automatically`

In my current setup, I have a traditional array where each element represents an HTML element. The issue arises when I manipulate these elements within the array; any changes made to the HTML element also reflect in the array automatically. However, I pref ...

Issue with AngularJS ng-if causing hidden elements to not respond to ng-select event

In my code, there is a hidden select input that is initially hidden using ng-if. Inside this hidden select, I have included a ng-change tag, which triggers a function to display an img element that is also hidden by ng-if. The element hiddenNinja is hidd ...

Exploring the integration of Construct 3 objects with ReactJs

Although I am well-acquainted with Construct 3 platform, I now have an interest in website development. Specifically, I would like to incorporate a character-like object into my web project that moves similar to a game character. While I know how to achiev ...

The PHP navigation is being obscured by the image gallery

I have implemented a PHP navigation system for my website using the code below: * { margin:0; padding:0; list-style:none; text-decoration:none; } img { position: absolute; top: 10px; left: 40%; } ul#navi { float:left; background:#31 ...

Tips on building an immersive interactive panoramic website

I have a vision for a website that will simulate being in a room, where users can explore the space with limited panoramic views - allowing them to look up/down 30 degrees and left/right 45 degrees. In addition, I would like to integrate interactive object ...

Exploring the art of CSS box-shadow and playing with margins

In one of my blog posts, I've applied CSS box-shadow to the <img> elements. To ensure that they adjust their size along with the column, I have set max-width:100%. However, the box-shadow spills over into the margins due to its rendering outsid ...