Solved

How to Overwrite TD Element Properties?

Posted on 2006-06-26
8
473 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now