我有一个页面,看起来像这样现在:定位按百分比在foreach
,并为这个代码是:
<?php
$count_axle = $database->count_axles($_GET['train_id']);
foreach($count_axle as $counting){
}?>
<div id="axle_bogie_border">
<img id="count_train_image" src="Images/add_train1.png" alt="Train look" style="width:<?php echo $counting['totaldistance']; ?>%">
<?php
$show_axle = $database->axles($_GET['train_id']);
?>
<div id="axle_position_count">
<?php
foreach($show_axle as $axlefigure){ ?>
<div id="count_axle_figure" style="margin-left:<?php echo $counting['totaldistance']; ?>%">
<?php echo $axlefigure['axle'] ?>
</div>
<?php
}
?><br /><br /><br />
</div>
</div>
而CSS:
#axle_bogie_border {
border: 2px solid black;
width: 100%;
height: auto;
overflow-x: scroll;
white-space: nowrap;
}
#count_train_image{
margin-left: 10%;
margin-right: 10%;
height: 100px;
display: inline-block;
position: relative;
float: left;
}
#show_length{
border-bottom: 2px solid black;
width: 100%;
}
#show_length2{
border-bottom: 2px solid black;
width: 10%;
}
#axle_position_count {
margin-top: 10%;
margin-left: 10%;
}
#count_axle_figure {
background: black;
width: 40px;
height: 40px;
border-radius: 50px;
float: left;
}
没错。所以我根据数据库的总和制作图像的宽度。举个例子。你看到的每个圆圈(在这个例子中是4个)都有一个距离。洙:
- 轴1 = 2000
- 车轴2 = 8000
- 轴3 = 2000
- 轴4 = 8000
在总这是20.000毫米20.000毫米=20米。所以这列火车是20米。现在我这个规模下降到percantages:(见图片宽度)
function count_axles($id) {
$sql = "SELECT (sum(distance))/(25000)*(100) as totaldistance from axle WHERE train_id = :train_id";
$sth = $this->pdo->prepare($sql);
$sth->bindParam(":train_id", $id, PDO::PARAM_STR);
$sth->execute();
return $sth->fetchAll();
}
在这里,我告诉大家,100%是25.000毫米(25米)。 现在我也需要这个轴位置。
所以轴1 =例如总数的10%。所以我需要左边10%(保证金)
车轴2 = 5%。所以我需要车轴1+ 5%=左侧15%。 等
每个轴都有自己的ID(这里的DB图像)
所以最终我想最终的结果需要看起来像一个小火车。 (所以前两个车轴离开,最后2个车轴向右)在火车图像下。 像这样:
您可能会发现[这](http://codepen.io/jbutler483/pen/VYzKaP:
所以,你可以仅仅通过chnaging的
axles
值像在这个片段中播放)在定位方面的使用 – jbutler483看起来很有前途@ jbutler483。我看看它! :) – Mitch
你的代码中有四次id count_axle_figure。这是不可能的,一个ID只能在页面上出现一次。车轮应该使用float:left和float:right来显示。因此,你应该有两个班级,一个留给轮子,另一个留给轮子。那么你不需要添加样式到div#count_axle_figure。 –