0

I'm trying to select one specific table on one html page to be formatted with css. I do not want any other tables anywhere else, including on the same page, to be formatted this way.

I tried this inside the header but it did not work-

<style>
    #table3 {
        td,th { padding: 10px }
        tr:hover { background-color: #f5f5f5 }
    }
</style>

<table id="table3">
...
</table>
Alireza
  • 2,319
  • 2
  • 23
  • 35
hotkarl
  • 33
  • 4
  • This is definitely the correct way to do it, but that is not valid css. You can't nest elements in plain css. Try these styles instead: `#table3 td, #table3 th { padding: 10px }` and `#table3 tr:hover { background-color: #f5f5f5 }` – 01010011 01000010 Jun 08 '17 at 21:00
  • I'm voting to close this question as off-topic because the CSS is invalid and that's why it doesn't work. – Rob Jun 08 '17 at 21:12

3 Answers3

5

You can't nest selectors like that. At least not in normal CSS.

You want:

<style>
    #table3 td, #table3 th { padding: 10px }
    #table3 tr:hover { background-color: #f5f5f5 }
</style>

<table id="table3">
...
</table>
Blazemonger
  • 90,923
  • 26
  • 142
  • 180
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
1

This wont work because this isn't the format for CSS, although the concept is right in what you have done the format isn't correct.

Try this...

#table3 td, #table3 th {
    padding: 10px;
}

#table3 tr:hover {
    background-color: #f5f5f5;
}

However, if you would like to do it the way in which you did it. You could do it with a CSS compiler such as less, which you can view online as less js, it makes CSS lightweight and a lot easier to write.

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
0

The way you wrote it looks more like SCSS. If you need plain CSS, this is how it should look like:

<style>
    #table3 TD {
        padding: 10px;
    }
    #table3 TH {
        padding: 10px;
    }
    #table3 tr:hover {
        background-color: #f5f5f5;
    }
</style>

<table id="table3">
...
</table>
user3429660
  • 2,420
  • 4
  • 25
  • 41