PDA

View Full Version : Get element to ignore all styles?


Jak-S
01-26-2006, 03:33 PM
This is probably a no, but is there any way to get a div to ignore all styles except those that are specifically targeted at that div?

For example, if I had all divs set to “font-weight: bold” and then one particular div set to ignore all styles, the text wouldn’t appear in bold, and would only follow the styles set in the div#mydiv {} rule (for example).

Thanks in advance.

Jack

_Aerospace_Eng_
01-26-2006, 03:37 PM
You would have to tell the div to be font-weight:normal

Jak-S
01-26-2006, 03:50 PM
Yeah, that’s what i assumed, but the whole point is that im not going to know what css rules have been created, so i want it to ignore all possible.

Im writing a PHP debugging tool, and it outputs its results at the very beginning of the page, the data is formatted with css and i don’t want the formatting of my debug output to be affected by the style of the actual page. The script could be used on any site, so its impossible to know what css properties i need to override.

mark87
01-26-2006, 03:54 PM
Well if you think about it, there's not *too* many properties, and you can use shorthand to set them quickly. eg.

font: normal 1em Verdana;

I do realise it could be a bit of a pain though!

VIPStephan
01-26-2006, 08:35 PM
You could set all the possible values back to normal for that one div... I mean it would be a lot of writing for ALL of them but you probably can figure out which kind of styles are going to be applied. So set all of those to "default"... maybe?

mark87
01-26-2006, 09:45 PM
Well the thing is, there isn't a way to specify defaults in CSS. Sure, elements have defaults, but 'cascading' is the key word in CSS, which is where Jak-S' problem arises.

As I said before, you need to find all of the properties which can be inherited and set them to what you want.

Here's the CSS2 reference - http://www.w3schools.com/css/css_reference.asp .

If you scroll through you'll see what you need to change...

Background doesn't get inherited so that's ok, border you can simply set to 0, font you can set in one declaration as I showed above, etc etc.

Jak-S
01-26-2006, 11:54 PM
Yeah, looks like im gonnna have to go down that route, cheers for the help.