homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

Assign a max width attribute to a <PRE> tag
Is it possible?

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

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)

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)

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)

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)

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


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...

Longhaired Genius

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

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved