如何使用float来定位列?

时间:2013-02-11 03:36:10

标签: css position css-float multiple-columns

如何使用浮动来定位照片下方的联系人信息栏。我大部分时间都在漂浮,但是我想知道如何将最后的联系信息与图片粘在一起。

enter image description here

这是我希望它向前迈进的地方,我无法这样做。 这是当前的设置:

<div id='post'><div id='vpPhotos'>
  <img src='Images/img.jpg'/><img src='Images/default.png'/><img src='Images/default.png'/><img src='Images/default.png'/></br><a id='posttitle' href='#?photoID=$photoID'>View More Pictures</a>
  </div>
    <div id='vpTitle'>
            <h3>$eventTlt</h3>
        </div>
    <div id='vpprice'><b>Price: </b>$priceOfEvent</div>
  <div id='vpdate'>
  </br><b>Start Date:</b>  <div class='float-right'>$eventSD </div>
  </br><b>End Date:</b>  <div class='float-right'>$eventED</div>
  </br><b>Start Time:</b> <div class='float-right'> $eventTime </div>  
  <br/><b>Location Of Event:</b> <div class='float-right'>$location</div>
  <br/><b>Address Of Location:</b> <div class='float-right'>$locationAddress</div></div>
  <div id='eventdesc'>
  </br></br><b>Description:</b> &nbsp&nbsp$eventDesc </div>
<div id='vpcontact'>
  </br><h3 align='left'><b>Contact Information</b></h3> &nbsp&nbsp
  </br><b>Name:</b> &nbsp&nbsp$contactName
  </br></br><b>Email:</b> $emailAddress</div>


<div style='clear:both;'/>
</div>

我全都漂浮了。在我的所有其他div都向左浮动之后我不确定。 #post是最外层的,其余的基本上可由名称描述。

#post{
border:3px inset red;
margin-right:20px;
}
#vpPhotos{
border:3px outset blue;
float:left;
width:25%;
}
#vpTitle{
float:left;
border:3px inset green;
}
#vpdate{
float:left;
width: 20%;
border:3px inset blue;
margin-right:100px;
padding-right:300px;
}
#eventdesc{
float:left;
width: 73.74%;
border:3px inset green;
}
#vpcontact{
float:left;
width: 24%;
border:3px inset red;
}
#vpprice{
float:right;
width: 15%;
border:3px inset black;
}

1 个答案:

答案 0 :(得分:0)

为了做到这一点,你需要将照片和联系div放在一个单独的div中,浮动它并将所有其他div放在另一个也是浮动的div中。

Working example on JS Bin

更新的代码:

HTML:

  <div id='post'>
    <div id='column-one'>
      <div id='vpPhotos'>
        <img src='Images/img.jpg'/><img src='Images/default.png'/><img src='Images/default.png'/><img src='Images/default.png'/></br><a id='posttitle' href='#?photoID=$photoID'>View More Pictures</a>
        </div>
        <div id='vpcontact'>
         <h3 align='left'><b>Contact Information</b></h3> &nbsp&nbsp
          </br><b>Name:</b> &nbsp&nbsp$contactName
          </br></br><b>Email:</b> $emailAddress
        </div>
      </div>

       <div id="column-two">
  <div id='vpTitle'>
              <h3>$eventTlt</h3>
          </div>
      <div id='vpprice'><b>Price: </b>$priceOfEvent</div>
    <div id='vpdate'>
    </br><b>Start Date:</b>  <div class='float-right'>$eventSD </div>
    </br><b>End Date:</b>  <div class='float-right'>$eventED</div>
    </br><b>Start Time:</b> <div class='float-right'> $eventTime </div>  
    <br/><b>Location Of Event:</b> <div class='float-right'>$location</div>
    <br/><b>Address Of Location:</b> <div class='float-right'>$locationAddress</div></div>
    <div id='eventdesc'>
    </br></br><b>Description:</b> &nbsp&nbsp$eventDesc </div>
</div>

<div style='clear:both;'/>
</div>

CSS:

#post {
    border: 3px inset red;
    margin-right: 20px;
}

#column-one,
#column-two {
    float: left;
    width: 24%;
}

#column-two {
    width: 76%;
}

#vpPhotos {
    border: 3px outset blue;
  width: 98%;
  float: left;
}

#vpTitle {
    float: left;
    width: 80%;
    border: 3px inset green;
}

#vpdate {
    width: 99%;
    float: left;
    border: 3px inset blue;
}

#eventdesc {
    float: left;
    width: 99%;
    border: 3px inset green;
}

#vpcontact {
    float: left;
  width: 98%;
    border: 3px inset red;
}

#vpprice {
    float: right;
    width: 15%;
    border: 3px inset black;
}