更新
看到你是什么后尝试以下:
为节类添加类变量
使用那里的三元运算符来设置它。
使用 CSS 更改定位。
如果您需要更改布局,这将使 CSS 更加负责定位,并且可能会减少重构 php 代码。
<?php
$sectionClass = "" #new class for section
$result1 = db_getarticles( array('campaigns_id' => $SYS_campaign) );
if (!is_null($result1)) {
while ( $row = $result1->fetch_object() ) {
#set section class as needed
$sectionClass = ($sectionClass == "section" ? "section alt" : "section");
?>
<div class="<?php echo $sectionClass ?>">
<?php
echo "<img src='$SYS_folder/images/articles/$row->imagearticle' alt='' />";
?>
<div class="info">
<h2>
<?php
echo $row->titlearticle;
?>
</h2>
<?php
echo $row->descparticle;
?>
</div>
</div>
<?php
}
}
?>
现在使用以下 CSS:
.section{width:500px; height:200px; clear:both;}
.section img{width:402px; height:178px;float:left}
.section .info {float:right}
/*Swap Position Of image and description*/
.section.alt img{float:right}
.section.alt .info {float:left; }
来自 HTML 的示例:http: //jsfiddle.net/FttQ5/3/
结束更新
如果将来,请在解决您的问题方面付出更多努力。
我曾经display:inline-block
给你你的2列。inline-block
请参阅有关使用over的利弊的文章floats
更改您的 php 以生成以下 HTML
<div class="section">
<div class="leftinfo">
<img style='height:178px;width:402px;' src='' alt='' />
</div>
<div class="rightinfo"> <strong>Title 1</strong>
<br />Dscription 1</div>
</div>
<div class="section">
<div class="leftinfo" >
<img style='height:178px;width:402px;' src='' alt='' />
</div>
<div class="rightinfo"> <strong>Title 2</strong>
<br />Dscription 2</div>
</div>
现在添加以下 CSS
.section {
position:relative;
margin-bottom:5px;
}
.section .leftinfo, .section .rightinfo {
display:inline-block;
vertical-align:top;
}
.leftinfo{ height:178px;width:408;}
示例:http: //jsfiddle.net/FttQ5/1/
请注意,您最好将您的标题放在适当的hx
标签中,例如h1
....h6
并且图像可以使用 CSS 类进行样式设置。例如:
.section img {height:178px;width:402px; }
此外,根本没有理由将图像包裹在 adiv
中
稍微优化的例子:http: //jsfiddle.net/FttQ5/2/