Forum Moderators: not2easy

Message Too Old, No Replies

Convert <table> to <div> - need help.

convert 4 images from table format to div

         

ne00_99

5:22 am on Sep 21, 2003 (gmt 0)

10+ Year Member



I have 4 images positioned by use of a table. I would like to know how to position these images within my style sheet so I can use div instead. I've tried many times but just can't seem to position everything. The use of table is my last resort, although if someone can show me a way I could get rid of it.


<table align="center" cellpadding="0" cellspacing="0" class="header" >
<form name="form1" method="post" action="">
<tr>
<td height="0" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="278" height="127" rowspan="2" background="images/logo.jpg">&nbsp;</td>
<td width="256" height="127" rowspan="2" background="images/headerbg_part1.jpg">&nbsp;</td>
<td width="266" height="28" background="images/search_bg.jpg" class="searchtable">Search:
<input name="textfield" type="text" class="searchfield"> <input name="Submit" type="submit" class="searchbutton" value="Go">
</td>
</tr>
<tr>
<td width="266" height="99" background="images/headerbg_part2.jpg">&nbsp;</td>
</tr>
</table></td>
</tr>
</form>
</table>

<Eeek!>

any help greatly appreciated.

[edited by: Nick_W at 5:57 pm (utc) on Sep. 22, 2003]
[edit reason] no urls please / thanks! [/edit]

MrMcTerse

2:32 am on Sep 22, 2003 (gmt 0)

10+ Year Member



ne00_99,

We notice you have a variety of contexts in your markup, care to include the CSS you have so far?

ne00_99

5:50 am on Sep 22, 2003 (gmt 0)

10+ Year Member



This was what I was trying to work on for the header to replace the table.


.logo {
background-image: url(../images/logo.jpg);
width: 278px;
height: 127px;
background-repeat: no-repeat;
background-attachment: scroll;
background-position: top left;
}

.part1 {
background-image: url(../images/headerbg_part1.jpg);
width: 256px;
height: 127px;
background-attachment: scroll;
background-position: top left;
margin-left: 23em;
background-repeat: no-repeat;
}

.searchtable {
font-family: Verdana;
font-size: 9px;
color: #000000;
text-align: center;
vertical-align: middle;
background-image: url(../images/search_bg.jpg);
background-repeat: no-repeat;
height: 28px;
width: 266px;
background-attachment: scroll;
background-position: top right;
}

.part2 {
background-image: url(../images/headerbg_part2.jpg);
width: 266px;
height: 99px;
background-repeat: no-repeat;
background-attachment: scroll;
background-position: top right;
}

.searchfield {
font-family: Verdana;
font-size: 9px;
color: #000000;
background-color: #FFFFFF;
height: 15px;
width: 127px;
border: 1px solid #000000;
}
.searchbutton {
font-family: Verdana;
font-size: 9px;
color: #000000;
background-color: #FFFFFF;
width: 50px;
height: 15px;
border: 1px solid #000000;
}

#header img, #image img {
vertical-align: bottom;
}

D_Blackwell

5:54 am on Sep 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think that this meets the criteria, but can't figure out why <div>s below the banner won't center perfectly. I just don't see why they won't. The #box must be a tad larger than the contents or the last float will break. Also, the DTD is required. The width is going to scroll horizontally at 800 resolution.

Help on the centering? Now that I'm into it, it's killing me. A better way?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {
margin: 0; padding: 0;
}
#box {
width: 815px; text-align: center; margin: auto;
}
.banner {
width: 800px; border: 1px solid #900; margin: .5em;
}
.leftcol {
width: 278px; height: 127px; border: 1px solid #900; float: left;
}
.centercol {
width: 256px; height: 127px; border: 1px solid #900; float: left;
}
.rightcol {
width: 266px; border: 1px solid #900; height: 127px; float: left;

}
.secondcell {
height: 28px; border-bottom: .1em solid #900; width: 266px;
}
</style>
</head>
<body>
<div id="box">
<div class="banner">
banner
</div>
<div class="leftcol">
left
</div>
<div class="centercol">
center
</div>
<div class="rightcol">
<div class="secondcell">
second cell
</div>
right
</div>
</div>
</body>
</html>

MrMcTerse

10:15 pm on Sep 22, 2003 (gmt 0)

10+ Year Member



D_Blackwell's method does get the images in place although I found it necessary to make some slight adjustments:

"banner_eg.html"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {
margin: 0; padding: 0;
}
#box {
width: 800px; text-align: center; margin: auto;
}
.banner {
width: 800px;
}
.leftcol {
width: 278px; height: 127px; float: left;
background-image : url(images/logo.jpg)
}
.centercol {
width: 256px; height: 127px; float: left;
background-image : url(images/headerbg_part1.jpg)
}
.secondcell {
width: 266px; height: 28px; float: left;
background-image : url(images/search_bg.jpg)
}
.rightcol {
width: 266px; height: 99px; float: left;
background-image : url(images/headerbg_part2.jpg)
}
.searchfield {
font-family: verdana, geneva, arial, helvetica, sans-serif;
font-size: 9px;
color: #000000;
background-color: transparent;
position : relative; top: +4px; left: +21px;
width: 127px;
max-height: 15px;
border: none;
}
.searchbutton {
background-color: transparent;
position : relative; top: +7px; left: +22px;
width: 50px;
max-height: 15px;
border: none;
}
</style>
</head>
<body>
<div id="box">
<div class="banner">
<!-- img="images/banner.jpg" -->
</div>
<div class="leftcol">
<!-- img="images/logo.jpg" -->
</div>
<div class="centercol">
<!-- img="images/headerbg_part1.jpg" -->
</div>
<div class="secondcell">
<!-- img="images/search_bg.jpg" -->
<form name="form1" method="post" action="">
<input name="textfield" type="text" class="searchfield">
<input name="Submit" type="submit" class="searchbutton" value="">
</form>
</div>
<div class="rightcol">
<!-- img="images/headerbg_part2.jpg" -->
</div>
</div>
</body>
</html>

For my own part, I'm not sure of the reasoning for the larger box, as the full banner appears correctly in both Firebird and IE6 with a box of 800px.

I played with two selectors and found a couple of things to help control the search area, which you will notice in the above example.

This seems to work fine in Firebird, now, but in IE we run into trouble, which you will see for yourself. Please let us know if you find a solution that works, as this is an interesting problem for us CSS novices.

ne00_99

4:02 am on Sep 24, 2003 (gmt 0)

10+ Year Member



Thanks for the help guys. Worked great except for the spacing issue for .rightcol between IE and Opera. Will look into this more.

Thanks once again!

D_Blackwell

6:06 am on Sep 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mr. McTerse,

The larger box came from my using a border on the various divisions to keep on eye how all the elements were behaving while working on the problem. I had to add a little extra width to keep the floated divisions from breaking down. The 800px box wouldn't hold them with the borders. (At least in IE6)

Your response got me to looking at it again. Of course, removing the borders eliminated the need for a slightly larger box - but it also repaired the problem of the banner and the columns not centering quite correctly. I don't why they didn't in the first place or why that fixed it. It immediately corrected though.

It would have been a much cleaner example piece if I'd posted the code with {background-color: xxx;} delineating each box instead of the borders in the first place.

MrMcTerse

11:05 am on Sep 24, 2003 (gmt 0)

10+ Year Member



Thanks for that added info, D_Blackwell.

Funny thing about browsers... Wish they were more like seat belts: no matter how they're made, they all work the same way.

I hadn't taken into account the effect of the borders since I immediately removed them before going any further.

One hopes that ne00_99 will keep us posted on how the IE problem is finally solved. I've tried everything my little brain can come up with.

The behavior appears to be related to the original height of the Search division, in that the text area is Npx below the top of the window, which appears to be echoed in the lower division for some reason.