Drewdavid
Drewdavid

Reputation: 3192

Why doesn't this work for me? [element] [class] {style}

I am trying to have a normal class for tables, e.g.

table {style here}

But for some tables I'd like to have a different style

I could just give the table a class and then use that class alone, e.g.

.specialTable {special style}

But I'd like to try specifying that this is just applicable to tables, e.g.

.specialTable table {special style}

However this isn't working, what's wrong?

Upvotes: 0

Views: 67

Answers (4)

Deonoway
Deonoway

Reputation: 1

.specialTable table Is selecting tables that are descendants of elements with the .specialTable class.

You want table.specialTable, which selects tables with the class specialTable.

Upvotes: 0

Brandon
Brandon

Reputation: 70052

.specialTable table specifies a table element within an element with the class specialTable.

You want table.specialTable, which means any table with the class specialTable.

Upvotes: 3

Cfreak
Cfreak

Reputation: 19319

It would help if you showed your HTML but I think I see what you're getting at.

<table class="specialTable"> is not what your CSS specifies. Instead it specifies something like

<div class="specialTable"><table>...</table></div>

Instead in your CSS you can do

table.specialTable { ... }

Upvotes: 0

kba
kba

Reputation: 19476

.specialTable table {special style}

The above code will affect any table which has an ancestor (a previous element) with the class specialTable. That will for instance match the table in

<body class="specialTable">
  ...
  <table>
  ...

What you want is a table with the class specialTable in which case the syntax is

table.specialTable {special style}

Upvotes: 0

Related Questions