2

这是我的代码:

CSS

div {
    height: 200px;
    width: 600px;
    border: 1px solid black;
}
ul {
    height: 200px;
    width: 600px;
    border: 1px solid black;
}
p {
    height: 200px;
    width: 600px;
    border: 1px solid black;
}

HTML

<div></div>
<ul>
    <li></li>
    <li></li>
    <li></li>
</ul>
<p></p>

我想问即使我设置的宽度和高度相同,为什么宽度和高度与正常(段落和分区)不同?

4

4 回答 4

1

ul许多浏览器默认在标签上放置内部填充。

您需要覆盖它:

CSS

div {
    height: 200px;
    width: 600px;
    border: 1px solid black;
}
ul {
    height: 200px;
    width: 600px;
    border: 1px solid black;
    padding: 0px;
    margin: 0px;
}
p {
    height: 200px;
    width: 600px;
    border: 1px solid black;
    margin: 0px;
}​

演示

于 2012-12-07T02:22:19.800 回答
0

您可能只需要进行 CSS 重置:

/**
 * Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
 * http://cssreset.com
 */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

或者现在你可以添加到你所有的 css 中:

html, body, div, ul, li, p { margin:0; padding:0;}

于 2012-12-07T02:18:52.787 回答
0

浏览器具有默认样式。在有序/无序列表的情况下,一些浏览器添加左边距,而一些浏览器添加左边距

于 2012-12-07T02:18:54.040 回答
0

请试试

ul {
-webkit-padding-start: 0px;
padding-left: 0px;
}

您可以打开开发人员工具并查看浏览器定义的用户代理样式表并覆盖您想要的任何内容。

于 2012-12-07T02:27:58.460 回答