Wrox Programmer Forums
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 17th, 2010, 08:33 AM
Registered User
 
Join Date: Apr 2005
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default Alternative of <div>.

Hi,

somehow

Code:
<div>
      </table>
      <table> <tr><td><td></table>
</div>
is giving error that u can't embeded bla blah..

so is there any other way to do this?

Note: Why I am doing this is bit leanghty subject.

Thank you .

Last edited by rupen; November 17th, 2010 at 08:43 AM..
 
Old November 17th, 2010, 09:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Nope, not if you want to create valid HTML.

A <div> can't be placed within <table> and </table> tags directly...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
rupen (November 17th, 2010)
 
Old November 17th, 2010, 09:25 AM
Registered User
 
Join Date: Apr 2005
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

ok, but what is the alternative for this? is it <span>?
 
Old November 17th, 2010, 10:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Nope; you simply can't do it. Valid items for within the <table> element are elements like colgroup, thead, tbody and so on, as specified here: http://www.w3.org/TR/1999/REC-html40...tml#edef-TABLE (and <tr> elements, although they should be placed in a tbody)

In other words, you need to rethink your strategy if you want to make this valid HTML.

Why do you need this? Can't you just swap the first <div> and the first </table>?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 17th, 2010, 10:46 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Also, your code has two opening <td> elements and no closing </tr> which makes it invalid as well.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
rupen (November 18th, 2010)
 
Old November 17th, 2010, 12:10 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Quote:
Originally Posted by rupen View Post
Code:
<div>
      </table>
      <table> <tr><td><td></table>
</div>
is giving error that u can't embeded bla blah..

so is there any other way to do this?

Note: Why I am doing this is bit leanghty subject.
I concur with Imar. Sometimes when you're facing a challenge, the first issue is figuring out which way you're going to attack the problem. If you're comfortable using <div>s, which some guys aren't, you probably don't need a table here unless it is explicitly being used for tabular data. The fact that you're trying to shove a div element into it, makes me suspect that this is not the case. This is undesirable enough that it's worth taking a second look at the decision making process and see if there's a different approach that would be better.

I would consider this, at least temporarily, a dead end, and give us the lengthy background on why you're trying to do this. Perhaps we will wind up right back here, trying to figure out the "least bad" solution, but more likely we can find a different approach that will be more successful.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
The Following User Says Thank You to chroniclemaster1 For This Useful Post:
rupen (November 18th, 2010)
 
Old November 18th, 2010, 03:15 AM
Registered User
 
Join Date: Apr 2005
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

I need to do this because: there are few information we need to display in header and footer of print page ( & not in web-page) so when user access the web-page the div tab will not be displayed, (using @media CSS technique) and when user prints the page the footer text (div tag) will be printed.

So, if user prints web-page, I need to end the product list table and insert my footer table with custom CSS page-break else if user is just seeing in web-browser I need to hide the footer text.

Further, the existing page itself is very complex and is written by somebody else some years ago, so can't modify the entire structure of page and have to go with <table> tags as time cruch.
 
Old November 18th, 2010, 03:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

table tags are fine in this case; it's just the incorrect nesting that will cause you problems. Based on your description, I don't see a solid case for this nesting issue; maybe by simply swapping just a few tags around you can fix it and make it valid? It's a bit difficult to suggest something based on this short snippet alone.

The fact that it's bad HTML isn't so bad and is not something that *must* be fixed just so it's valid. Browsers are typically very forgiving. The only problem is of course that it'll lead to other problems: tables disappearing when you're printing, or other weird layout issues may occur.

But if this is just a header and footer issue, why not insert them after the opening and before the closing body tags?

Code:
 
<body>
<div class="PrintOnly">Header only visible when printed</div>
   ...
  Your content here
<div class="PrintOnly">Footer only visible when printed</div>
</body>
The CSS class PrintOnly can then made invisible in the browser, but visible in print.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Container <div> and another ,div. not behaving as expected SouthendSupporter ASP.NET 3.5 Basics 8 December 15th, 2009 10:05 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
sizeable <div> johnjohn Javascript How-To 1 December 8th, 2004 08:28 PM
<A><DIV><TABLE></DIV></A> anshul HTML Code Clinic 2 July 17th, 2004 02:17 PM
Alternative to <embed> Snib HTML Code Clinic 10 June 19th, 2004 05:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.