【问题标题】:Margin browser default setting pervents me to use full screen width & height边距浏览器默认设置使我无法使用全屏宽度和高度
【发布时间】:2014-09-26 01:06:07
【问题描述】:

我的网站宽度和高度没有完全使用,因为浏览器默认边距,有些部分被空白。

.header{
     background: #493131;
     width: 100%;
     height: 10%;
}

HTML 代码包含在正文中:

<body>
       <div class="header"> </div>
</body>

代码在我看来很好,但结果是这样的:

http://i57.tinypic.com/282j1hs.png

如何将浏览器默认边距设置为我自己的设置?

【问题讨论】:

  • 我不明白你们为什么对我的说唱评分..

标签: html css margin


【解决方案1】:

只需在body 标签上设置margin: 0;

body { margin: 0; }

【讨论】:

  • 这是margin 而不是padding
  • @ExCluSiv3 在这种情况下,你能链接到你的页面吗?
  • @ExCluSiv3 jsfiddle.net/83ehq5ok - 只需 margin: 0; 在正文加上您的代码即可正常工作。说“复制代码并在本地运行”对我们没有好处。向我们展示您的页面
  • 啊,好吧,你在前 10 秒左右看到了我的帖子,然后我才意识到我会把填充而不是边距 :) 很高兴你让它工作了
  • @ExCluSiv3 最初只是一个建议,consider reseting the default stylesheet 作为起点。
【解决方案2】:

您应该重置您的浏览器默认样式。这是标准重置,如

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

【讨论】:

  • 最好说should 而不是have to
  • 好吧,我编辑了我的答案,这是错误的,因为我的英语很差。
【解决方案3】:
*{ margin:0 auto; padding:0px;}

它将删除所有默认边距和填充

【讨论】:

  • 这将从p标签和东西中删除边距。这就像用大锤敲打你的窗户,因为它需要向框架中移动 2 毫米深。
猜你喜欢
  • 1970-01-01
  • 2011-10-15
  • 1970-01-01
  • 2012-02-26
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 2013-03-02
  • 1970-01-01
相关资源
最近更新 更多