I’m trying to expand a div. However everything works accept the ‘height’ property. I use jQuery’s addClass function to add this class;
.expandHighlight
{
height:300px;
border-color:rgba(48,110,158,.75)!important;
box-shadow:0 0 5px 2px rgba(48,110,158,.5);
}
using the jQuery function;
$('#expand').click(function()
{
$('#buttonField').css('visibility','hidden');
$('#expand').addClass("expandHighlight");
});
And the div im trying to expand has the css;
#expand
{
background-color:#F9F9F9;border-radius:3px;
border:1px solid #C0C0C0;
width:500px;
height:66px;
border-radius:2px;
}
When you add the class, you then have two CSS rules that pertain to the same object for height. That means the the CSS specificity rules will determine which CSS rule applies.
In this case, the
#expandrule has more specificity than the.expandHighlightrule so it wins.You can fix this by adding more specificity to the .expandHighlight rule like this:
And, then it will have more specificity and will win when the expandHighlight class is assigned.
You can read more about CSS specificity and how it works here.
You could also fix it by making both of the rules be only a class and putting the
expandHighlightrule after the regular height rule like this:You would of course add
class="expandNormal"to the#expandobject so it would get the default rule which would then be override by theexpandHighlightrule only when that class was also present.