How to overright inline CSS

Forums CSSHow to overright inline CSS
Staff asked 2 years ago

For example, this css added inline

element.style{
width: 500px !important;
}

How Can I overright this css?
Note: You can’t change this CSS.
I want to overright this css

Answers (1)

Add Answer
Prince Dhameliya Marked As Accepted
Staff answered 2 years ago

If you want how to overright inline CSS so please review my code.

I have created HTML in an index.html file.

<body>
  <div class="mydiv" id="mydivid" style="width: 500px!important"> test </div>
</body>

And I have add CSS in <style>…</style> tag on index.html file.

#mydivid {
    background: #ffc107;
    width: 200px !important;
  }

I have tried width overnight with !important but it’s not working and the output looks like this:

So I have tried another way.

I have overwritten CSS using jQuery

Now I added code in my <script>…</script> tag on index.html file.

$(window).on("load", function() {
      $(".mydiv").removeAttr("style");
      $(".mydiv").css("width","200px");
    });

I have removed inline CSS on window load and added new CSS.

So my CSS now working and the output looks like this:

I hope you found something useful  ??

Subscribe

Select Categories