Welcome to WebmasterWorld Guest from 54.145.176.120

Forum Moderators: incrediBILL

Message Too Old, No Replies

Assign a max width attribute to a <PRE> tag

Is it possible?

   
1:07 pm on Oct 17, 2005 (gmt 0)

5+ Year Member



I am trying to output some system messages on a linux server directly to a browser and must use the <pre> tag to keep the formatting on the text that is dumped out.

Problem is if the text is over a certain length the table the text is in expands to make the text fit. Is there a way to stop this from happening? CSS would be preferable as it means I can lose the table completly.

Any help appreciated...

1:11 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep. I'd suggest having the <pre> element scroll when the content gets too big to fit it. Something like:

pre { overflow: auto; width; 300px; }

Replace 300 with the width you want of course.

1:29 pm on Oct 17, 2005 (gmt 0)

5+ Year Member



Thought about that one and it does work the only problem is it looks really ugly...

What I was wanting really was something that would dump the remainder of the string onto the next line by splitting it. Perhaps it can be done with Javascript but I have no idea...

Thanks for the input, any other ideas appreciated...

2:00 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, I've had a flick through the specs and this [w3.org] seems to fit your requirements, but I have no idea what browser support is like:

pre { white-space: pre-wrap; }
2:17 pm on Oct 17, 2005 (gmt 0)

5+ Year Member



Thats the problem there is no whitespace, consider a long url e.g.

.com?a=longword1&b=longword2&c=longword3&d=longword4&e=longword5

There is no whitespace there so it wont work. The only option I can really see is to not use a <pre> tag but that sort of defeats the purpose of the script as it collapses the output into 1 long string of data.

Oh well the scrollbars idea will have to suffice for now but if anyone knows something I dont please tell me :)

Thanks for the help so far...

5:49 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



Why not process the message with your script before it goes into the pre tags? If you are using PHP you can use wordwrap() [uk.php.net] or chunk_split() [uk.php.net] to chop it up.
7:32 am on Oct 18, 2005 (gmt 0)

5+ Year Member



Ill check it out, sounds like what I am looking for thanks.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month