【问题标题】:My div images won't position. Nor place themselves 0px top and left我的 div 图像不会定位。也不将自己放置在顶部和左侧 0px
【发布时间】:2014-06-02 10:47:20
【问题描述】:

希望对象从顶部 0px 和左侧 0px 开始,一直到右侧: http://imgur.com/A76ymUQ

我在上面展示过。 这是它的html代码和css代码:

<div id="page">
                <h1 id="header"></h1>
</div>
-------------------------------------------------------------
body {
    background-image:url(../img/b_webclient_1.png);
    background-position: center center fixed;
    background-repeat: no-repeat;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

div #header {
    background-image:url(../img/webclient_header.png);
    min-height: 100px;
    width: auto;
    margin:; /* If you want no margin */
    padding:; /*if your want to padding */
    background-repeat: no-repeat;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

【问题讨论】:

  • 大多数浏览器的默认body边距为8px...尝试在上面的正文中添加margin:0;
  • 这就是它没有帮助的问题。
  • 啊,是的,h1 标签也有边距。试试这个:body,html,h1 {margin:0;padding:0;}
  • 谢谢!它工作 henryaaron

标签: html css background-image positioning


【解决方案1】:

来源:来自万维网联盟的Default style sheet for HTML 4


&lt;body&gt; 标签的默认边距为 8 像素

通过将其添加到您的 CSS 来重置它:

body {
  margin:0;
}

&lt;h1&gt; 标签的默认边距为 0.67 em

通过将其添加到您的 CSS 来重置它:

h1 {
  margin:0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多