Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    me2
    me2 is offline
    New Coder
    Join Date
    Oct 2007
    Posts
    88
    Thanks
    8
    Thanked 3 Times in 3 Posts

    pre tag ignores width attribute

    when i use the pre tag on text it seems that it continues on in a line if it doesnt have \n is there a way to wrap the text so it doesnt continue on in a line forever??

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,667
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    That's the beauty of the pre tag - it follows the previous formatting.
    If you want it to break, put it in <p> tags.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #3
    me2
    me2 is offline
    New Coder
    Join Date
    Oct 2007
    Posts
    88
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Code:
    <p class="eventinfo"><pre>REally long one lined text line does not seem to work as it does not wrap still</pre></p>
    Is that right??

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,667
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    No.
    The pre tag is for quoting pre-formatted text. Like a paragraph straight from a Word document when you would like to keep the same line breaks and indentation.
    <p></p> is paragraph tags

    For your sentence to break it should be <p>REally long one lined text line does not seem to work as it does not wrap still</p> . That will break if the containing div it's in is too narrow to fit it on one line.

    Of course, some will say since that is only one sentence it should not be enclosed in paragraph tags.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,274
    Thanks
    28
    Thanked 271 Times in 265 Posts
    Quote Originally Posted by me2 View Post
    when i use the pre tag on text it seems that it continues on in a line if it doesnt have \n is there a way to wrap the text so it doesnt continue on in a line forever??
    It sounds like you want the functionality of one of the CSS2.1 white-space: pre-wrap or white-space: pre-line [1] declarations; youíd apply either to the pre element to alter its line‐breaking behavior. Unfortunately, neither appear to be well‐supported. [2]

    As an alternative to trying to control line‐wrapping, you might use the overflow property to specify what should happen to excess content. For example, you could provide a scrollbar with the overflow: auto or overflow: scroll declarations.

    You might want to make it more clear what effect youíre trying to achieve though. Right now, I canít tell if either of the above are really solutions to your issue because Iím not sure what the issue actually is; if I took your question literally, the answer might simply be ďdonít use a pre elementĒ (as Excavator has already proposed).

    Quote Originally Posted by Excavator View Post
    No.
    The pre tag is for quoting pre-formatted text. Like a paragraph straight from a Word document when you would like to keep the same line breaks and indentation.
    If you were copying a real paragraph (as opposed to a Word paragraph), you would probably want to use both elements (pre and p). Better examples (from a semantic standpoint), might be use of a pre element for the preservation of line‐breaks in poetry or code.

    Quote Originally Posted by Excavator View Post
    Of course, some will say since that is only one sentence it should not be enclosed in paragraph tags.
    Iíd say that a one sentence paragraph is fine; itís grammatically correct English anyway. The problem is when people stick non‐sentence content in the element and treat it as if it were a Microsoft Word paragraph (which happens to simply be a line‐break).

    Of course, one might argue that ďREally long one lined text line does not seem to work as it does not wrap stillĒ isnít actually a sentence since it contains several grammatical errors.

    1. http://www.w3.org/TR/2007/CR-CSS21-2...ef-white-space
    2. http://www.webdevout.net/browser-sup...sic-whitespace
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •