这是我的代码:
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>
我想问为什么宽度和高度与正常(段落和分割)不同,即使我设置的宽度和高度相同?
答案 0 :(得分: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;
}
<强> Demo 强>
答案 1 :(得分: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;}
答案 2 :(得分:0)
浏览器具有默认样式。在有序/无序列表的情况下,一些浏览器添加左边距而一些添加左边距
答案 3 :(得分:0)
请尝试
ul {
-webkit-padding-start: 0px;
padding-left: 0px;
}
您可以打开开发人员工具,查看浏览器定义的用户代理样式表,并覆盖您想要的任何内容。