次のコードは、可能な 4 つの背景画像のうちの 1 つを、対応する背景色でデスクトップ ブラウザーに表示するのに適切に機能します ( methodally.comを参照)。ただし、iOS では背景が白の場合にのみ画像が表示されます。色付きの背景が表示されている場合、画像は表示されません。すべての画像はほぼ同じサイズです。何かご意見は?
更新:配列の順序を切り替えてみました。運がない。白い背景と関連する画像が配列の最後にある場合でも、これが iOS に表示される唯一の組み合わせです。
これが私のindex.php
ファイルです:
<?php
$bl = array('logo-white.png', 'logo-pink.png', 'logo-blue.png', 'logo-teal.png' );
$bc = array('#fdfdfe', '#b0265d', '#040442', '#43a5ae' );
$i = rand(0, count($bl)-1); // generate random number size of the array
$selectedBl = "$bl[$i]"; // set variable equal to which random filename was chosen
$selectedBc = "$bc[$i]"; // set variable equal to corresponding background color
?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
html {
width:100%;
height:100%;
background: <?php echo $selectedBc; ?> url(/img/<?php echo $selectedBl; ?>) center center no-repeat;
background-size:60%;
}
</style>
</head>
<body>
</body>
</html>