我想在水平行中创建4个按钮。我使用变量来设置' x'坐标。
我有这段代码。
<?php
$x=0;
while ($x<1000)
{
echo $x;
echo '<div style="position: absolute;top: 0; left: '.$x.';width: 200px;">
<button style="width: 200px; height: 125px" onclick="this.parentElement.style.display=\'none\'" class="w3-button w3-red"></button>
</div>';
$x=$x+250;
}
?>
但它只显示一个按钮而不是我期待的4个按钮。我无法看到问题出在哪里......
答案 0 :(得分:1)
您在离开后错过了一个px:
echo '<div style="position: absolute;top: 0; left: '.$x.'px;width: 200px;">
<div class="section result" style="margin-top:80px;">
0
<div style="position: absolute;top: 0; left: 0;width: 200px;">
<button style="width: 200px; height: 125px" onclick="this.parentElement.style.display='none'" class="w3-button w3-red">1</button>
</div>250
<div style="position: absolute;top: 0; left: 250px;width: 200px;">
<button style="width: 200px; height: 125px" onclick="this.parentElement.style.display='none'" class="w3-button w3-red">2</button>
</div>500
<div style="position: absolute;top: 0; left: 500px;width: 200px;">
<button style="width: 200px; height: 125px" onclick="this.parentElement.style.display='none'" class="w3-button w3-red">3</button>
</div>750
<div style="position: absolute;top: 0; left: 750px;width: 200px;">
<button style="width: 200px; height: 125px" onclick="this.parentElement.style.display='none'" class="w3-button w3-red">4</button>
</div>
</div>