How can I link words in a table cell so that it does not disrupt the flow of the table?

I have the following HTML and PHP:

        <?php
            if ($_POST["submit"] == "Get Articles") {
                $api_url = "https://DonutJuice:so%20many%20people%20in%20my%20bed@api.pinboard.in/v1/posts/all?format=json";

                $ch = curl_init();

                curl_setopt($ch, CURLOPT_URL, $api_url);
                curl_setopt($ch, CURLOPT_HEADER, FALSE);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

                $json = curl_exec($ch);

                curl_close($ch);

                $values = json_decode($json, true);

                echo "<div class='article-output'>";
                echo "<table>";
                echo "<tr><th>URL</th> <th>Title</th></tr>";

                foreach ($values as $bookmark) {
                    $bookmark_url = $bookmark["href"];
                    $bookmark_title = $bookmark["description"];
                    echo "<tr><td><a href='" . $bookmark_url . "'>" . $bookmark_url . "</a></td> <td>" . $bookmark_title . "</td></tr>";
                }

                echo "</table>";
                echo "</div>";
            }
        ?>

Using this CSS:

table {
    margin-top: 50px;
    padding: 5px 20px;

    background: rgba(255, 255, 255, 0.5);
    border: 1px solid #a9a8a7;
    border-radius: 5px;
}

tr {
    height: 50px;
}

th {
    color: #173769;
}

td {
    width: 60px;
    word-wrap: break-word;

    color: #444;
}

    td:first-child {
        padding-right: 30px;
    }

But whenever I click on a button that processes this PHP, I get things like this:

enter image description here

Where they still violate the page layout mercilessly.

How to fix it?

+5
source share
3 answers

Property word-breakcan cause wrapping to occur when lines are too long

http://tinker.io/ca0ae

td {
    word-break: break-all;
    word-break: break-word;
}
+3
source

You can always do this on the PHP side :

echo "<tr><td><a href='" . $bookmark_url . "'>" . wordwrap($bookmark_url, 40, "\n") . "</a></td> <td>" . $bookmark_title . "</td></tr>";
+1
source

Edit tdin CSS:

td {
    width: 60px;
    color: #444;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}
0
source

All Articles