所以,我正在为摄影师写一个自定义网站。我试图让它先移动,并确保一切都可以工作,没有JavaScript。我决定使用php while循环来创建一个非常长的字符串,用于我在一些html旁边注入的脚本标记。我不想把它放到CSS中,因为我相信我将来必须稍微改变它。无论如何,循环非常简单,但它提前结束。真的很早,我不知道为什么。我想知道它是否只是超时,但我不能确定。任何有关解决此问题的帮助表示赞赏:
<?php
echo "<style>";
$imgClass = "hzPic";
$i0 = 20;
$theString = "";
while($i0 < 200){
$theString = $theString."@media screen and (min-height:".($i0*10)."px){ .".$imgClass."s{ height: ".($i0 - 13)."em; } }\n";
++$i0;
}
echo $theString;
echo "</style>";
?>
修改
@media screen and (min-height:200px){ .hzPics{ height: 7em; } }
@media screen and (min-height:210px){ .hzPics{ height: 8em; } }
@media screen and (min-height:220px){ .hzPics{ height: 9em; } }
@media screen and (min-height:230px){ .hzPics{ height: 10em; } }
@media screen and (min-height:240px){ .hzPics{ height: 11em; } }
@media screen and (min-height:250px){ .hzPics{ height: 12em; } }
@media screen and (min-height:260px){ .hzPics{ height: 13em; } }
@media screen and (min-height:270px){ .hzPics{ height: 14em; } }
@media screen and (min-height:280px){ .hzPics{ height: 15em; } }
@media screen and (min-height:290px){ .hzPics{ height: 16em; } }
@media screen and (min-height:300px){ .hzPics{ height: 17em; } }
@media screen and (min-height:310px){ .hzPics{ height: 18em; } }
@media screen and (min-height:320px){ .hzPics{ height: 19em; } }
@media screen and (min-height:330px){ .hzPics{ height: 20em; } }
@media screen and (min-height:340px){ .hzPics{ height: 21em; } }
@media screen and (min-height:350px){ .hzPics{ height: 22em; } }
@media screen and (min-height:360px){ .hzPics{ height: 23em; } }
@media screen and (min-height:370px){ .hzPics{ height: 24em; } }
@media screen and (min-height:380px){ .hzPics{ height: 25em; } }
@media screen and (min-height:390px){ .hzPics{ height: 26em; } }
@media screen and (min-height:400px){ .hzPics{ height: 27em; } }
@media screen and (min-height:410px){ .hzPics{ height: 28em; } }
@media screen and (min-height:420px){ .hzPics{ height: 29em; } }
@media screen and (min-height:430px){ .hzPics{ height: 30em; } }
@media screen and (min-height:440px){ .hzPics{ height: 31em; } }
@media screen and (min-height:450px){ .hzPics{ height: 32em; } }
@media screen and (min-height:460px){ .hzPics{ height: 33em; } }
@media screen and (min-height:470px){ .hzPics{ height: 34em; } }
@media screen and (min-height:480px){ .hzPics{ height: 35em; } }
@media screen and (min-height:490px){ .hzPics{ height: 36em; } }
@media screen and (min-height:500px){ .hzPics{ height: 37em; } }
@media screen and (min-height:510px){ .hzPics{ height: 38em; } }
@media screen and (min-height:520px){ .hzPics{ height: 39em; } }
@media screen and (min-height:530px){ .hzPics{ height: 40em; } }
@media screen and (min-height:540px){ .hzPics{ height: 41em; } }
@media screen and (min-height:550px){ .hzPics{ height: 42em; } }
@media screen and (min-height:560px){ .hzPics{ height: 43em; } }
@media screen and (min-height:570px){ .hzPics{ height: 44em; } }
@media screen and (min-height:580px){ .hzPics{ height: 45em; } }
@media screen and (min-height:590px){ .hzPics{ height: 46em; } }
@media screen and (min-height:600px){ .hzPics{ height: 47em; } }
@media screen and (min-height:610px){ .hzPics{ height: 48em; } }
@media screen and (min-height:620px){ .hzPics{ height: 49em; } }
@media screen and (min-height:630px){ .hzPics{ height: 50em; } }
@media screen and (min-height:640px){ .hzPics{ height: 51em; } }
@media screen and (min-height:650px){ .hzPics{ height: 52em; } }
@media screen and (min-height:660px){ .hzPics{ height: 53em; } }
@media screen and (min-height:670px){ .hzPics{ height: 54em; } }
@media screen and (min-height:680px){ .hzPics{ height: 55em; } }
@media screen and (min-height:690px){ .hzPics{ height: 56em; } }
@media screen and (min-height:700px){ .hzPics{ height: 57em; } }
@media screen and (min-height:710px){ .hzPics{ height: 58em; } }
@media screen and (min-height:720px){ .hzPics{ height: 59em; } }
@media screen and (min-height:730px){ .hzPics{ height: 60em; } }
@media screen and (min-height:740px){ .hzPics{ height: 61em; } }
@media screen and (min-height:750px){ .hzPics{ height: 62em; } }
@media screen and (min-height:760px){ .hzPics{ height: 63em; } }
@media screen and (min-height:770px){ .hzPics{ height: 64em; } }
@media screen and (min-height:780px){ .hzPics{ height: 65em; } }
@media screen and (min-height:790px){ .hzPics{ height: 66em; } }
@media screen and (min-height:800px){ .hzPics{ height: 67em; } }
@media screen and (min-height:810px){ .hzPics{ height: 68em; } }
@media screen and (min-height:820px){ .hzPics{ height: 69em; } }
@media screen and (min-height:830px){ .hzPics{ height: 70em; } }
@media screen and (min-height:840px){ .hzPics{ height: 71em; } }
@media screen and (min-height:850px){ .hzPics{ height: 72em; } }
@media screen and (min-height:860px){ .hzPics{ height: 73em; } }
@media screen and (min-height:870px){ .hzPics{ height: 74em; } }
@media screen and (min-height:880px){ .hzPics{ height: 75em; } }
@media screen and (min-height:890px){ .hzPics{ height: 76em; } }
@media screen and (min-height:900px){ .hzPics{ height: 77em; } }
@media screen and (min-height:910px){ .hzPics{ height: 78em; } }
@media screen and (min-height:920px){ .hzPics{ height: 79em; } }
@media screen and (min-height:930px){ .hzPics{ height: 80em; } }
@media screen and (min-height:940px){ .hzPics{ height: 81em; } }
@media screen and (min-height:950px){ .hzPics{ height: 82em; } }
@media screen and (min-height:960px){ .hzPics{ height: 83em; } }
@media screen and (min-height:970px){ .hzPics{ height: 84em; } }
@media screen and (min-height:980px){ .hzPics{ height: 85em; } }
@media screen and (min-height:990px){ .hzPics{ height: 86em; } }
@media screen and (min-height:1000px){ .hzPics{ height: 87em; } }
@media screen and (min-height:1010px){ .hzPics{ height: 88em; } }
@media screen and (min-height:1020px){ .hzPics{ height: 89em; } }
@media screen and (min-height:1030px){ .hzPics{ height: 90em; } }
@media screen and (min-height:1040px){ .hzPics{ height: 91em; } }
@media screen and (min-height:1050px){ .hzPics{ height: 92em; } }
@media screen and (min-height:1060px){ .hzPics{ height: 93em; } }
@media screen and (min-height:1070px){ .hzPics{ height: 94em; } }
@media screen and (min-height:1080px){ .hzPics{ height: 95em; } }
@media screen and (min-height:1090px){ .hzPics{ height: 96em; } }
@media screen and (min-height:1100px){ .hzPics{ height: 97em; } }
@media screen and (min-height:1110px){ .hzPics{ height: 98em; } }
@media screen and (min-height:1120px){ .hzPics{ height: 99em; } }
@media screen and (min-height:1130px){ .hzPics{ height: 100em; } }
@media screen and (min-height:1140px){ .hzPics{ height: 101em; } }
@media screen and (min-height:1150px){ .hzPics{ height: 102em; } }
@media screen and (min-height:1160px){ .hzPics{ height: 103em; } }
@media screen and (min-height:1170px){ .hzPics{ height: 104em; } }
@media screen and (min-height:1180px){ .hzPics{ height: 105em; } }
@media screen and (min-height:1190px){ .hzPics{ height: 106em; } }
@media screen and (min-height:1200px){ .hzPics{ height: 107em; } }
@media screen and (min-height:1210px){ .hzPics{ height: 108em; } }
@media screen and (min-height:1220px){ .hzPics{ height: 109em; } }
@media screen and (min-height:1230px){ .hzPics{ height: 110em; } }
@media screen and (min-height:1240px){ .hzPics{ height: 111em; } }
@media screen and (min-height:1250px){ .hzPics{ height: 112em; } }
@media screen and (min-height:1260px){ .hzPics{ height: 113em; } }
@media screen and (min-height:1270px){ .hzPics{ height: 114em; } }
@media screen and (min-height:1280px){ .hzPics{ height: 115em; } }
@media screen and (min-height:1290px){ .hzPics{ height: 116em; } }
@media screen and (min-height:1300px){ .hzPics{ height: 117em; } }
@media screen and (min-height:1310px){ .hzPics{ height: 118em; } }
@media screen and (min-height:1320px){ .hzPics{ height: 119em; } }
@media screen and (min-height:1330px){ .hzPics{ height: 120em; } }
@media screen and (min-height:1340px){ .hzPics{ height: 121em; } }
@media screen and (min-height:1350px){ .hzPics{ height: 122em; } }
@media screen and (min-height:1360px){ .hzPics{ height: 123em; } }
@media screen and (min-height:1370px){ .hzPics{ height: 124em; } }
@media screen and (min-height:1380px){ .hzPics{ height: 125em; } }
@media screen and (min-height:1390px){ .hzPics{ height: 126em; } }
@media screen and (min-height:1400px){ .hzPics{ height: 127em; } }
@media screen and (min-height:1410px){ .hzPics{ height: 128em; } }
@media screen and (min-height:1420px){ .hzPics{ height: 129em; } }
@media screen and (min-height:1430px){ .hzPics{ height: 130em; } }
@media screen and (min-height:1440px){ .hzPics{ height: 131em; } }
@media screen and (min-height:1450px){ .hzPics{ height: 132em; } }
@media screen and (min-height:1460px){ .hzPics{ height: 133em; } }
@media screen and (min-height:1470px){ .hzPics{ height: 134em; } }
@media screen and (min-height:1480px){ .hzPics{ height: 135em; } }
@media screen and (min-height:1490px){ .hzPics{ height: 136em; } }
@media screen and (min-height:1500px){ .hzPics{ height: 137em; } }
@media screen and (min-height:1510px){ .hzPics{ height: 138em; } }
@media screen and (min-height:1520px){ .hzPics{ height: 139em; } }
@media screen and (min-height:1530px){ .hzPics{ height: 140em; } }
@media screen and (min-height:1540px){ .hzPics{ height: 141em; } }
@media screen and (min-height:1550px){ .hzPics{ height: 142em; } }
@media screen and (min-height:1560px){ .hzPics{ height: 143em; } }
@media screen and (min-height:1570px){ .hzPics{ height: 144em; } }
@media screen and (min-height:1580px){ .hzPics{ height: 145em; } }
@media screen and (min-height:1590px){ .hzPics{ height: 146em; } }
@media screen and (min-height:1600px){ .hzPics{ height: 147em; } }
@media screen and (min-height:1610px){ .hzPics{ height: 148em; } }
@media screen and (min-height:1620px){ .hzPics{ height: 149em; } }
@media screen and (min-height:1630px){ .hzPics{ height: 150em; } }
@media screen and (min-height:1640px){ .hzPics{ height: 151em; } }
@media screen and (min-height:1650px){ .hzPics{ height: 152em; } }
@media screen and (min-height:1660px){ .hzPics{ height: 153em; } }
@media screen and (min-height:1670px){ .hzPics{ height: 154em; } }
@media screen and (min-height:1680px){ .hzPics{ height: 155em; } }
@media screen and (min-height:1690px){ .hzPics{ height: 156em; } }
@media screen and (min-height:1700px){ .hzPics{ height: 157em; } }
@media screen and (min-height:1710px){ .hzPics{ height: 158…
这是我得到的实际输出。正如你所看到的,对我来说它停在171左右。我似乎无法弄清楚为什么。 是的,我希望它能够连接起来。
答案 0 :(得分:0)
您需要使用串联.
来加入字符串。我不确定早期完成是什么意思。您可以使用$i++
(后添加)代替++$i
(之前添加)。
echo "<style>";
$imgClass = "hzPic";
$i = 20;
$theString = "";
while($i < 200){
$theString .= '@media screen and (min-height:'.($i*10).'px){ .'.$imgClass.'s{ height: '.($i - 13).'em; } }';
++$i;
}
echo $theString;