views:

79

answers:

5

Hi,

I want to create a dialog with a title, borders (left, right, bottom) as well as the content. The current source code:

<html>
<body>
<div style="background: #0ff; width: 152px; height: 112px; position: absolute; top: 24px; left: 128px; display: table">
<div style="display: table-row;">
<div style="background: #f00; width: 100%; display: table-cell;height: 24px;">top</div>
</div>
<div style="display: table-row;">
<div style="background: #0f0; width: 100%; display: table-cell;">

<div style="display: table;">
<div style="display: table-row;">

<div style="display: table-cell; width: 4px; height: 100%; background: #000;"></div>

<div style="display: table-cell;">
<div style="overflow: scroll; white-space: nowrap">
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />

cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe cwe <br />
</div>
</div>

<div style="display: table-cell; width: 4px; height: 100%; background: #000;"></div>

</div>
</div>



</div>
</div>
<div style="display: table-row;">
<div style="background: #000; width: 100%; display: table-cell; height: 4px;"></div>
</div>

</div>
</body>
</html>

produces an output of

alt text

what happened to the left and the right borders and why does the size exceed the width specified in the top parent (152px)?

+4  A: 

If you're going to use a table, use a table. Setting the display of block elements to mimic various table elements is problematic at best, and very unpredictable cross-browser.

Robusto
+1  A: 

You are using too many inline rules, try separating them using CSS selectors, classes and ids to divs, use tables appropriately.

Some rules are canceling out others that's why you don't see borders.

Lex
+1  A: 

Sorry but your HTML code is a horrible mess of tag soup reminiscent of the early 90s.

For your exact problem, the width is larger because of your rule white-space: nowrap which stretches the table. And this is what's likely removing the borders - there is no content in those "cells" so they collapse to a zero width.

Like Robusto said, if you want a table, use a table. If you want a dialog-like box, you definitely don't need all those nested div tags. Just have your outer one and use the border rule to set the borders:

<div style="border:4px solid #000; border-top:0; background:#0ff; width:152px; height:112px;">
    <h2 style="background:#f00;">top</h2>
    cwe cwe cwe cwe...
</div>
DisgruntledGoat
A: 

You don't have to use all these divs to begin with. You can simplify your HTML drastically:

<div>
  <h1>top</h1>
  <div>
    <p>cwe cwe cwe</p>
    <p>cwe cwe cwe</p>
  </div>
</div>

and still easily apply all the styling you need. No need to create a div for each border. That's what the CSS attributes border-left, border-right, border-bottom and border-top are there for (and these are supported by ancient browsers, unlike display: table).

From what I see, you don't have an advanced problem, you're deliberately turning a very simple problem into an advanced one.

RegDwight
A: 

the scrolling is not caused by the sizing, its caused by you forcing the Scroll value in overflow. In my experience, setting it to scroll shows the scrollbars all the time - albeit in their disabled state. try setting the overflow to auto

<div style="overflow: auto; white-space: nowrap"> 
Mauro