首页 > 怎么消除css中的绝对定位重叠问题

怎么消除css中的绝对定位重叠问题

<div class="navBar">

<div class="comWidth">
  <div class="shopClass fl">
    <h3>全部商品分类<i></i></h3>
    <div class="shopClass_show">
      <dl class="shopClass_item">
        <dt><a href="#" class="b">手机</a> <a href="#" class="b">数码</a> <a href="#" class="aLink">合约机</a></dt>
          <dd><a href="#">荣耀3X</a> <a href="#">单反</a> <a href="#">智能设备</a></dd>
      </dl>
    </div>
    <div class="shopClass_show">
      <dl class="shopClass_item">
        <dt><a href="#" class="b">手机</a> <a href="#" class="b">数码</a> <a href="#" class="aLink">合约机</a></dt>
          <dd><a href="#">荣耀3X</a> <a href="#">单反</a> <a href="#">智能设备</a></dd>
      </dl>
    </div>
    <div class="shopClass_show">
      <dl class="shopClass_item">
        <dt><a href="#" class="b">手机</a> <a href="#" class="b">数码</a> <a href="#" class="aLink">合约机</a></dt>
          <dd><a href="#">荣耀3X</a> <a href="#">单反</a> <a href="#">智能设备</a></dd>
      </dl>
    </div>
    <div class="shopClass_show">
      <dl class="shopClass_item">
        <dt><a href="#" class="b">手机</a> <a href="#" class="b">数码</a> <a href="#" class="aLink">合约机</a></dt>
          <dd><a href="#">荣耀3X</a> <a href="#">单反</a> <a href="#">智能设备</a></dd>
      </dl>
    </div>
    <div class="shopClass_show">
      <dl class="shopClass_item">
        <dt><a href="#" class="b">手机</a> <a href="#" class="b">数码</a> <a href="#" class="aLink">合约机</a></dt>
          <dd><a href="#">荣耀3X</a> <a href="#">单反</a> <a href="#">智能设备</a></dd>
      </dl>
    </div>
    <div class="shopClass_list">
    </div>
  </div>
  <ul class="nav fl">
    <li><a href="#" class="active">数码城</a></li>
    <li><a href="#">天黑黑</a></li>
    <li><a href="#">团购</a></li>
    <li><a href="#">发现</a></li>
    <li><a href="#">二手特卖</a></li>
    <li><a href="#">名品会</a></li>
  </ul>
</div>

</div>
/导航/
.navBar
{

height:35px;
background-color:#1369c0;
color:#FFF;

}
.shopClass
{

width:190px;
position:relative;

}
.shopClass h3
{

text-align:center;
line-height:35px;

}
.shopclass i
{

width:11px;
height:7px;
overflow:hidden;
background:url(../1.%E9%A6%96%E9%A1%B5-assets/%E4%B8%89%E8%A7%92%E7%AE%AD%E5%A4%B4.png) no-repeat left center;
display:inline-block;
margin-left:11px;

}
.nav,.shopClass
{

font-family:"微软雅黑";

}
.nav
{

line-height:35px;

}
.nav li
{

float:left;

}
.nav a
{

height:35px;
display:inline-block;
padding:0 35px;
color:#FFF;

}
.nav .active
{

background-color:#4593fd;

}
/商品弹出列表/
.shopClass_show
{

background-color:#4593fd;
position:absolute;
left:0;
top:35px;
width:100%;
 

}
.shopClass_item
{

padding:14px 10px;
border-bottom:1px solid #3487f2;
border-top:1px solid #5aa1fe;
 

}
.shopClass_item dt
{

height:22px;
background:url(../1.%E9%A6%96%E9%A1%B5-assets/%E7%AE%AD%E5%A4%B4.png) no-repeat right center;

}
.shopClass_item .b
{

font-family:"微软雅黑";
font-size:14px;
font-weight:bold;

}
.shopClass_item a
{

color:#FFF;

}
.shopClass_item .aLink
{

width:48px;
height:20px;
background:url(../1.%E9%A6%96%E9%A1%B5-assets/%E5%9C%86%E5%9C%88.png) no-repeat left center;
display:inline-block;
text-align:center;
line-height:20px;
text-decoration:underline;

}
为什么我的shopClass_show绝对定位之后几个div都重叠在了一起?抓狂。。。。。。。


因为你是绝对定位~所以脱离了文档流,而你给所有的div套的都是shopClass_show的这个类,

.shopClass_show
{
background-color:#4593fd;
position:absolute;
left:0;
top:35px;
width:100%;
}

所以所有的div应用了这个类,自然会全部重叠在一起了.
一般nav不会用绝对定位吧~都是限定在某一行然后float,给他一个最小宽度,让他不会小于某个宽度换行之类的~这是我的个人看法~~不对请指正。


绝对定位不应该用在单个商品(shopClass_show)上,而应该用在商品列表(shopClass)上。

【热门文章】
【热门文章】