开发者

Table with pre overflows proportional div

开发者 https://www.devze.com 2023-03-06 07:14 出处:网络
I\'m trying to create a simple (ha) two column layout, where the first column is variable width and the 2nd column is fixed size.

I'm trying to create a simple (ha) two column layout, where the first column is variable width and the 2nd column is fixed size.

The first column contains a table which works fine except if the td element contains a pre block. In that case, the pre block extends to the 2nd column.

Here is a simple example:

<div class="content">
  <div id="Left">
    <table id="q-table">
      <tr><td>
        <div class="q">
           <p>This is some paragraph that will be fairly long and开发者_开发百科 wrap.</p>
           <pre>This is a very long pre tag that causes headaches.</p>
        </div>
        <div>
            <p>Causes problems if I make class q position: absolute</p>
        </div>
      </td></tr>
     </table>
   </div>
   <div id="Right">
     <p>This is a paragraph on the right with fixed width</p>
   </div>
</div>

Here is the CSS style I'm using for this example:

.content {
    width: 95%;
    position: relative;
}
#Left {
    width: 50%;
    float: left;
}
#Right {
    float: right;
    width: 200px;
}
#q-table {
    width: 99%;
}
.q {
    overflow: auto;
    width: 99%
}

If I make the .q class position: absolute then the horizontal flow mostly behaves like I want, but the following div section moves up and messes the vertical alignment.

The pre tag is the culprit. Removing it causes the correct behavior. Unfortunately, pre tags are a necessity.

Think of a StackOverflow layout where a question with code would show up with the scrollbars on a small screen, but if I have a large monitor, the question area would extend and the scrollbars would disappear.

Anyone have any ideas?

Does CSS provide support for what I'd like to do?


This may not provide the desired result. But you can adjust the white-space property instead.

For example, setting it to normal will make it behave like, say, a p tag:

pre {
  white-space: normal;
}

See it in action - http://jsfiddle.net/az85F/

Otherwise, set the width and overflow properties. That's what this very forum does for code samples. A quick example - http://jsfiddle.net/mj6Nh/1/


I have come to the conclusion that it is simply not possible to provide the behavior described.

I believe the problem is that the table and the tags conflict with each other.
The table does not enforce the proportional spacing directive when one of the cell element uses a pre tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消