试图使回声中的文本居中

时间:2019-05-20 11:29:53

标签: php css

我试图设置这样的文本

enter image description here 我已经尝试过

  • 显示功能,

  • 绝对位置

  • 弹性方向

  • float:left

  

在回波上没有任何作用

<?php
$servers = array('30120' => 1, '30121' => 2, '30122' => 3);

foreach ($servers as $key => $value) {

    $server = json_decode(@file_get_contents("http://xxxxxxxxx:$key/players.json"), true);

    if ($server) {
        $players = count($server);
        $key = "<p style=color:green;>Online</p><p>$players/32";
    } else {
        $key = "<p style=color:red;>Offline</p>";
    }

    echo "<h3>Server $value:</h3>";
    echo $key;
    echo "<br>";

}
?>

1 个答案:

答案 0 :(得分:0)

您应该将项目包装在一个容器中,将容器看成一行,将其中的“服务器”看成水平列。

$servers = array('30120' => 1, '30121' => 2, '30122' => 3);

echo "<div style=\"display:flex;text-align: center\">"; // the row
  foreach ($servers as $key => $value) {

    $server = json_decode(@file_get_contents("http://xxxxxxxxx:$key/players.json"), true);

    if ($server) {
        $players = count($server);
        $key = "<p style=color:green;>Online</p><p>$players/32";
    } else {
        $key = "<p style=color:red;>Offline</p>";
    }

    echo "<div>"; // column
    echo "<h3>Server $value:</h3>";
    echo $key;
    echo "</div>";
}
echo "</div>";