user1250526
user1250526

Reputation: 309

Is there a way to take off the style off a certain table?

I have a css file which styles my tables, although I have one table where I would like to use a different style, or no style? is there a way I can do something like <table style="no-style"> and then it is plain and ignores the CSS?

I have looked but I can not find anything related!

Upvotes: 0

Views: 65

Answers (4)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201808

No, you cannot take off a style that way – there is no way in CSS to say “don’t apply any of my styles inside this particular element.” You can only override style settings. For example, if you have a setting like * { color: red } in your stylesheet (just a foolish example), you cannot add a rule that would exclude a particular element and make the browser apply its default color inside it. But you can set table#foo * { color: black; } to make all text inside a table with id=foo have the black color.

Overriding overall style settings inside a table that way isn’t trivial, but certainly possible. You just need to be explicit about the style you want; you cannot say “use browser defaults.”

However, there’s an indirect way, in a sense, though it is seldom a good idea: If you put your table in a separate document and embed it via an iframe element, then the table will be displayed according to the CSS code specified for the embedded document, quite independently of the style sheets for the embedding document. At the extreme, if you specify no CSS code for the embedded document, it will appear as per browser defaults (though inside a subwindow, an inline frame, with dimensions set by the embedding document).

Upvotes: 0

Marvo
Marvo

Reputation: 18143

You need to explore CSS in more depth, and one thing you might focus on is classes. You can create a "class" of styles, and apply it to a particular HTML element like a table, and not have it affect another table you want to leave "plain."

.foo {
    border : 1px solid black;
}

Then apply that class to your HTML element:

<table class="foo">
    ...
</table>

Another way to approach the problem is with selectors.

Upvotes: 0

mert
mert

Reputation: 2002

Use class definitions for table properties in your CSS file. Whenever you want them, use with class property.

CSS

table.myClass {
...
}

HTML

<table class="myClass">...</table>
<table class="anotherTableWithAnotherClass">...</table>

Upvotes: 1

Starx
Starx

Reputation: 79031

CSS are cascading style sheets, they only style an element. Can't manipulate anything. You will need to use JavaScript.

Best way I know of, is to use CSS classes for different styles. And use javascript to switch them or remove them.

Upvotes: 0

Related Questions