1

So a string is being entered from a database into a paragraph, when the paragraph has spaces the paragraph breaks perfectly but if the string has a word longer than the line it goes off the page as shown below, how can i make it go the the next line instead of off the page?

enter image description here

here is my php and html code:

<div id = "comment">
        <?php
        echo "<div style = 'border-bottom-style: solid;border-bottom-width:1px;'><p class = 'word'>" . $issue . "</p>";
        echo "<p class = 'word info'>" . $author . ' ' . $date . "</p></div>";
        $sql2 = "select * from Ticket_Message where Ticket_Main_id = '$MainId'";
        $query2 = mysqli_query($con,$sql2);
        while ($row = mysqli_fetch_array($query2)){
            $message = $row['message'];
            $auth = $row['auth'];
            $date = $row['date'];
            echo "<div style = 'border-bottom-style: solid; border-bottom-width: 1px;'>";
            echo "<p class = 'word'>" . $message . "</p>";
            echo "<p class = 'word info'>" . $auth . ' ' . $date . "</p>";
            echo "</div>";
        }
        ?>
        </div>

and here is my css attempt to fix it :

p{max-width: 250px;}

basically what i need am trying to do is use css to prevent all paragraphs from extending off the page when the string is longer than the width of the page.

  • http://stackoverflow.com/questions/28688767/whats-the-difference-between-word-break-break-all-and-word-wrap-break-word – Stickers Jul 28 '15 at 15:15

2 Answers2

2

Try:

p { word-wrap: break-word; }

https://developer.mozilla.org/en-US/docs/Web/CSS/word-wrap

Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
2

You don't need any php code here.

Use css property word-wrap

p {
    word-wrap: break-word;
    max-width: 250px;
}

Demo: http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-wrap

Eldar Rakhimberdin
  • 1,042
  • 1
  • 7
  • 10