Social Icons

Wednesday, February 18, 2015

How to override inline css

Generally, inline css is meant to be used to override external css. But sometimes, it needs that you cannot remove the inline css for an element and you have to overrride that using some external css. You can do this using "!important" in css

Say for example, you have a "p" element as follows:

<p id="mypara" style="color:red">
    Paragraph content
</p>

Here, you have to change the "p" background to blue color with external css i.e, you have to override the inline one. You can do this as follows:

#para {
    color: blue; !important
}

jquery remove a style property

There are many a times it happen that you need to remove a particular css style only for an element (say div). You can remove that style property using jquery.

Say for example, you have a div like this:

<div id="mydiv" style="overflow:auto;float:left">
       div content
</div>

Now, if u want to remove the "overflow" style only from the above div, then you can do it in jquery as follows:

$(#div).css("overflow", "");

The above code will remove the "overflow" style from the div.

Total Pageviews