在 content-full 类中,我使用了 word-wrap: break-word;文本仍然没有以正确的格式出现?可能的解决方案是什么?有什么方法可以获得正确的格式,以便允许长单词能够中断并换行到下一行。但奇怪的部分是对于 content-short word-wrap:break-word 是有效的!
echo "<div class='mainlayout' data-js-module='layout'>";
echo "<div class='grid' style='position: relative;'>";
include "mysql.php";
$query= "SELECT ID,Title,Summary,Content,ImgName,Image FROM content ORDER BY ID DESC";
$result=mysql_query($query,$db);
while($row=mysql_fetch_array($result)) {
echo "<div class='grid-item item1' style='position: relative; left: 240px; top: 0px; background: ".ran_col().";'>";
echo "<div class='content-short' style='position:relative;'>";
$string = $row['Content'];
if (strlen($string) > 200) {
$trimstring = substr($string, 0,200). '...';
}
else {
$trimstring = substr($string,0). '...';
}
echo $trimstring;
echo "</div>";
echo "<div class='content-full'>";
echo $row['Content'];
echo "</div>";
echo "</div>";
}
mysql_close($db);
echo "</div>";
echo "</div>";
?>
以及内容完整的样式
<style type="text/css>
.content-full{
border: 1px;
border-radius: 5px;
word-wrap: break-word;
width: 100%;
height: 100%;
padding: 5px 5px 5px 10px;
overflow-y: auto;
float: left;
background: white;}
.content-short {
float: left;
position: relative;
border: 1px;
border-radius: 5px;
margin: 10px 0 0 10px;
padding: 10px 0 10px 10px;
word-wrap: break-word;
height: auto;
width: 200px;
background: White;}
</style>
最佳答案
我遇到了同样的问题,我正在使用来自 docx 文件的文本,并且在上传时我使用了预标记,因此自动换行无法正常工作。如果是这种情况,请删除前置标签。
关于javascript - php 中的自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32411894/