Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply style classes to td elements?

Tags:

html

css

What I am trying to find out is the proper syntax to apply some style to each individual td in my table below:

<section id="shows"> <!-- HTML5 section tag for the shows 'section' -->  <h2 class="gig">Shows</h2>  <ul class="gig">      <!-- Start the table -->     <table>         <tr>             <!-- Setup the header row -->             <th>When</th>             <th>Where</th>             <th>Start</th>             <th>Finish</th>         </tr>          <?php             // some PHP to fetch all the gig entries from the shows table             $shows_query = "SELECT * FROM shows ORDER BY date ASC";             $shows = mysql_query($shows_query);             // a loop to place all the values in the appropriate table cells             while ($show = mysql_fetch_array($shows)){             //begin the loop...             ?>          <!-- Start the row -->         <tr>              <!-- Format the date value from the database and print it: -->             <td class="when"><?php              $date = date("l, F j, Y", strtotime($show['date']));              echo "$date";             ?></td>              <td class="venue"><?php             echo $show['venue'];             ?></td>              <!-- Format the start and end times and print them: -->             <td class="start"><?php             $time = date("G:i", strtotime($show['time']));              echo "$time";             ?></td>              <td class="finish"><?php             $until = date("G:i", strtotime($show['until']));             echo "$until";             ?></td>              <!-- Finish this row -->         </tr>          <!-- Some space before the next row -->         <div class="clear"></div>          <?php              // close the loop:              }              ?>         <!-- Finish the table -->     </table> </ul>  </section> 

The styling that I have at the moment is:

#shows table.gig { font-size: 25px; } #shows td.finish { margin-left: 50px;} 

I did have a class for the table itself but not sure if it's necessary.

The font-size works but what I can't figure out is how to apply the style to the td, th, tr elements etc. I have tried several things but can't seem to get it to work!

like image 914
martincarlin87 Avatar asked Mar 15 '11 12:03

martincarlin87


People also ask

How do you apply a class style rule to an element?

It is needed to stylize HTML elements – including changing colors, fonts, or the size of a text. If you want to use a class, use a full stop (.) followed by the class name in a style block. Next, use a bracket called a declaration block that contains the property to stylize the element, such as text color or text size.

How do I add a class to my TD tag?

Code explanation Two CSS classes are defined in the <style> element. The class attribute in <td> assigns one classname. Repeatedly clicking the button calls JavaScript which locates all the <td> tags using classnames. It then toggles the another class, changing the background and text color.

What is td style in HTML?

The <td> HTML element defines a cell of a table that contains data. It participates in the table model.


1 Answers

Give the table a class name and then you target the td's with the following:

table.classname td {     font-size: 90%; } 
like image 132
moleculezz Avatar answered Sep 24 '22 14:09

moleculezz