2013-04-08 59 views
1

我有PHP程序,其中包含div main_wrapper该div有两个子div resultwrapper和adv_right。我希望adv_right div完全在resultwrapper div的右侧。当我使用float时,表示div存在于main_wrapper div之外。Proplem在div右对齐?

<style> 
.resultwrapper{width:990px; margin: 10px auto 10px auto; clear:both; } 
.resultitem{ float: left; 
    height: 170px; 
    margin-bottom: 0px; 
    margin-left: 10px; 
    min-height: 130px; 
    width:218px;} 
.resultleftitem{padding-left:0;margin-left:0px;} 
.resultitem img{border:dotted 1px #666; padding:6px;} 
.resultitem img:hover{border:solid 1px #F60;} 
.resultitem h4{font-size:12px; font-weight:bold; color:#249ce9; margin-top:5px; } 
.resultitem a{color:#249ce9;} 
.resultitem .caption{color:#9c9c9c; font-size:12px; display:block; margin-top:6px; text-align:justify;} 
</style> 
<div class="main_warpper"> 
<div class="resultwrapper"> 
<?php 
while($row = mysql_fetch_array($rs)) { 
     $id=$row['id']; 
     $type=$row['type']; 
     $location=$row['location']; 
     if(file_exists("properties//". $imageloc ."//thumb.jpg")) 
     { 
      $thumb_img="properties/". $imageloc ."/thumb.jpg"; 
     } else { 

      $thumb_img="images/default.jpg"; 
     } 
     if($cnt==0 || $cnt ==4) $newResult=true; else $newResult=false; 

?> 

<div id="parent" > 
    <div class="resultitem <?php if($newResult) echo ' resultleftitem'; ?>" id="resultitem"> <a href="viewpropdetails.php?id=<?php echo $id;?>" target="_blank"> 
    <img id="parent" src="<?php echo $thumb_img; ?>" alt="<?php $new=strtolower($heading); echo ucwords($new); ?>" title="<?php $new=strtolower($heading); echo ucwords($new); ?>" width="100" height="100" /></a> 
     <div class="itemdetails"> 
      <h4 id="linkheading"><a href="viewpropdetails.php?id=<?php echo $id;?>" target="_blank"><?php echo $type ." @ ".$location; ?></a></h4> 
      <span class="box"><?php echo cropStr($desc,$MAX_DESC); ?></span> 

     </div> 
    </div> 
    </div> 

<?php 
    $cnt++; } ?> 
</div> 

<div class="adv_right" style=" clear:both; width:15%; float:right;height:300px; background-color:#999999;"> 
    </div> 
</div> 
+0

main_warpper!= main_wrapper ...你可以使用的jsfiddle或东西可写可读的代码? – Shomz 2013-04-08 06:09:45

+2

http://stackoverflow.com/questions/2716955/css-layout-aligning-two-divs-side-by-side – 2013-04-08 06:10:46

回答

2

请尝试它,

清除:两者;来自股利,并设置宽度ü希望什么,,

请尝试你想这样的代码?

<style> 
.resultwrapper { 
    margin: 10px auto 10px auto; 
} 
.resultitem { 
    float: left; 
    height: 170px; 
    margin-bottom: 0px; 
    margin-left: 10px; 
    min-height: 130px; 
    width:218px; 
} 
.resultleftitem { 
    padding-left:0; 
    margin-left:0px; 
} 
.resultitem img { 
    border:dotted 1px #666; 
    padding:6px; 
} 
.resultitem img:hover { 
    border:solid 1px #F60; 
} 
.resultitem h4 { 
    font-size:12px; 
    font-weight:bold; 
    color:#249ce9; 
    margin-top:5px; 
} 
.resultitem a { 
    color:#249ce9; 
} 
.resultitem .caption { 
    color:#9c9c9c; 
    font-size:12px; 
    display:block; 
    margin-top:6px; 
    text-align:justify; 
} 
</style> 
<div class="main_warpper"> 
    <div class="resultwrapper"> 
    <?php 
while($row = mysql_fetch_array($rs)) { 
     $id=$row['id']; 
     $type=$row['type']; 
     $location=$row['location']; 
     if(file_exists("properties//". $imageloc ."//thumb.jpg")) 
     { 
      $thumb_img="properties/". $imageloc ."/thumb.jpg"; 
     } else { 

      $thumb_img="images/default.jpg"; 
     } 
     if($cnt==0 || $cnt ==4) $newResult=true; else $newResult=false; 

?> 
    <div id="parent" > 
     <div class="resultitem <?php if($newResult) echo ' resultleftitem'; ?>" id="resultitem"> <a href="viewpropdetails.php?id=<?php echo $id;?>" target="_blank"> <img id="parent" src="<?php echo $thumb_img; ?>" alt="<?php $new=strtolower($heading); echo ucwords($new); ?>" title="<?php $new=strtolower($heading); echo ucwords($new); ?>" width="100" height="100" /></a> 
     <div class="itemdetails"> 
      <h4 id="linkheading"><a href="viewpropdetails.php?id=<?php echo $id;?>" target="_blank"><?php echo $type ." @ ".$location; ?></a></h4> 
      <span class="box"><?php echo cropStr($desc,$MAX_DESC); ?></span> </div> 
     </div> 
    </div> 
    <?php 
    $cnt++; } ?> 
    </div> 
    <div class="adv_right" style="width:15%; float:right;height:300px; background-color:#999999;">23123 </div> 
</div> 
1

加浮动:这里留下了

 <div class="resultwrapper" style="float:left;"> 

和rempove明确:双方并添加浮动:左

 <div class="adv_right" style=" clear:both; width:15%; float:left;height:300px; 
           background-color:#999999;"> 

看到演示这里.... http://jsfiddle.net/6e4xN/1/

+0

我也尝试,但它的回报同样的问题。 – nagaking 2013-04-08 06:14:49

1

当你要使用此代码也不会超过7-8元的工作,当你有更多的元素,然后在下面的样式表来变通。

<style> 
.resultwrapper { 
    margin: 10px auto 10px auto; 
    width:80%; 
    float:left; 
} 
.resultitem { 
    float: left; 
    height: 170px; 
    margin-bottom: 0px; 
    margin-left: 10px; 
    min-height: 130px; 
    width:150px; 
} 
.resultleftitem { 
    padding-left:0; 
    margin-left:0px; 
} 
.resultitem img { 
    border:dotted 1px #666; 
    padding:6px; 
} 
.resultitem img:hover { 
    border:solid 1px #F60; 
} 
.resultitem h4 { 
    font-size:12px; 
    font-weight:bold; 
    color:#249ce9; 
    margin-top:5px; 
} 
.resultitem a { 
    color:#249ce9; 
} 
.resultitem .caption { 
    color:#9c9c9c; 
    font-size:12px; 
    display:block; 
    margin-top:6px; 
    text-align:justify; 
} 
</style> 

让我知道它是否适用于您。

1

我想有一个代码中的一些问题。您不能在页面中为多个元素使用相同的ID。其次,当您使用百分比宽度为adv_right DIV,你为什么不使用相同的同时与resultwrapper & adv_right的div resultwrapper格向左浮动,并没有明确的:无论是在CSS。我觉得这应该可以解决你的问题。