473,408 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Table layout to Div

Hopefully this is an easy solution.

I come from the old school tables layout.

I am trying to accomplish a layout using divs that I can easily do in tables but having trouble with using divs.

This is what I am trying to do (this is how i'd do it using tables).

<table width="750" border="1">

<tr>

<td width="500">content for this div here</td>

<td width="250" height="450" rowspan="2">content for cell here, this will span 2 rows.</td>

</tr>

<tr>

<td> content for this cell </td>

</tr>

</table>

I don't get it!

Any help would be great, thanks.
Jun 26 '07 #1
7 13060
nathj
938 Expert 512MB
Hopefully this is an easy solution.

I come from the old school tables layout.

I am trying to accomplish a layout using divs that I can easily do in tables but having trouble with using divs.

This is what I am trying to do (this is how i'd do it using tables).

<table width="750" border="1">

<tr>

<td width="500">content for this div here</td>

<td width="250" height="450" rowspan="2">content for cell here, this will span 2 rows.</td>

</tr>

<tr>

<td> content for this cell </td>

</tr>

</table>

I don't get it!

Any help would be great, thanks.
Hi,

There is an easy way to do this. I found an article the other day when i was trawling around the web but I can't for the life of me remember where, and foolishly I did not bookmark this. So the code I am abut to post is not mine originally but it does work a treat.

CSS
Expand|Select|Wrap|Line Numbers
  1. div.row 
  2. {
  3.     clear: both;
  4.     padding-top: 3px;
  5.     padding-bottom: 5px;
  6. }
  7.  
  8. div.row span.label 
  9. {
  10.     padding-left: 10px;
  11.     padding-right: 0px;
  12.     float: left;
  13.     width: 100px;
  14.     text-align: right;
  15. }
  16.  
  17. span.labelwarning 
  18. {
  19.     padding-left: 10px;
  20.     padding-right: 0px;
  21.     float: left;
  22.     width: 100px;
  23.     text-align: right;
  24.     color: #ff0000;
  25. }
  26.  
  27. div.row span.formw 
  28. {
  29.     float: right;
  30.     width: 455px;
  31.     text-align: left;
  32.  
  33.  
HTML (for a dummy form that I am working on)
Expand|Select|Wrap|Line Numbers
  1. <form id="personal" action="application.php?step=2" method="post">
  2.     <!-- 
  3.     Personal details
  4.     -->    
  5.     <div class="row">
  6.         <h4 class="eventListItem">Personal Details </h4>
  7.     </div>
  8.  
  9.     <div class="row">
  10.         <span class="labelwarning">
  11.             Title:
  12.         </span>
  13.         <span class="formw">
  14.             <input id="title" type="text" maxlength="15" size="47" />
  15.         </span>
  16.     </div>
  17.  
  18.     <div class="row">
  19.         <span class="labelwarning">
  20.             Forename(s):
  21.         </span>
  22.         <span class="formw">
  23.             <input id="forename" type="text" maxlength="30" size="47" />
  24.         </span>
  25.     </div>
  26.  
  27.     <div class="row">
  28.         <span class="labelwarning">
  29.             Surname:
  30.         </span>
  31.         <span class="formw">
  32.             <input id="surname" type="text" maxlength="30" size="47" />
  33.         </span>
  34.     </div>
  35.  
  36.     <div class="row">
  37.         <span class="label">
  38.             Note:
  39.         </span>
  40.         <span class="formw">
  41.             <textarea id="note" cols="44" rows="8">
  42.             </textarea>
  43.         </span>    
  44.     </div>
  45.  
  46. <div class="row">
  47.         <h4 class="eventListItem">Access Details </h4>
  48.     </div>
  49.  
  50.         <div class="row">
  51.         <span class="labelwarning">
  52.             Username:
  53.         </span>
  54.         <span class="formw">
  55.             <input id="username" type="text" size="47" />
  56.         </span>
  57.     </div>
  58.  
  59.     <div class="row">
  60.         <span class="labelwarning">
  61.             Password:
  62.         </span>
  63.         <span class="formw">
  64.             <input id="password" type="password" maxlength="18" size="47" /> 
  65.              (6-18 characters)
  66.         </span>
  67.     </div>
  68.  
  69.  
This structure code be used and modified for any situation where you would normally use a table.

I hope this helps
Nathan
Jun 27 '07 #2
drhowarddrfine
7,435 Expert 4TB
Well, using CSS to imitate tables is the anti-thesis for using CSS in the first place. Tables were originally used because nothing much else was available. So trying to duplicate table usage defeats the whole purpose of CSS.

What you want to do is layout your page using html only. Group those elements which belong together with a <div> if necessary; and it's not always necessary. Then, style those elements as needed using CSS.

Separating your content from your style makes life much easier than in the old table method.
Jun 27 '07 #3
nathj
938 Expert 512MB
Well, using CSS to imitate tables is the anti-thesis for using CSS in the first place. Tables were originally used because nothing much else was available. So trying to duplicate table usage defeats the whole purpose of CSS.

What you want to do is layout your page using html only. Group those elements which belong together with a <div> if necessary; and it's not always necessary. Then, style those elements as needed using CSS.

Separating your content from your style makes life much easier than in the old table method.
Hi,

The sample code I provided lays out a form. Originally tables were the best way to ensure that the labels and inputs lined up nicely. As tables are dead, and really should not be used any more CSS is the way to do it. I agree with what drhowarddrfine is saying and that is, to my mind, what I have done. I have used <div> to group similar elements together. My testing has also shown that my page displays the same way in FF, IE and O. So the results are good, the code is smooth and the effect desirable.

If there is another way to layout a form that is even better than I have suggested then please post it. I am always keen to learn new things. Sorry if that was a bit of a hijack, I didn't mean to.

I hope the questions have been answered and an informative discussion provided.

Cheers
nathj
Jun 28 '07 #4
drhowarddrfine
7,435 Expert 4TB
So no one is confused, tables are not 'dead', but, intead, tables have resumed their rightful place in the display of tabular data instead of being used for page layout. Page styling and layout should only be done using CSS.
Jun 28 '07 #5
<!-- courtesy to authors .... -->
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1" />
<title>Accessible Table-less forms</title>
<style type="text/css" media="all">
#content_half1
{
float:left;
border: 1px dashed #333;
background-color: #0028ff;
min-width:300px;
min-height:300px;
max-width:600px;
max-height:600px;
}
#content_half2
{
float:left;
border: 1px dashed #333;
background-color: #ffffff;
min-width:20px;
min-height:20px;
max-width:20px;
max-height:20px;
}

#content_half3
{
float:left;
border: 1px dashed #333;
background-color: #0028ff;
min-width:300px;
min-height:300px;
max-width:600px;
max-height:600px;
}

form, label, input { font-size : 1em; }
fieldset { width : 25em; padding : 0.5em 1em; }
label { position : relative; width : 15em; display : block; margin : .5em 0em; }
label input { position : absolute; left : 100%; top : 0px; width : 10em; }
input.submit { margin-left : 15em; }
br { display : none; }
</style>
</head>

<body>
<h1>CSS Forms</h1>
<p>This page is based entirerly on CSS. No tables whatsoever. It's fast, accessible, and probably the most elegant way to make table-less forms today. Check it out yourself...</p>



<div id="content_half1">
<fieldset>
<legend>Personal details</legend>

<label>Name:<input type="text" name="name" /></label><br />
<label>Email:<input type="text" name="email" /></label><br />
<label>Telephone:<input type="text" name="tel" /></label><br />

<input type="submit" value="Submit" class="submit" />
</fieldset>
</div>
<div id="content_half2">
</div>
<div id="content_half3">
<fieldset>
<legend>Personal details</legend>

<label>Name:<input type="text" name="name" /></label><br />
<label>Email:<input type="text" name="email" /></label><br />
<label>Telephone:<input type="text" name="tel" /></label><br />

<input type="submit" value="Submit" class="submit" />
</fieldset>
</div>

</body>
</html>[/html]
Mar 7 '08 #6
dlite922
1,584 Expert 1GB
Hi,

The sample code I provided lays out a form. Originally tables were the best way to ensure that the labels and inputs lined up nicely. As tables are dead, and really should not be used any more CSS is the way to do it. I agree with what drhowarddrfine is saying and that is, to my mind, what I have done. I have used <div> to group similar elements together. My testing has also shown that my page displays the same way in FF, IE and O. So the results are good, the code is smooth and the effect desirable.

If there is another way to layout a form that is even better than I have suggested then please post it. I am always keen to learn new things. Sorry if that was a bit of a hijack, I didn't mean to.

I hope the questions have been answered and an informative discussion provided.

Cheers
nathj
tables are not Dead!

i love tables. (then again, i grew up with them)...but for page layout, not anymore. for tabular data? hell ya.

For tabular data , div and css is hell.
Mar 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Anthony Williams | last post by:
Good morning, I'm currently designing a site, using CSS, and wish to create a variable width two-column layout, with header and footer, and one fixed-width column on the left. Previously, I...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
4
by: Rob Freundlich | last post by:
I have some servlet-generated tabular data that I need to present, so I'm using an HTML Table. In some cases, it can be quite large. I'm flushing the servlet output every N lines to push the data...
4
by: Eric | last post by:
I'm trying to reproduce the following table layout using CSS only and am having some trouble with it. I'd like them to look identical but I'm having trouble sizing the labels properly as it doesnt...
2
by: Wayne Wengert | last post by:
I have an aspx page I originzlly built in WebMatrix that includes a "<table>" structure to layout the columns using "<tr>" and "<td>" elements (see sample below). When I create a new aspx form in...
4
by: greg.mckone | last post by:
Hi folks, I've been using CSS for style for several years now, but I've never attempted a layout using CSS. (I'd like to move away from tables) I'm working on a page here:...
3
by: Roberto Roachling | last post by:
Hello, Converting a table layout to a div layout. The navbar is giving me some trouble. div link: http://gertrudischale.com/essay.pl.htm (slightly incomplete, but illustrates problem) table...
8
by: sethp | last post by:
I have a question about table layout in IE. I have a table with two columns. The left column has two rows and the right column has 1 row that has a column span of 2. In the left column I have...
2
by: spacix | last post by:
Does anyone know a work around for "table-layout: fixed;" to prevent the automatic evenly space cells width without assigning classes or ID to cells? My program prints a HTML "report" file and I...
5
by: Timothy Larson | last post by:
I'm trying to create a 3 row layout in which each row will have two blocks, BUT I want the width of these blocks to be independent of the blocks in the other rows. So AFAICT a regular table layout...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.