51

I have a few HTML tables. These tables do not have CSS classes. The two tables have width="100%" attribute. Other tables don't have the width attribute.

Using only CSS I need to set the width of the tables which don't have width=100%. Something like this:

table:not(width="100%"){
    width: myValue;
}
Andry
  • 15,262
  • 25
  • 130
  • 229
Sanya530
  • 1,139
  • 4
  • 17
  • 24

4 Answers4

106

Attribute selectors are surrounded by [], so your selector should look like this instead:

table:not([width="100%"]) {
    width: myValue;
}
BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
2

use a class on that table and put that in the not

table:not(.foo) {

}

you need a selector in the not and width = 100% is not one

zzzzzzzzz
  • 47
  • 6
-1

How about using inline styles for the tables you want to have different widths?

<table style="width:95%">
    <tr>
        <td></td>
    </tr>
</table>

OR a separate class:

<table class="customWidth">
    <tr>
        <td></td>
    </tr>
</table>

CSS:

table { width:100%; }
table.customWidth { width:95%; }
Brian Salta
  • 1,624
  • 1
  • 10
  • 18
-3

just write in the css folder table { width: 100% };

Zlatko Soleniq
  • 340
  • 2
  • 4
  • 13