将容器绝对定位在其他容器内

时间:2014-07-16 21:10:05

标签: html css position containers

我想定位这个"描述"这些其他容器内的容器。我的问题是,由于它的绝对定位,它溢出我的主要容器。

以下是最新动态的截图。

Screenshot

HTML

<div id="inventorycont">
 <div class="Content">
  <div class="cattitle">Trucks</div>

  <div id="container3">
    <a href="/Trucks/70017/70017.html"><img class="itemthumb" src="/Trucks/70017/70017.JPG" alt=""></a>
    <div class="Itemtitle">
    <div class="main"> GMC Dump Truck </div>
    <br>
    <b>Stock #:</b> 70017
    <br>
    <b>Price:</b> Call
    <br><br>
    <a href="/Trucks/70017/70017.html"><b>Full Details</b></a> 
    </div>
    <div id="container4">
    <div class="Itemdesc">
    <b>Description:</b><br>1989 GMC Dump Truck, Model 7000 Top Kick, 3280T Cat Diesel, 10spd. Roadranger, Tag Axle, 20' Lined Box, Hydraulic Winch, 46000# GVWR, Only 68427 Miles
    </div>
    </div>
  </div>

  <div id="container3">
    <a href="/Trucks/12017/12017.html"><img class="itemthumb" src="/Trucks/12017/12017.jpg" alt=""></a>
    <div class="Itemtitle">
    <div class="main"> Peterbilt Truck Tractor </div>
    <br>
    <b>Stock #:</b> 12017
    <br>
    <b>Price:</b> Call
    <br><br>
    <a href="/Trucks/12017/12017.html"><b>Full Details</b></a> 
    </div>
    <div id="container4">
    <div class="Itemdesc">
    <b>Description:</b><br>Truck Tractor, NTC 350 Cummins, 13 spd. Roadranger, Like New
    </div>
    </div>
  </div>

    <div id="container3">
    <a href="/Trucks/80004/80004.html"><img class="itemthumb" src="/Trucks/80004/80004.jpg" alt=""></a>
    <div class="Itemtitle">
    <div class="main"> International Truck Tractor </div>
    <br>
    <b>Stock #:</b> 80004
    <br>
    <b>Price:</b> Call
    <br><br>
    <a href="/Trucks/80004/80004.html"><b>Full Details</b></a> 
    </div>
    <div id="container4">
    <div class="Itemdesc">
    <b>Description:</b><br>International 8100, 6 spd, DT 466 Engine
    </div>
    </div>
  </div>

 </div>
</div>

CSS

/*Inner Item Container*/
#container3 {
    position: abosolute;
    width: 750px;
    height: 150px;
    overflow: hidden;
    margin-top: 15px;
    margin-right: 0px;
    background: #ffffff;
    border: 2px solid #000000;
}

/*Outer Container*/
#inventorycont {
    width: 800px;
    height: 510px;
    overflow: hidden;
    margin-top: 5px;
    margin-right: 30px;
    background: #EEEEEE;
    border: 3px solid #000000;
}

/*Inner Item Container for description*/
#container4 {
    position: absolute;
    width: 300px;
    height: 95px;
    overflow: hidden;
    margin-top: 50px;
    margin-left: 400px;
    margin-right: 5px;
    background: #ffffff;
    border: 1px solid #000000;
    float:left;
}

1 个答案:

答案 0 :(得分:1)

您需要将position:relative添加到主容器(您希望div在哪里),因此绝对位置将相对于它。