What is preventing internal CSS from functioning properly on mobile devices within the Gmail platform?

I have encountered an issue while sending an email from a PHP file to a Gmail account. The code I am using consists of basic HTML and CSS. Interestingly, the email looks perfect on desktop devices with all styles applied correctly. However, when viewed on mobile devices (both app and browser), the styles seem to be stripped off as if the internal CSS is being removed.

Even after trying out Google's sample code:

<html>
  <head>
    <style>
      .colored {
        color: blue;
      }
      #body {
        font-size: 14px;
      }
      @media screen and (min-width: 500px) {
        .colored {
          color:red;
        }
      }
    </style>
  </head>
  <body>
    <div id='body'>
      <p>Hi Pierce,</p>
      <p class='colored'>
        This text is blue if the window width is
        below 500px and red otherwise.
      </p>
      <p>Jerry</p>
    </div>
  </body>
</html>

And here are the headers that I'm including in the email:

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "From: Optimization Manager <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72xxx5xx2xyxxxxxxxxx5xxxxx625xx65592d7daxxx5xx2xy002dd5728c8c">[email protected]</a>>" . "\r\n" .
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

Despite trying different approaches, even this setup doesn't seem to work as expected.

Any insights or solutions you could provide on this matter?

Answer №1

Try applying this solution, as it may work. My system is functioning well after clearing the cache. If you continue to experience issues, please inform me.

<!DOCTYPE html>
<html>

<head>
  <title>sdb</title>
  <style>
    .colored {
      color: red;
    }
    
    #body {
      font-size: 14px;
    }
    
    @media screen and (max-width: 500px) {
      .colored {
        color: blue;
      }
    }
  </style>
</head>

<body>

  <div id='body'>
    <p>Hi Pierce,</p>
    <p class='colored'>
      This text will appear blue if the window width is below 500px, otherwise it will be red.
    </p>
    <p>Jerry</p>
  </div>

  </script>
</body>

</html>

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

Retrieve the content of the 'div' element, but exclude certain text

I have a task to copy the content from a div into a textarea, allow for editing within the textarea, and ensure that any changes made are saved back to the original div. I also need to filter out an attribute, such as data-bind: "some stuff;", set for the ...

Issues arise when attempting to use bootstrap in col-md-6 format on a tablet, as the

I attempted to have 2 columns appear side by side on tablets by using col-md-6 so that each column would only use 6 units. However, when switching from desktop to tablet size, the columns end up stacked vertically, with each column now using all 12 units ...

Struggling with dynamically updating fields based on user input in real time

I have a goal to update a field based on the inputs of two other fields. Currently, all the fields are manual input. Below is the code I'm using to try and make the "passThru" field update in real-time as data is entered into the other fields. The ma ...

What is the best way to center text in a div with a distinct background color?

Could really use some assistance with this. Here are the images for reference: https://i.stack.imgur.com/JNZkT.jpg Currently getting this result: https://i.stack.imgur.com/nW17o.jpg <style> .Nav_bar_links div{ margin: 0% 1 ...

I am looking to adjust the width of an element within an Iframe

In my single post, I have a social sidebar on the left side. Currently, the buttons in the sidebar are appearing in different sizes, but I want them all to be the same size as the "Twitter" button. To see the issue, please visit this link. I've tried ...

Error: $ is not defined when the jquery.js script is placed at the bottom of the HTML document

My current project has all JS files referenced in the footer for faster page loading. This includes the Jquery file link. However, I am encountering an "Uncaught ReferenceError" which I believe is due to Jquery not being defined before my script is called: ...

Using CSS to style PHP function results

I am working on a shopping cart application and I want to incorporate a condensed version of the cart onto my home page. The main shopping cart page is called 'modcart.php' and I have managed to integrate it into my homepage using the following c ...

Creating a custom Chrome extension with CSS embedded within an iframe

Recently, I developed a Chrome app that includes an iframe element within it. <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="v ...

What are the steps to create a downpour in every location on Earth

Is there a way to create a continuous raining effect for my weather app using CSS only? I have achieved a satisfactory look, but the rain effects seem to only cover random chunks of the screen rather than the entire screen. How can I make it cover the enti ...

Using CSS to customize the dropdown text styling of a select box within a custom wrapper

I have a specific customized dropdown menu using the styled-select wrapper: HTML: <div class="styled-select"> <select name="example_length" aria-controls="example" class=""> <option value="10">10</option> <option value="25"> ...

How can I avoid using the appendTo method in jQuery?

There seems to be an issue in my HTML code, could you please take a look at the code snippet below: HTML: <div class="agent_select_wrap"> <select name="menu-114" class="wpcf7-form-control wpcf7-select" aria-invalid="false"> <op ...

Assistance needed with CSS - making an element occupy the entire remaining vertical space

Although I'm quite confident in my CSS/XHTML abilities, this particular issue has me stumped. You can view the problem here: - (please note that the website is still under development, most features are not functional, and it's subject to frequ ...

When attempting to use the .split method, an error is thrown stating that addEventListener is not

I'm attempting to create a table that automatically fills in the next input when I select options from MySQL. However, when I run this code, I get an error saying "addEventListener is not a function." I'm not very familiar with JavaScript, so I&a ...

Interactive YouTube video in a responsive classroom environment

Hello! I have a website at bit.ly/1EfgOsM and I am trying to align the video box with a YouTube video next to an image box. The width of the image box is set to 40%, so I want the video box to also be responsive with a width of 40%. The video box is in a s ...

Modify content or display picture within accordion panel based on its identifier

In my view, I have a model representing a list of items. Each item has a unique ID, which is included in the H2 header tag. The details of each item are displayed in a div below the header. Initially, there is an image within the header that is set to disp ...

Instructions on how to automatically navigate to a different tab upon clicking an <a> element on a separate webpage, and subsequently display the designated tab on that

I have a button on my home page that, when clicked, should open a specific tab section on another page. The button is located on one page and the tabs are on a different page. On the second page, I have multiple tabs but will only mention one here, which ...

What is the best way to assign a background color to each tr element using JavaScript?

I have a list of table rows with different background colors like <tr bgcolor="#OC6110"> <tr bgcolor="#000000"> <tr bgcolor="#FFFFFF"> Is there a way to assign unique background colors to each tr element without specifying its id value ...

Having trouble getting jQuery .append() to behave the way you want?

I have created a code snippet to display a table like this: $("#results").append("<table><tr><th>Name</th><th>Phone Number</th></tr>"); $("#results").append("<tr><td>John</td><td>123123123 ...

Implement a "View All" link to toggle between displaying all items and keeping one item open by default,

I am working on multiple toggles for each letter of the alphabet. To make it easier for users, I want to add a "See All" button that will open any closed toggles. Additionally, I want the toggle for the letter A (div1) to be automatically open when the pag ...

Looking for a way to make this HTML tab appear using ng-show and an external variable in AngularJS - seeking guidance as a beginner!

Here is the HTML code snippet controlling the tab presentation: <li class="presentation" ng-show="currentUserAuthority == LIBRARIAN" > However, there seems to be an issue with the variable "currentUserAuthority" not updating until after the web pag ...