简体   繁体   English

PHP中的自动换行

[英]Word-wrap in php

Here in content-full class I have used word-wrap: break-word; 在内容完整的课程中,我使用了自动换行:break-word; still the text do not appear in proper format?What could be the possible solution to it?Is there some way to get a proper format so as to Allow long words to be able to break and wrap onto the next line.But wierd part is that for content-short word-wrap:break-word is working! 仍然没有以正确的格式显示文本吗?可能的解决方案是什么?是否有某种方法来获取正确的格式以便允许长单词能够折断并换行到下一行。对于内容简短的自动换行:断行有效!

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>";  
?>  

and the styling for content-full 以及完整内容的样式

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

UPDATE : 更新:

if it is external , it will be like : 如果是外部的,它将像:

<link rel="stylesheet" type="text/css" href="pathto.css">

the parent div bypass this div style , try to change the style of parent div like the following : 父div绕过此div样式,请尝试更改父div的样式,如下所示:

change this line : 更改此行:

 echo "<div class='grid-item item1' style='position: relative; left: 240px; top: 0px; background: ".ran_col().";'>";

by this : 这样 :

 echo "<div class='grid-item item1' style='position: relative; word-wrap: break-word; left: 240px; top: 0px; background: ".ran_col().";'>";

it will inherit your mentioned div 它将继承您提到的div

Is this what you want to accomplish? 这是您要完成的吗? https://jsfiddle.net/9s2zr7gL/ If so, just add this to your current CSS: https://jsfiddle.net/9s2zr7gL/如果是这样,只需将其添加到当前CSS中即可:

-ms-word-break: break-all;
 word-break: break-word;
-webkit-hyphens: auto;
   -moz-hyphens: auto;
    -ms-hyphens: auto;
        hyphens: auto;

You also need to add "lang=en" as a parameter in your div. 您还需要在div中添加“ lang = en”作为参数。 Otherwise it won't work in firefox. 否则,它将无法在Firefox中使用。 If your text is not in English, check if the language is supported: https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens 如果您的文字不是英语,请检查是否支持该语言: https : //developer.mozilla.org/en-US/docs/Web/CSS/hyphens

i encountered the same problem you i am using a text from docx file and while uploading i used pre tags so then word-wrap do not work properly. 我遇到了同样的问题,您正在使用docx文件中的文本,并且在上载时使用了预标签,因此自动换行功能无法正常使用。 if this is your case remove pre tags. 如果是这种情况,请删除前置标签。

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

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