0

I have a css class pause. This is applied in various pages. Only one section of markup doesn't margin-left:42px;, so I want to make it 0px. I don't want to use a new class because I am applying this class dynamically using jQuery for certain conditions.

So, I need to overwrite the class to make margin-left:0px; from markup.

css

.pause a{
         background-image:url(../img/pink_pause.png);float:left;
         height:26px;width:96px; margin-left:42px; margin-top:6px;
         }   

markup

<td  class="pause  bid_button_logout bidder_name">
<a href="login"></a>
</td>  

How can I neutralize margin-left by any other class or any other way?

6 Answers 6

1

If you can't define another style, use an inline style on the element that you don't want margin-left applied to. Inline styles are more specific than those defined elsewhere, so it should take precedence:

<a href="login" style="margin-left:0">

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

Comments

1

You could split the .pause into two css classes where one of them only defines the extra margin, and simply not apply that class to the ones that don't need margin.

Or set the style attribute on the element like this: style="margin-left: 0;", this will override the css value.

Or you could create anoter class called say ".noMargin" like this:

.noMargin{ margin-left: 0 !important; } 
/* important overrides other class values 
   even if the cascading would not */

and apply that class to the ones you dont want to have the extra margin.

1 Comment

Typical when I've finished writing 3 ways of doing it, each method is already answered by several others... heheh
0

If you want to use inline style:

<a href="login" style="margin-left:0px;"></a>

Or creating a new declaration:

.bid_button_logout a{
    margin-left: 0px; 
}

but this has to come after .pause a.

Comments

0

Or, if you really need to switch classes see toggleClass

Comments

0

Try the important hack:

margin-left: 0px !important;

Comments

0

If bid_button_logout or bidder_name are unique to the situation where you want no margin, add margin-left:0px; to either of those classes (but make sure they are after .pause a in your css file. If not, use your conditional jQuery to add an inline style, which will bypass the original left margin style.

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.