这里就是我试图完成:如何在X,Y坐标下使用WHILE和/或FOREACH循环创建DIV框?
- 位置的每个DIV /盒到适当的X,Y在另一个DIV 帮助协调这里PLZ
我希望每个位置DIV /框到其在“map_size”DIV中的适当坐标。我所有的盒子都被放在一条直线上。提前致谢。我只想使用HTML,PHP和CSS。
我想要什么(不是地图的所有四个区域,只有一个):
: http://www.chem.utoronto.ca/coursenotes/analsci/stats/images/2D_Centroid.gif我的html文件的PHP顶部
<?php include 'db_conn.php'; //query to get X,Y coordinates from DB $coord_sql = "SELECT x_coord, y_coord FROM coordinates"; $coord_result = mysqli_query($conn,$coord_sql); //see if query is good if($coord_result === false) { die(mysqli_error()); } ?>
其他php部分只有DIV:
<div id="map_size" align="center">
<?php
//get number of rows for X,Y coords in the table
while($row = mysqli_fetch_assoc($coord_result)){
//naming X,Y values
$x_pos = $row['x_coord'];
$y_pos = $row['y_coord'];
//draw a box with a DIV at its X,Y coord
echo "<div id='desk_box' style='style:absolute;
left: " . $x_pos. " px;
top: " . $y_pos. " px;'>box number</div>";
} //end while coord_result loop
?>
</div> <!-- end div map_Size -->
我的CSS文件:你想要什么
body{
margin:0px auto;
width:80%;
height:80%;
}
#map_size{
width:800px;
height:800px;
background:#0099FF;
border-style: solid;
border-color: black;
}
#desk_box{
width: 20px;
height: 30px;
border:5px solid black;
margin: 10px;
}
没有位置:center。 – coopersita 2014-10-01 18:49:56
究竟在哪里?我刚才更新了我的代码 – mario 2014-10-01 18:52:16
#map_size有位置:中心 – coopersita 2014-10-01 18:53:06