我有以下HTML和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>";
}
?>
使用这个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;
}
但每当我按下处理该PHP的按钮时,我就会得到这样的结果:
他们仍在无情地打破页面布局。
我该如何解决这个问题?
答案 0 :(得分:4)
word-break
属性可能会在行太长时强制换行
td {
word-break: break-all;
word-break: break-word;
}
答案 1 :(得分:1)
您可以随时在PHP side:
上执行此操作echo "<tr><td><a href='" . $bookmark_url . "'>" . wordwrap($bookmark_url, 40, "\n") . "</a></td> <td>" . $bookmark_title . "</td></tr>";
答案 2 :(得分:0)
在CSS中修改td
:
td {
width: 60px;
color: #444;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}