3

I'm loading emails (via gmail's api) using Angular:

<div class="email-body">
  <div compile-html data-html="thread.message.body"></div>
</div>

When I do so, the loaded emails bring with them css styling that affect the css of the whole site.

For example, my css:

.container {
  width: 80%;
}

But an email (once loaded) brings the following css:

.container {
  width: 20% !important;
}

The css for .container gets overridden by the newly loaded css. Is there a way I could contain the imported css within a div (email-body)?

3
  • possible duplicate of Div with external stylesheet? Commented Feb 11, 2015 at 18:32
  • Do you know of an alternative way to do it without using an iframe? Commented Feb 13, 2015 at 15:51
  • Could you not just remove all <style> nodes when loading the email? Commented Apr 1, 2015 at 17:46

1 Answer 1

1

This could might not be the fastest way, but gets the job done without iframes (using javascript and jquery):

  $('.email-body').find('*').each(function () {
    if ($(this).css("width")) {
      var setWidth = $(this).css("width");

      //clearing width value
      setWidth = setWidth.replace(/[^0-9]/g, '');

      $(this).css("width", NEW WIDTH VALUE HERE);
    }
  })

If you are using Angular, you might want to wrap this in a $timeout.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.