Solved

How to Overwrite TD Element Properties?

Posted on 2006-06-26
8
476 Views
Last Modified: 2008-02-01
Hello,
I have a CSS file that sets TD peoperty for the whole page like this:

td{
font: 10pt Verdana;
}

I want to apply a different font and font size to only one particular table on this page without changing CSS TD set above. How can I do it if I know table's ID?

Something like this, perhaps, using JavaScript:
var mytable=document.getElementById("mytable");
mytable.style.fontFamily= "Arial";
mytable.style.fontSize= "8pt";

But this does not overwrite TD CSS set above. I need a way to apply above JavaScript to the TD element of the table. Please help!
0
Comment
Question by:Vadymus
  • 3
  • 3
  • 2
8 Comments
 
LVL 6

Expert Comment

by:inviser
ID: 16986010
why don't you you create a new css class, say:

td.new_class {
font: 10pt Verdana;
}

and then assign the particular td that class name like this:

<td class=new_class>...</td>

Otherwise if you still want to go the js route, make sure the js code comes after the css in the page, then it should work.
0
 

Author Comment

by:Vadymus
ID: 16986135
Great! But how can I assign these TDs to have "new_class" if I know TD's table ID? See, I do not want to do <td class=new_class>...</td> because in some cases this table is using default TD CSS.

So, can it be something like:
#tableId.td.new_class {
font: 10pt Verdana;
}

Thank you
0
 
LVL 6

Expert Comment

by:inviser
ID: 16986158
Sure thing, you would do it like this:

<td id=tdID>...</td>

<style>
#tdID {
font: 10pt Verdana;
}
</style>
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16986315
here is the syntaxt if your table's id is "mytable":

table#mytable td {
  font-family: Arial;
  font-size: 8pt;
}
0
 

Author Comment

by:Vadymus
ID: 16986596
Your suggestions make my question answered almost completely.
Please, tell me the very last thing is it is possible:

If I have this (if syntax is correct):

table#mytable td.new_class {
  font-family: Arial;
  font-size: 8pt;
}

how can I tell JavaScript to apply it when I need (something like):

var mytable=document.getElementById("mytable");
mytable.className = "table#mytable td.new_class";
0
 
LVL 6

Expert Comment

by:inviser
ID: 16986657
I'm not sure I understand exactly what you are trying to do by the code you just posted. Could you elaborate a bit more?
0
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 25 total points
ID: 16986770
Sorry, i did not read the question with enough care.

You should set the class on the table:

var mytable=document.getElementById("mytable");
mytable.className = "someclass";

then use this CSS:

table.someclass td {
  font-family: Arial;
  font-size: 8pt;
}
0
 

Author Comment

by:Vadymus
ID: 16986814
GrandSchtroumpf offered this:

table#mytable td {
  font-family: Arial;
  font-size: 8pt;
}

By default, I have this:

td{
font: 10pt Verdana;
}

I want to use default all the time unless I specify GrandSchtroumpf's version. How do I specify it? That;s my question. I thought if I add a class to GrandSchtroumpf's version, then I can call it with JavaScript like this:

var mytable=document.getElementById("mytable");
mytable.className = "table#mytable td.new_class";

But will it work?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question