html - 为什么无序列表项顶部有一个空格?

标签 html css firefox html-lists

问题:无序列表项顶部有一个空格。这个空格出现在 Firefox 18.0.1

HTML:

<ul>
<li>
    <a href="">
        <h3>Lorem ipsum</h3>
        <p>It is a long established fact that a reader will be distracted by the readable content</p>
    </a>
</li>
<li>
    <a href="">
        <h3>Lorem ipsum</h3>
        <p>It is a long established fact that a reader will be distracted by the readable content</p>
    </a>
</li>
<li>
    <a href="">
        <h3>Lorem ipsum</h3>
        <p>It is a long established fact that a reader will be distracted by the readable content</p>
    </a>
</li>

CSS:

ul {
    list-style: square;
    margin-left: 20px
}

工作演示: http://jsfiddle.net/vpdd7/

最佳答案

这似乎是列表样式与 block 元素前面/包含 block 元素(例如 h3p)冲突的问题。如果您

我在 CSS2.1 spec 中找不到任何内容这将确定此行为是 Firefox 中的错误,还是其他浏览器中的错误。其实在list-style-position下,它表示标记框(包含元素符号)的确切位置或布局未定义,即使相对于由 li 元素本身(主框)或其任何元素创建的框也是如此 children 。

鉴于您的情况,第三个选项可能是最好的解决方法,它不会对布局造成太大影响(如果有的话)。如果您打算将列表项的全部内容变成一个链接,那么您最好将其显示为一个 block 。这样,所有内容都安全地包含在 block 盒中,其渲染定义非常明确且完全可靠。

关于html - 为什么无序列表项顶部有一个空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14535935/

相关文章:

jquery - 工具提示在相对位置移动

javascript - D3 xlink : "href" appends image fine on Google Chrome but not on Firefox

javascript - 从 Firefox 扩展访问 DOM 函数

Html Navigation bar item 只有最后一项可点击,其余不能

javascript - Bootstrap 模式在 Laravel 中不起作用

html - 内容显示滚动条但不可滚动

javascript - Internet Explorer 不遵守最大宽度或最大高度

javascript - 如何为图像创建随机大小的平铺照片库?

html - 使用 Bootstrap 从右到左的列

javascript - 使方法 "click"跨浏览器的插件