如何删除html顶部,左上角和右侧中不需要的空格



我想知道为什么在HTML中,当我制作整个页面的表格时,我得到了一个不需要的空间。如何删除该空间?我尝试了cellpadding="0"border="0"

地址栏和页面之间的间距

    <html>
    <head>
    <title>Lord Machine Admin</title>
    </head>
    <body>
    <table width="100%" height="100%" bgcolor="Blue" border="1" cellpadding="0">
        <tr>
            <td>
            </td>
        </tr>
    </table>
    </body>
    </html>

body 元素具有默认边距。 只需将身体margin设置为0,即可设置好一切。

"CSS重置"是矫枉过正,不应该要求。

body{
  margin:0;
}
<html>
  <head>
    <title>Lord Machine Admin</title>
  </head>
  <body>
    <table width="100%" height="100%" bgcolor="Blue" border="1" cellpadding="0">
      <tr height="100px">
        <td>
        </td>
      </tr>
    </table>
  </body>
</html>

在大多数浏览器中,<body> 元素会获得默认的 CSS 边距(在 Chrome 中,它是 8 像素)。

您可以使用 CSS 删除此默认样式:

<html>
<head>
<title>Lord Machine Admin</title>
<style>
    body {
        margin: 0;
    }
</style>
</head>
<body>
<table width="100%" height="100%" bgcolor="Blue" border="1" cellpadding="0">
    <tr>
        <td>
        </td>
    </tr>
</table>
</body>
</html>

正如其他答案所提到的,有各种各样的CSS重置样式组试图以合理的方式反转默认浏览器样式,为您提供一张白纸。

但是,这可能比您在这种情况下需要的 CSS 更多,或者您最终可能会重新设置您实际想要保留的默认浏览器样式。

将"CSS Reset"与 CSS 通用选择器一起使用,并删除任何默认空格,这些空格可能是浏览器特定的呈现空格或来自其他样式表:

* {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
}

"CSS Reset"的好地方是在你的主网站样式表的顶部,你的主样式表应该在任何外部样式表(如引导)之后.css

这是一个

CSS 重置。您可以使用它来重置所有默认的预应用边距填充等。/* http://meyerweb.com/eric/tools/css/reset/ 2.0 版 |20110126 许可证:无(公共领域) */

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;
}

最新更新