Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 背景不起作用_Html_Css - Fatal编程技术网

Html 背景不起作用

Html 背景不起作用,html,css,Html,Css,我有一个特殊的css代码。但它并没有像预期的那样发挥作用。我想把整个内容都写在包装纸上。但它不起作用。我只是得到一个div上面和下面我的内容显示。实际上,我所有的内容都应该显示在我的白色包装中 <div id ="Wrapper1"> <div class ="whitewrapper"> <div class ="content"> <div class =

我有一个特殊的css代码。但它并没有像预期的那样发挥作用。我想把整个内容都写在包装纸上。但它不起作用。我只是得到一个div上面和下面我的内容显示。实际上,我所有的内容都应该显示在我的白色包装中

<div id ="Wrapper1">
        <div class ="whitewrapper">
                <div class ="content">
                        <div class ="subleft">
                                loremipsum
                        </div>
                        <div class ="subright">
                                loremipsum
                        </div>
                </div>  
        </div>
</div>

错误是什么?

.white\u wrapper
应该是
.whitewrapper

.content {
overflow: auto;
}

你应该在谷歌上搜索一下“css清除浮动”来理解这是因为你在内容分区内浮动所有内容。浮动内容不会占用父内容的任何空间(垂直),因为它基本上是从内容中删除的。最好的解决方案是在两个浮动元素之间添加内容,或者在内容分区上设置一个高度(不可靠)

或者,有一个CSS黑客,但你必须担心浏览器的兼容性:

.whitewrapper:after {
     content: " ";
     display: block;
     clear: both;  
}


设置元素样式的更好方法是使内容容器显示为表,其子元素显示为表单元格,假设布局中只有这两列:

.subleft {
    display: table-cell;
    max-width: 400px;
    width: 400px;
}
.subright {
    display: table-cell;
    max-width: 300px;
    width: 300px;
}
.content{
    display: table;
    width:880px;
    max-width:880px;
}

.white_wrapper{background:#000;}
-一个典型的例子,说明了为什么应该避免使用表示类名称。我尝试了所有颜色组合。即使使用以下代码[code].white_wrapper{background:none repeat scroll 0#fff;margin:10px;padding:10px;}[/code],但它不起作用。这是投票被否决的原因吗?你被否决是因为不清楚你的问题是什么。编辑打字错误。但这不能解决我的问题。你可以自己测试。实际上,白色包装应该覆盖左右div中的整个文本。但它并没有这样做。你是说?@Madmartigan:我希望我的内容应该显示在白色包装内。但它并没有显示增加高度和移除浮子对我有效:@Jivings:我无法添加固定高度。高度需要根据内容长度自动调整。我也试过了。它没有按预期工作。看我对Jivingst的评论这是对他狡猾的css的攻击。一个更好的答案难道不能教他如何正确地设置样式吗?@animuson:我如何将内容左右对齐而不是usinf float?有比浮动更好的方法吗?@user632347:查看我的更新,它使用表格显示而不是浮动。@animuson:谢谢你教我一个新信息。如果我在content div中有sub-left和sub-right怎么办?@user632347:我不明白你的意思;这不是你已经有的吗?
.subleft {
    display: table-cell;
    max-width: 400px;
    width: 400px;
}
.subright {
    display: table-cell;
    max-width: 300px;
    width: 300px;
}
.content{
    display: table;
    width:880px;
    max-width:880px;
}