4

我想要一个父类(ul标签)来保存一堆li相互重叠的标签,这是我的代码:

<ul class="overlap">
    <li>
        Overlap One
    </li>
    <li>
        Overlap Two
    </li>
    <li>
        Overlap Three
    </li>
</ul>

我不希望它们被绝对定位,因为我有一个具有背景边框和颜色的父元素,但是当我绝对定位子元素时,父元素不会拉伸,这是完整的代码。

<blockquote>
 <ul class="overlap">
    <li>
        Overlap One
    </li>
    <li>
        Overlap Two
    </li>
    <li>
        Overlap Three
    </li>
</ul>
</blockquote>

标签上有背景颜色,这blockquote就是为什么孩子不能绝对定位的原因。

在此先感谢您的帮助!

4

2 回答 2

5

像这样?http://jsfiddle.net/2N8Jz/

<blockquote class="clearfix">
  <ul class="overlap">
    <li>Overlap One</li>
    <li>Overlap Two</li>
    <li>Overlap Three</li>
  </ul>
</blockquote>
​

blockquote {
    border: 1px solid black;    
    padding: 10px;
}

.overlap {
    padding-left: 10px;
}

.overlap li {
    border: 1px solid grey;
    float: left;
    margin: 0 0 0 -10px;
}

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

.clearfix {
    display: inline-block;
}

html[xmlns] .clearfix {
    display: block;
}

* html .clearfix {
    height: 1%;
}
​
于 2012-05-17T20:24:03.263 回答
1

给出<li>'a 负数margin应该可以解决问题。

这是一个例子:http: //jsfiddle.net/wvEms/1/

于 2012-05-17T20:28:37.163 回答