我只有这段代码(没有CSS或更多的HTML)。
当我在浏览器中加载html文件时,在我看来,顶部有一个21 my的页边距(如果您不理解我的意思,请参阅图像链接)。
我知道body元素在默认情况下通常有一个8px边距,所以我通过开发人员工具添加了这段代码,从而删除了这个边距。margin: 0px;
即使在添加了这些代码之后,我仍然可以在页面的顶部得到21 of的页边距。
我不知道该怎么做,所以如果你能帮我,那就太好了。
body {
margin: 0px;
}<body>
<div id="unit-type">
<h1>Converter</h1>
</div>
</body>
发布于 2022-08-29 19:35:47
考虑检查元素,以确定哪些元素应用了默认边距或填充,并将*替换为类、id或元素。
使用*重置所有元素的默认填充和边距(传统上不是最佳实践)
*{
margin: 0;
padding: 0;
}发布于 2022-08-29 20:39:13
您可以创建一个文件来重置页面的CSS并将其导入到HTML中;reset.css的一个示例是:
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,浏览器放置的所有默认格式都将被删除。
发布于 2022-08-29 20:39:48
* {
margin: 0px;
padding:0px;
}<body>
<div id="unit-type">
<h1>Converter</h1>
</div>
</body>
https://stackoverflow.com/questions/73533807
复制相似问题