Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all CSS from specific DIV [duplicate]

Tags:

html

css

Possible Duplicate:
Disinherit (reset) the CSS style of a specific element?

I have a page that loads an external CSS file with different CSS attributes.

Is it possible to create an element within that same page and specifically for that element not load any of the css?

For example:

<style type="text/css">
p {
    background-color:#000000;
    width:550px;
}
</style>
<p>This should get the P styling from the style tag</p>
<p>This should NOT get the P styling</p>
like image 755
user838437 Avatar asked Nov 04 '12 14:11

user838437


3 Answers

As everyone else is saying, there are usually better ways to isolate an element. However, there is a CSS selector for this purpose too.

See The Negation Pseudo-Class

HTML

<p>A paragraph</p>
<p class="nostyle">Don't style me</p>
<p>A paragraph</p>
<p>A paragraph</p>

CSS

P:not(.nostyle) { color: red; }

Example: http://jsfiddle.net/LMDLE/

This is rarely the right solution, but it can be useful for handling edge cases which are hard to match with another selector.

like image 117
Tim M. Avatar answered Nov 20 '22 21:11

Tim M.


This would be exactly what classes were designed for.

<style type="text/css">
.class1{
background-color:#000000;
width:550px;
}
</style>
<p class="class1">This should get the P styling from the style tag</p>
<p>This should NOT get the P styling</p>

For the record don't use names like class1 that was for demonstration only. Use descriptive names for classes that make sense.

like image 1
Rick Calder Avatar answered Nov 20 '22 22:11

Rick Calder


You could positively isolate the P's you want styled:

<p class="hasStyle"></p
<p></p>

Or you could override the ones you want to remain unstyled:

<style>
p {
    background-color:#000000;
    width:550px;
}

.noStyle {
 background-color: none;
 width: none /* or whatever you want here */;
}
</style>

<p>has a style</p>
<p class="noStyle"></p>

The latter is harder to maintain.

like image 1
Martin Lyne Avatar answered Nov 20 '22 22:11

Martin Lyne