Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-21-2013, 01:25 AM   PM User | #1
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
Table Question

I have tabulated data of beverages with price and beverage. I need to position the price at far right. I don't know if I am doing it right with tables, I used mant td. Below is my code.

Code:
<table  cellspacing="0" cellpadding="0">
			<tr>
			    <td align="right"> <span class="menu_name"> Classic Drinks</span></td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>	
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >80z</td><td>&nbsp;&nbsp;</td><td >120z</td>
			</tr>
			
			<tr>
			<td >Classic Drinks</td>
			  <td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>	
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >&nbsp;</td><td >&nbsp;</td><td >&nbsp;</td>
				<td >200.00</td><td>&nbsp;&nbsp;</td><td >300.00</td>
			</tr>
		</table>

Below is what I want to achieve
Code:
Classic Drink                                       80z             120z
Regular Brew                                       68.00           168.00
Decaf                                             178.00            98.00

Last edited by Anishgiri; 02-21-2013 at 01:28 AM..
Anishgiri is offline   Reply With Quote
Old 02-21-2013, 06:51 AM   PM User | #2
Brandnew
New Coder

 
Join Date: Aug 2012
Posts: 50
Thanks: 0
Thanked 11 Times in 11 Posts
Brandnew is an unknown quantity at this point
<!DOCTYPE html>
<head>
<style type="text/css">
td{text-align:center}
</style>
</head>

<body>

<table border="1" width="400px">
<th>Classic Drinks</th>
<th></th>
<th>80oz</th>
<th>120oz</th>

<tr>
<td width="25%">Regular Brew</td>
<td width="25%"></td>
<td width="20%">68.00</td>
<td width="20%">168.00</td>
</tr>

<tr>
<td width="25%">Decaf</td>
<td width="25%"></td>
<td width="20%">178.00</td>
<td width="20%">98.00</td>
</tr>

</table>
</body>

</html>

Hope this helps
__________________
1 Corinthians 15:3-4 / Ephesians 2:8-9 - What or Who are you living for?
Brandnew is offline   Reply With Quote
Old 02-21-2013, 08:39 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,448
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The table has three columns - not four or eleven.

So the HTML needs to look like this to properly define all the semantic parts of the table:

Code:
<table>
<col class="col1">
<col class="col2">
<col class="col3">
<thead>
<th>Classic Drinks</th>
<th>80oz</th>
<th>120oz</th>
</thead>
<tbody>
<tr>
<td>Regular Brew</td>
<td>68.00</td>
<td>168.00</td>
</tr>
<tr>
<td>Decaf</td>
<td></td>
<td>178.00</td>
<td>98.00</td>
</tr>
</tbody>
</table>
How you want the table to look is defined in CSS - not in HTML.
So everything else about the table will be in your external CSS file and not in the HTML at all.

For example the CSS might look like this:

Code:
table {border: 1px #000 solid; width:400px;}
.col1 {width:200px; text-align:left;}
.col2, .col3 {width:25%;text-align:right;margin-right:25px;}
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-21-2013, 01:40 PM   PM User | #4
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
The table has three columns - not four or eleven.

So the HTML needs to look like this to properly define all the semantic parts of the table:

Code:
<table>
<col class="col1">
<col class="col2">
<col class="col3">
<thead>
<th>Classic Drinks</th>
<th>80oz</th>
<th>120oz</th>
</thead>
<tbody>
<tr>
<td>Regular Brew</td>
<td>68.00</td>
<td>168.00</td>
</tr>
<tr>
<td>Decaf</td>
<td></td>
<td>178.00</td>
<td>98.00</td>
</tr>
</tbody>
</table>
How you want the table to look is defined in CSS - not in HTML.
So everything else about the table will be in your external CSS file and not in the HTML at all.

For example the CSS might look like this:

Code:
table {border: 1px #000 solid; width:400px;}
.col1 {width:200px; text-align:left;}
.col2, .col3 {width:25%;text-align:right;margin-right:25px;}
Below I change the margin right from 25px to 45px. It did not change the layout. I also change from margin right to left, it did not change the layout. Why is that so? I know putting a span style inside a td or th with margin properties will move the text. But it seems that is not the correct approach.
Code:
.col2, .col3 {width:25%;text-align:right;margin-right:25px;}
Anishgiri is offline   Reply With Quote
Old 02-21-2013, 02:13 PM   PM User | #5
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,042
Thanks: 9
Thanked 81 Times in 81 Posts
jerry62704 is on a distinguished road
Could you show the code that includes the classes? Changing a class that isn't connected to anything won't do anything.
__________________
.
.
...and gladly would he learn and gladly teach

Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls
jerry62704 is offline   Reply With Quote
Old 02-22-2013, 12:56 AM   PM User | #6
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
I use your code. I change the margin to left with 55px. It did not change anything.

Code:
<html>
<head>
    <style type="text/css">
     
   table {border: 1px #000 solid; width:400px;}
.col1 {width:200px; text-align:left;}
.col2, .col3 {width:25%;text-align:right;margin-left:55px;}
     
        
   </style>
 
</head>
<body >
<table>
<col class="col1">
<col class="col2">
<col class="col3">
<thead>
<th>Classic Drinks</th>
<th>80oz</th>
<th>120oz</th>
</thead>
<tbody>
<tr>
<td>Regular Brew</td>
<td>68.00</td>
<td>168.00</td>
</tr>
<tr>
<td>Decaf</td>
<td>178.00</td>
<td>98.00</td>
</tr>
</tbody>
</table>

</body>
</html>

Last edited by Anishgiri; 02-22-2013 at 12:59 AM..
Anishgiri is offline   Reply With Quote
Old 02-22-2013, 01:57 AM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,448
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Apparently the text-align and margin only work for a class defined on the col tag in some browsers (I had it working in Opera when I first suggested it). So you'll need to move the classes to the individual td tags rather than being able to allocate the class to the entire column in one go. Of the CSS properties you want only the width can be set for the entire column via col but there's little point in keeping those tags when you need the classes on all the tds anyway..

Code:
<html>
<head>
    <style type="text/css">
     
   table {border: 1px #000 solid; width:400px;}
.col1 {width:200px; text-align:left;}
.col2, .col3 {width:25%;text-align:right;margin-left:55px;}
     
        
   </style>
 
</head>
<body >
<table>

<thead>
<th class="col1">Classic Drinks</th>
<th class="col2">80oz</th>
<th class="col3">120oz</th>
</thead>
<tbody>
<tr>
<td class="col1">Regular Brew</td>
<td class="col2">68.00</td>
<td class="col3">168.00</td>
</tr>
<tr>
<td class="col1">Decaf</td>
<td class="col2">178.00</td>
<td class="col3">98.00</td>
</tr>
</tbody>
</table>

</body>
</html>
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-22-2013, 02:13 PM   PM User | #8
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,042
Thanks: 9
Thanked 81 Times in 81 Posts
jerry62704 is on a distinguished road
I just changed the classes to apply them to the TD and it worked the way you want it to (using FF18).
__________________
.
.
...and gladly would he learn and gladly teach

Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls
jerry62704 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:21 AM.


Advertisement
Log in to turn off these ads.