试图将文本置于回声中心

im trying to set the text like this

enter image description herei have tried with

  • display flex,

  • position absolute,

  • flex-direction,

  • float:left,

and nothing working on the echo

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

}
?>

You should wrap your items in a container, see the container as a row and the "servers" within as horizontal columns.

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