tags:

views:

2787

answers:

4

I'm wondering how to ignore a parent style and use the default style (none). I'll show my specific case as an example but I'm pretty sure this is a general question.

<style>
#elementId select {
    height:1em;
}
</style>

<div id="elementId">
    <select name="funTimes" style="" size="5">
        <option value="test1">fish</option>
        <option value="test2">eat</option>
        <option value="test3">cows</option>
    </select>
</div>

Ways I do not want to solve this problem:

  • I cannot edit the stylesheet where the "#elementId select" is set, my module won't have access that.
  • Preferably not overwrite the height style using the style attribute.

For example using firebug i can turn off the parent style and all is well, this is the effect I am going for.

Once a style is set, can it be disabled or must it be overwritten?

+6  A: 

It must be overwritten. You could use:

<!-- Add a class name to override -->
<select name="funTimes" class="funTimes" size="5">

#elementId select.funTimes {
   /* Override styles here */
}

You could use an attribute selector, but since that isn't supported by legacy browsers (read IE6 etc), it's better to add a class name

PatrikAkerstrand
+1  A: 

you can create another definition lower in your CSS stylesheet that basically reverses the initial rule. you could also append "!important" to said rule to make sure it sticks.

Jason
A: 

It would make sense for CSS to have a way to simply add an additional style (in the head section of your page, for example, which would overwrite the linked style sheet) such as this:

<head>
<style>
#elementId select {
    /* turn all styles off (no way to do this) */
}
</style>
</head>

and turn off all previously applied styles, but there is no way to do this. You will have to override the height attribute and set it to a new value in the head section of your pages.

<head>
<style>
#elementId select {
    height:1.5em;
}
</style>
</head>
Chris Tek
+1  A: 

You could turn it off by overwriting it like this:

height:auto !important;

Fabian Brenes