使用填充停止比父div更高的无序列表

时间:2014-04-10 14:50:36

标签: css

我有一个与页面一样高的无序列表。我不希望它与div的两侧齐平,所以我添加了填充。除了现在它溢出。如何使列表与其父级减去填充一样高?

HTML

<div class="wrapper">
    <div class="menu"></div>
    <div class="content">
        <ul class="list">
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
        </ul>
    </div>
</div>

CSS

/* Clear any defaults on the ul */
ul {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
}

/* Make a container that fills the entire screen */
.wrapper {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    overflow: auto;
    background: hotpink;
}

/* Left hand 200px wide menu */
.menu {
    position: fixed;
    left: 0;
    bottom: 0;
    top: 0;
    width: 200px;
    background: blanchedalmond;
}

/* Fill the remaining width of the screen. */
.content {
    margin: 0 0 0 200px;
    height: 100%;
    overflow: auto;
    padding: 10px;
    background: mistyrose;
}

/* 200px wide that shouldn't be taller than it's container */
.list {
    width: 200px;
    border: 1px solid orchid;
    box-sizing: border-box;
    list-style: none;
    height: 100%;
}

http://jsfiddle.net/8A2un/

1 个答案:

答案 0 :(得分:2)

box-sizing: border-box添加到.content

http://jsfiddle.net/8A2un/1/