html - 背景无法正确定位

标签 html css

大家好,我是 html 和 css 新手 我想创建 4 个背景,一个在顶部,一个在左边,一个在底部,一个在右边......但不知何故,右边的一个没有显示,另一个工作正常 你能帮我吗?

HTML:

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

    <div class="leftheader">
    </div>

    <div class="rightheader">
    </div>

    <div class="bottomheader">
    </div>

CSS

body {
    background-color: #efefef;
    margin: 0px auto;
    font-family: arial

}


.header{
    background: #cccccc;
    background-position: top;
    background-repeat: no-repeat;
    background-attachment: fixed;
    border: 0px solid #000000;
    width: auto;
    height: 60px;
}

.leftheader {
    background: #cccccc;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: left;
    border: 0px solid #000000;
    width: 100;
    height: 590;
}

.rightheader {
    background: #cccccc;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: right 10px top 10px;
    border: 1px solid #000000;
    width: 100;
    height: 590;
}

.bottomheader {
    background: #cccccc;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: bottom;
    border: 0px solid #000000;
    width: auto;
    height: 60px;
}

最佳答案

实现此功能的关键是在 .leftheader.rightheader 上使用 float: leftfloat: right 元素。然后,您需要通过将 clear: Both 放在 .bottomheader 上来清除 float 。

body {
    background-color: #efefef;
    margin: 0px auto;
    font-family: arial
}
.header {
    background: #cccccc;
    background-position: top;
    background-repeat: no-repeat;
    background-attachment: fixed;
    border: 0px solid #000000;
    width: auto;
    height: 60px;
}
.leftheader {
    background: #cccccc;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: left;
    border: 0px solid #000000;
    width: 100px;
    height: 590px;
    float: left;
}
.rightheader {
    background: #cccccc;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: right 10px top 10px;
    border: 1px solid #000000;
    width: 100px;
    height: 590px;
    float: right;
}
.bottomheader {
    background: #cccccc;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: bottom;
    border: 0px solid #000000;
    width: auto;
    height: 60px;
    clear: both;
}
<div class="header">header</div>
<div class="leftheader">leftheader</div>
<div class="rightheader">rightheader</div>
<div class="bottomheader">bottomheader</div>

关于html - 背景无法正确定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33929560/

相关文章:

html - CSS子菜单对齐问题

html - 在 angularjs 中使用指令时在列中定位 Div

jquery - 视口(viewport)底部的菜单然后粘在顶部

php - 未选择下拉选项

html - 使一个 div 绝对化到特定的 div

javascript - 图像预览 - 将 div 更改为已单击的内容 - Polymer(无 JQuery)

css - 转换时文本模糊 :rotate in Chrome

html - 为什么边框半径只在 1 个 Angular 起作用?

css - 我如何在 React 中将组件堆叠在一起?

jquery - 导航样式问题