tags:

views:

166

answers:

3

I have this html that I use to create a box look around the title, this is for a flowchart looking page. Fairly straight forward and looks correct.

    <td>
        <table align="center" border="0" style="border: thin solid black;" cellpadding="0">
            <tr>
                <td align="center" nowrap style="padding: 5px;" class="headerlarge">&nbsp;Resources:&nbsp;</td>
            </tr>
        </table>
    </td>

When I try and use a span with border and padding, I lose the top border, the class is only for the font.

font-weight: 600;
font-size: 12pt;
color: black;
font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
font-style: normal;

when I try and use a div, the border fills the entire parent element and I only want it to be a size that fits around the text, not grow to whatever. I have played around with margins and padding in the parent TD element as well as within the div or span. What css do I need to create a box with padding that fits exatly around the text and will not lose any of its border when in a table cell?

UPDATE : So I found that this problem was only specific to IE6 & 7, other browsers work using Phoenix's css, the div wrapper around a span. I posted the html/css Here at Jsbin . So the question remains, how to get around this in IE 6 & 7 without any hacks and over doing the css, otherwise I might as well stick with a stupid nested table.

+2  A: 

Edit: I verified that Nino's answer works on Firefox 3.0.14/Ubuntu 9.04 and IE 8/WinXP SP3. The style of the dt and tr tags in which the div is contained need not be updated. So combining these things, we get:

.headerlarge {
  border: 1px solid black;
  display: inline-block;
  margin: 0px;
  padding: 5px;
  /* ... */
}

<div class="headerlarge">Resources:</div>
Stephan202
To be honest I was playing around with inline style, but I will try out your suggestion real quick.
Breadtruck
I only now read that you did try to set the padding of the surrounding `dt`. I vaguely remember having problems with this myself, and that a solution involved changing the padding of the `tr` as well. So I updated the answer.
Stephan202
Sorry, didn't help either. I am thinking it has to do with some css farther up in the DOM like maybe the top level parent table or something. I am trying out Phoenix's suggestion now.
Breadtruck
Good luck. Unfortunately I have to run now. I'll read about the solution this afternoon.
Stephan202
I posted the code in a link in the update section of my question.
Breadtruck
Column 2 and 3 on the page you linked to look identical to me (Firefox 3.0.13, Ubuntu 9.04). I don't have Internet Explorer here.
Stephan202
Your solution was column 1, any idea on how to make a div NOT expand to fit parent container?
Breadtruck
Can you test the updated code on IE 6/7?
Stephan202
Still didn't work, I also tried numerous variations using "display" on your code and phoenix's. I tried altering the TD, DIV and SPAN.
Breadtruck
A: 
<div class="divClass">
    <span class="headerlarge spanClass">
      Resources: 
    </span>
</div>
<style>
.headerlarge
{
    font-weight: 600;
    font-size: 12pt;
    color: black;
    font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-style: normal;    
}
.divClass
{
    text-align: center; 
    padding: 0;
}
.spanClass
{
    white-space: nowrap; 
    padding: 5px; 
    border: 1px solid black;
}
</style>
rahul
Still lose the top border on the span. So if your sure that this should work, then it must be some other style farther up the dom then? What is your opinion?
Breadtruck
Breadtruck
+1  A: 

Try using display:inline-block for the container in IE.

Nino
+1. I cannot test this in IE 6/7, but it seems key to the most elegant solution. I'll update the example code in my answer.
Stephan202