html - CSS li 列表,左边距

标签 html css margin

我不明白为什么我的左边有边距:

example

CSS:

html, body {
    font-family:Myriad Pro, sans-serif;
    font-size:18px;
    color:#000;
    margin:0px;
    padding:0px;
    background: url('./images/background.png');
}

#container {
    width:890px;
    height:530px;
    margin:36px auto;
}

#userList {
    width:228px;
    height:355px;
    float:right;
    border:1px solid #cccccc;
}

.users li {
    list-style-type:none;
    background-color: #f2f2f2;
    width:100%;
    height:50px;
    border-bottom: 1px solid #cccccc;
}

HTML:

<div id="userList"><ul class="users"><li><img src="./pic/none.png">Piet van Meerdijk</li><li><img src="./pic/none.png">Henk v/d Wal</li></ul></div>

当我放置 margin-left:-40px;在 CSS 代码中,li 项现在位于左侧,但右侧有一个边距。为什么?

JSfiddle:http://jsfiddle.net/8Cwcy/

最佳答案

<ul>标签有一个自动 padding40px所以您需要将其更改为 0px:

ul {
    padding: 0px;
}

这应该适用于所有浏览器。

fiddle :http://jsfiddle.net/8Cwcy/3/

关于html - CSS li 列表,左边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21648296/

相关文章:

javascript - 在基于 polymer 的游戏中 : how to display an image depending on the total score

html - 强制元素与兄弟元素的高度相同?

css - 从 html 中的交互式表格更新绘图

JQuery 可拖动 DIV 以负边距居中...问题

android - View 的填充和边距之间的区别

html - 更改 HTML 导出到 Word 的边距

css - 两个内联 block (右侧固定)

javascript - 打开对话框后如何返回主视图?

html - 在 div 容器中将文本居中覆盖在图像上

jquery - 将 "nephew"draggable 拖动到 "aunt"droppable,同时保持 CSS 和尺寸