Forum Moderators: not2easy

Message Too Old, No Replies

Table breaking out of a div, only in FF

centering a title at the bottom of a div

         

Tolvor

5:14 pm on Apr 4, 2008 (gmt 0)

10+ Year Member



The entire point is that I need to have the title of the sidebar (yellow area) to be centered at the bottom of sidebar header (this is the black area). In Internet Explorer this works perfectly. In Firefox the black title is breaking into the green sidebar by 2 pixels. When enlarging the font through the browser, IE keeps the title within the sidebarheader (black), in FF it becomes more pronounced that the table is not constrained.

<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">

body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
font-size: small;
background-color: #FFFFFF; /* gets overwritten by container */
margin: 0;
padding: 0;
text-align: center;
color: #FFFFFF;
}

#container {
width: 700px;
background: #d0d0d0;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 21px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
overflow: hidden;
}
#header {
border-bottom: solid 2px #202020;
border-top: solid 2px #202020;
background-color: #ff0000;
height: 100px;
}
#sidebar1 {
float: left;
width: 225px; /* since this element is floated, a width must be given */
background: #00ff00;
height: 200px;
}
#sidebar1 table {
background-color: #ff0;
}
#sidebar1 h3 {
color: #f00;
margin: 0 0 0 0;
}
#sidebar1 td {
height: 60px;
vertical-align: bottom;
}
#sidebartitle {
background: #000000;
height: 60px;
text-align: center;
}
.centeredtable {
margin-left: auto;
margin-right: auto;
}
#mainContent {
background: #0000ff;
border: solid 0px #202020;
float: right;
width: 410px;
margin: 15px 15px 0px 15px;
padding: 0 15px 0px 15px;
position: relative;
height: 185px;
}

</style>
</head>

<body>
<div id="container">
<div id="header">
</div>
<div id="sidebar1">
<div id="sidebartitle">
<table class="centeredtable"><tr><td><h3>Title</h3></td></tr></table>
</div>
</div>

<div id="mainContent">
</div>
</div>
</body>
</html>
</code>

Dave75

6:22 pm on Apr 4, 2008 (gmt 0)

10+ Year Member



This declaration height was wrong:

#sidebartitle {
background: #000000;
height: 64px;
text-align: center;
}

penders

8:36 pm on Apr 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Agree with Dave75.

In Internet Explorer this works perfectly.

Because IE treats height the same as min-height, IE is actually stretching the container to accommodate your Title. FF is rendering this correctly, fixing the height of the container to 60px. You could also try adding

overflow:hidden
to #sidebartitle in order to prevent it from being stretched - this should also render the same in FF and IE.

Tolvor

5:08 am on Apr 6, 2008 (gmt 0)

10+ Year Member



I appreciate the answer, and indeed it does work. I had been checking into finding the deeper reason of what is happening here (and knowing where the correct setting should be is a huge help). I had set the height of the table cell to be exactly the same as the height of the title area in the sidebar - a neat fit. Apparently I overlooked the fact that something in the table is increasing my minimum height for that area - but what that is still stumps me. Is it the cell spacing or padding between the td area and the outside area of the table is causing the need to increasing the height from 60 to 64?

Thanks again.

Dave75

4:00 pm on Apr 6, 2008 (gmt 0)

10+ Year Member



The reason the height was 64px is because the table and td elements have a 1px border around them, adding 4px to the overall height. Lesson - don't use black in your design process when determining the position of your elements, if you'd used purple or another colour you would have caught that error.

penders

10:28 pm on Apr 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is it the cell spacing or padding between the td area and the outside area of the table is causing the need to increasing the height from 60 to 64?

Yes, I believe so - both.

<table class="centeredtable" cellpadding="0" cellspacing="0">

Setting the cellpadding and cellspacing to 0 should get rid of it. Unfortunately I believe this is the only way to remove the extra spacing cross-browser. IE6 (and IE7 - I think?) do not properly support the necessary CSS properties '

border-collapse
' and '
border-spacing
'.

swa66

11:46 pm on Apr 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No version of IE (6, 7 or 8beta) do border-collapse:collapse and border-style:hidden together properly, IE developers seem to be unable to comprehend what hidden means, perhaps it's too far down to the page.

[w3.org...]

I'd not risk mixing the old cellpadding/cellspacing in the HTML with CSS, but that's just me.
Instead, I'd se "border-spacing" if you're not collpasing borders in tables.

penders

7:14 am on Apr 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd not risk mixing the old cellpadding/cellspacing in the HTML with CSS, but that's just me.
Instead, I'd se "border-spacing" if you're not collpasing borders in tables.

But "

border-spacing
" is not supported at all by IE?
cellpadding
/
cellspacing
are not deprecated attributes and I would have thought setting these to 0 was a common starting point for many?

swa66

5:23 pm on Apr 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Honestly: dunno what IE does with border-spacing, perhaps I'm naive in expecting it to do anything right.

I actually seem to have always settled on border-collapse:collapse so I've never even touched border-spacing in IE as I've always settles on other ways before I got to even look at it in IE.

But my tables are just <table class="..."> (or perhaps an id), I've never felt the need to add layout to the table tag in html since I started to use CSS.

penders

11:59 pm on Apr 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I actually seem to have always settled on border-collapse:collapse so I've never even touched border-spacing in IE as I've always settles on other ways before I got to even look at it in IE.

I think this is OK if you don't want any cellspacing ('border-spacing' in CSS) and the cellspacing attribute has not been specified, as IE will not then override it.

Setting the cellpadding and cellspacing to 0 should get rid of it. Unfortunately I believe this is the only way to remove the extra spacing cross-browser.

May be I was a bit hasty - setting the attributes to 0 is not the only way ;) Setting

border-collapse:collapse
on the table and
#sidebar1 td {padding:0;}
should also do the job of eliminating the extra spacing/padding. Thanks swa66.