使div占据Y轴上的剩余空间

时间:2011-08-03 01:05:33

标签: css

我有一个如下所示的产品模板: enter image description here

它的html是:

                <div id="product">

            <div id="cont">
            <div class="productPictures">
                          <a 
               href="images/spalt_images/body_images/525a.JPG"
               target="_blank"
              >
              <img src="images/spalt_images/body_images/525a.JPG" 
              width="180"
              height="139.52153110048"
               alt="front image" class="productImage"/> 
               </a>
                          <a 
               href="images/spalt_images/body_images/525a.JPG"
               target="_blank"
              >
              <img src="images/spalt_images/body_images/525a.JPG" 
              width="180"
              height="139.52153110048"
               alt="front image" class="productImage"/> 
               </a>

                        </div>
            <div class="productNumber"> #123            </div>
            <div class="productDesc">
            <table>
    <col id="col1" />
    <col id="col2" />
    <tbody>
            <tr>

            <td> Body Type: </td>
            <td> Stratocaster            </td>
        </tr>
                <tr>
            <td> Body Wood Type: </td>
            <td> Walnut            </td>

        </tr>
                <tr>
            <td> Weight: </td>
            <td> 12.7 lbs            </td>
        </tr>
                <tr>
            <td> Thickness: </td>

            <td> 1 inch            </td>
        </tr>
                <tr>
            <td> Routing: </td>
            <td> Standard            </td>
        </tr>


    </tbody>
</table>
                &nbsp;<div class="productPrice">
                $456.00
                </div>
</div>
            </div>
</div>

        </div>
      </div>   

和css:

#product {
    background-position: left top;
    border: 2px solid #2D0000;
    background-color: #42533E;
    width: 650px;
    overflow: hidden;
    margin-top: 10px;
    margin-bottom: 10px;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px;
    border-radius: 4px 4px 4px 4px

}
.productNumber {
    padding: 4px;
    font-size: 35px;
    color: #C9E0D0;
    float: right;
    text-shadow: 2px 2px 3px #252525;
}
.productPictures
{
    float: left;
    padding: 0px;
    margin: 5px 0px 10px 0px;
    width: 200px;
}
.productDesc{
    padding: 5px 10px 5px 5px;
    color: #FFFFFF;
    font-size: large;
    float: left;
    width: 400px;
    height: 100%;
}
.productPrice {
    font-size: 25px;
    color: #F4D582;
    text-align: right;
    font-weight: bold;
    text-shadow: 2px 2px 3px #252525;
}
.productImage {
    border: 2px solid #20281E;
    margin-top: 10px;
    margin-right: 10px;
    margin-left: 10px;
}

#col1{
    width: 40%;
}
#col2{
    width: 60%;
}
table{
    width: 100%;
}

所以我想要的是产品描述div最终在底部,以便价格也最终在底部。我试图将高度设置为100%,但这没有任何效果。

谢谢

3 个答案:

答案 0 :(得分:1)

这是一个working example

相关代码:

#product {
    ...
    position:relative;
}

.productDesc{
    ...
    position:absolute;
    bottom:0px;
    right:0px;
}

答案 1 :(得分:0)

首先,您需要在ID为float:left的div上设置cont

您在该容器内部的元素向左浮动,但该容器不是,因此其高度不会扩展到其内容。

然后,您可以将productDesc div设置为position:absolutebottom:0px

当然,这会弄乱它对照片的相对定位,但是如果你想将它固定在父容器的底部,这是唯一的方法。然后,您可以设置right:100px,或者根据需要将其设置为水平放置。

修改

以下是一个有效的例子:http://jsfiddle.net/citizenconn/hXSmK/

答案 2 :(得分:0)

  • .productDesc .productPictures
  • 清除浮动广告
  • 对这2个DIV使用 display:inline-block
  • 并减少 .productDesc 的宽度。比如说,让它成为350px

这样可行。