0

I need to place inline !important css declarations in an e-mail signature, otherwise Gmail won't display it correct it.

My styles are binded via :style, and if I place !important in the declaration it removes that property.

...
linkStyle: {
     "textDecoration": "none !important", //this gets autoremoved
     "color": "#334593"
}
...
<a :style="linkStyle"></a>
...

Only the color gets applied, I've even tried this:

...
<a :style="linkStyle" style="text-decoration !important"></a>
...

To try and fool it, and it does get text-decoration:none applied but without the !important flag.

I'm lost. Can anybody tell me a workaround this?

4
  • Apply a class and put the !important in the css associated with the class. github.com/vuejs/vue/issues/3761#issuecomment-249422167 Commented Jan 17, 2018 at 15:59
  • Will this style be inlined? Remember, e-mail signatures only deal with inline styling. I cannot have a <style> element. Commented Jan 17, 2018 at 16:39
  • Is this an option for you? <a style="text-decoration:none !important"></a> Commented Jan 17, 2018 at 17:23
  • Yes it was, I was a little sleep deprived and couldn't see my obvious syntax error. Commented Jan 17, 2018 at 22:49

2 Answers 2

2

After some time I've found out that you have to use "text-decoration" instead to work:

linkStyle: {
    'text-decoration': 'none !important',
    color: "#334593"
}

In vue.common.js it reaches this line:

el.style.setProperty(name, val.replace(importantRE, ''), 'important');

Where name = textDecoration. In this case, the string textDecoration doesn't work, should be text-decoration.

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

1 Comment

Your answer is great because it takes a peek at how Vue actually parses it, and of course, the source code would reveal the mistery! That's why I'll give the checkmark to you instead of Roy, even though his answer is stellar too.
1

If you don't include textDecoration in linkStyle, your last example works:

const v = new Vue({
  el: '#app',
  data: {
    linkStyle: {
      color: "#334593"
    }
  },
  mounted() {
    document.getElementById('content').textContent = this.$el.innerHTML;
  }
});
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.min.js"></script>
<div id="app">
  <a href="#" style="text-decoration: none !important" :style="linkStyle">Whatever</a>
</div>
<code id="content">
</code>

1 Comment

I think I might need some sleep, I've just now seen that I put text-decoration !important instead of text-decoration: none !important. I believe both your answer and Felippe's are great for different reasons.

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.