简体   繁体   English

触发自动换行:CSS中的断行

[英]Triggering word-wrap: break-word in CSS

I have a <div> that contains a <p> in which I want to, when the p is larger than the users' screen (eg a user intentionally posts a long string of characters to break the page layout), cause word-wrap. 我有一个<div>包含一个<p> ,当p大于用户的屏幕时(例如,用户故意发布一长串字符以破坏页面布局),我想在其中包含<p>

The current method I have in place works okay; 我目前使用的方法行得通; setting the <div> 's css to width: 97% , and the <p> to word-wrap: break-word ; <div>的CSS设置为width: 97% ,将<p>word-wrap: break-word but this produces unwanted results if an image is put into the div that exceeds the width (high-resolution images-expanded in place), the image extends outside of the post. 但这会导致不想要的结果,如果将图像放入div中超过宽度的图像(高分辨率图像在适当位置展开),则图像会延伸到桩外。 I of course don't want to set overflow: hidden/scroll on the <div> , because that would obscure the image. 我当然不想设置overflow: hidden/scroll <div>上的overflow: hidden/scroll ,因为那样会使图像模糊。

Is there any way to trigger word-wrap: break-word in a way that will solve both of these problems? 有没有什么办法来触发word-wrap: break-word中,将解决这两个问题的方法吗? Or perhaps another CSS-based solution? 还是另一个基于CSS的解决方案?

Depending on what control you have over the user-generated content, you may be able to apply a style to their images (eg, to all img tags that are a child of the container holding your user's content). 根据您对用户生成的内容的控制程度,您可以将样式应用于其图像(例如,应用于保存用户内容的容器的子代的所有img标签)。

Assuming you can add your own styling to their images, you might be able to do something using max-width. 假设您可以向其图像添加自己的样式,则可以使用max-width进行某些操作。

Wrapping should be default behavior, but try setting your DIV's white-space to normal 包装应该是默认行为,但是请尝试将DIV的空白设置为正常

white-space:normal;

http://www.w3schools.com/css/pr_text_white-space.asp http://www.w3schools.com/css/pr_text_white-space.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM