tags:

views:

64

answers:

3

If you visit this page and shrink your browser window, you will see my problem. [If you want to open the page in a new window, just hold down shift when you click the link.]

The answers to the question extend beyond the page margin instead of wrapping.

I have spent the last half hour working with Chrome's Inspector and Firefox's DOM inspector - all to no avail. I just cannot figure out why it's doing this.

Update: Here is a screenshot of http://stackmobile.com/view_question.php?site=stackoverflow&id=3058417

+2  A: 

You're looking in the wrong place. It's not the paragraph tag, I'm almost certain it's the <pre> block in DJTripleThreat's answer. Notice that the behavior starts as soon as you resize the window below the width of that pre block.

This is quite normal. By design, text in a pre-formatted block does not get reflowed, and it will stop its parent container from being properly resized below its width.

Nicholas Knight
How can I force the block to be a certain width? I don't even care if it gets cut off.
George Edison
+5  A: 

The <pre><code> is what's doing it.

If you modified it like this:

<pre style="overflow:auto;max-width: 90%;">

Then a scrollbar will appear if it will go outside the lines. Adjust the max-width property to get the effect you like.

Or you could do this in your css:

pre {
  overflow: auto;
  max-width: 90%;
}

More information about the <pre> tag.


EDIT. Wow, your screenshot is ~ 400 pixels wide. 90% not working at that width. Hardcoding a width does the trick:

<pre style="overflow:auto;max-width: 400px;">

Or

pre {
  overflow: auto;
  max-width: 400px;
}
artlung
The HTML for the answers is being fetched from a third party so that added a bit of a challenge :)
George Edison
Fun! Best of luck to you!
artlung
The problem with specifying a width manually, is that different device's screens will be different sizes - and thus the layout will only work on some of them.
George Edison
Can you do something like add a class to the body based on device, sort of how Modernizr work? Then you can specify have `.android pre` `.ipad pre` `.iphone3g pre` or whatever. Would make a good new question, how to handle stylesheet or selector switching using CSS, JS, or CSS+JS!
artlung
@artlung: Ya but then I'm switching over a huge number of devices and such. Is there a way to indicate that the block should be xx% of its parent and **no more than that**?
George Edison
@artlung: Also, I can change the content on the fly with PHP. Is there a PRE or CODE equivalent that won't suffer from this? Could I repurpose a DIV for this?
George Edison
Yeah, huge number of devices = bummer. As to your second idea, CSS has a "white-space" attribute: http://www.w3schools.com/css/pr_text_white-space.asp `pre { white-space: pre-line; }` seems promising.
artlung
Oh, I didn't answer your % width of parent... not that I know of, but... maybe.
artlung
@artlung: Well thanks for your help. I decided to try rewriting the HTML on-the-fly with a complicated regular expression. (Don't worry - the HTML is guaranteed to be syntactically correct.)
George Edison
It works great now! I have the line breaks converted to `<br>`'s and that seems to do the trick - that and a monospace font.
George Edison
Excellent! Glad I could help!
artlung
A: 

Simple example of relative css width. You set the width of the table to 100%, but did not set a property for the <p> other tags.

A simple solution could be(a change in style.css:76):

.answer_content {
  width: 80%;
}

Tested to work on Chrome 6.

digitalFresh