58

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
  • 16,172
  • 27
  • 138
  • 246
Sanya530
  • 1,209
  • 4
  • 18
  • 24

4 Answers4

116

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

table:not([width="100%"]) {
    width: myValue;
}
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
3

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
  • 57
  • 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,576
  • 1
  • 10
  • 18
-3

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

Zlatko Soleniq
  • 390
  • 2
  • 4
  • 14