无序列表中的子弹未包含在块中?

问题描述 投票:5回答:2

我的子弹在无序列表中超出了其阻止元素范围,出现了问题。这是正常现象,还是子弹不被视为文档流的一部分?

在此小提琴中,我的无序列表显示为padding-left:0,您可以看到子弹正从其容器中推出。 http://jsfiddle.net/E4WWu/1/

我必须给无序列表一些填充以“修复”问题,如此处所示:http://jsfiddle.net/E4WWu/

我的问题是:为什么<ul>元素中不包含项目符号?是我的页面特定内容还是HTML / CSS中缺少的内容?

提前感谢。

HTML

<div class="center-midright-container">
    <div class="infoBox"><span class="filler">Content Goes Here ...</span></div>
    <div class="innerBottom">
        <h3 class="instructHeader">Instructions<br/></h3>
        <ul class="instructText">
            <li>This is a list of instructions and this sentence is meant to be an item of the list. Each item can wrap around to the next line if it is long enough.</li>
            <li>This is a list of instructions and this sentence is meant to be an item of the list. Each item can wrap around to the next line if it is long enough.</li>
            <li>This is a list of instructions and this sentence is meant to be an item of the list. Each item can wrap around to the next line if it is long enough.</li>
        </ul>
    </div>
</div>

CSS

h3 {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
h3 {
    color:#fff;
}
ul {
    list-style-image:url('http://oi43.tinypic.com/wb8nz9.jpg');
    padding-left:10px
}
h3.instructHeader {
    text-decoration:underline;
    text-align:center;
}
.center-midright-container {
    margin:0 auto;
    width: 700px;
}
.innerBottom {
    width:80%;
    border: 3px #b51700 ridge;
    background-color:#000;
    padding:10px;
    margin:0 auto;
    margin-top:25px;
}
.instructText {
    text-align:left;
    line-height:1.5;
    color:#fff;
}
/* This is actually filled with content in my page.  Here now just for a filler */
.infoBox {
    height:500px;
    background-color:#000;
    text-align:center;
    position:relative;
}
.filler {
    position:relative;
    top:47%;
    color:#fff;
}
html css html-lists
2个回答
9
投票

在评论中回答问题。感谢@Chad和@Mr Lister的帮助。

我没有注意到<ul>元素的默认属性,因为默认情况下项目符号位于块的外侧,而项目的填充位于项目的外。当我考虑它时,这是有道理的,因为这将使每个项目符号的文本精确地对齐。

添加list-style-position: inside;可以通过将其放置在元素内而不是填充中来修复它。

谢谢!


0
投票

list-style-position: inside使li文本自动包含项目符号,而这通常不是您想要的。

我相信,确保ul左侧有足够的边距/填充以包含项目符号是最佳解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.