Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placement of Table attributes (on tag vs in style)

Status
Not open for further replies.

TonyJollans

Programmer
Dec 18, 2002
7,186
GB
Still struggling to understand ...

Can someone please explain the difference between the following two samples.

I want to specify as much as possible in style sheets but can't seem to get it to work. In the two samples below, the only significant difference (as far as I understand it) is the placing of the width attribute. The border is just to provide a visual aid - it makes no obvious difference to what happens.

1. Width attribute given on table tag.

Code:
<HEAD>
</HEAD>

<BODY>
  <TABLE width = "100%" border = "2" >
    <TR><TD>First Cell</TD><TD>Second Cell</TD></TR>
  </TABLE>
</BODY>

2. Width attribute given in style.

Code:
<HEAD>
  <style>
    table { width: "100%"; }
  </style>
</HEAD>

<BODY>
  <table border = "2" >
    <TR><TD>First Cell</TD><TD>Second Cell</TD></TR>
  </table>
</BODY>

Whilst they appear to do the same in IE, in Firefox the table in the second sample is just wide enough for the content.

This is a deliberately simplified example to highlight my lack of understanding. The effect is not limited to the width attribute - it is just an easy one to demonstrate. There is clearly something I don't understand, but what?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
In the stylesheets you do not put values in quotes. IE will let your mistake slip and will work with it while FF will penalize you for the wrong code and ignore the specification. Try this:
Code:
<head>
  <style>
    table { width: 100%; }
  </style>
</head>

<body>
  <table border = "2" >
    <tr><td>First Cell</td><td>Second Cell</td></tr>
  </table>
</body>
 
How embarasingly simple [blush]

Many Thanks

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top