开发者

What is the best word-wrapping method?

开发者 https://www.devze.com 2023-04-06 04:04 出处:网络
I have two questions for you guys: Which is the proper way ot word-开发者_如何学Pythonwrap a user made comment? I mean, I

I have two questions for you guys:

  • Which is the proper way ot word-开发者_如何学Pythonwrap a user made comment? I mean, I know this can be done with CSS but maybe it would be safer doing it server-side (with some sort of manipulation of the carriage returns I guess). Which is the best way? What does the W3 recommends?

  • Also, if I want the text to fit the screen, and to adjust it's length to the width of the screen while it's resizing, how do I do that?

    I've seen it many times in many websites but I'm not sure of how that works. Is this done with the wordwrap PHP function or some style in CSS?

Thanks :)


W3 would recommend using CSS I'd imagine. Word wrapping is far easier client side than it is server side. However, the browser should do this for you anyway and you don't need to do anything.

To fit text to screen, just use a div or another block object. This will take the width of the screen and the browser will handle the word wrapping for you.

For example

CSS word-wrapping only if you need to force wrapping.

div { word-wrap: break-word } 
<div style="word-wrap: break-word">Long content here that will wrap automatically by thte browser, but you can force it with CSS break-word</div>


Unless you use <pre>, \n won't create a line break in the html code, so wordwrap only helps to keep the lines in the source code short so it's easier to read.

Depending on the font used by the browser the characters will be of different length, so it's best to use css for wrapping. I think it's enough to define a width for the container tag (<div>) and the browser will do the rest.

0

精彩评论

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

关注公众号