我正在尝试创建多色背景。
我希望整个背景都是蓝色的,在某些容器中有红色的部分。我希望红色从一边走到另一边,没有任何可能被浏览器呈现的空白。以下是我所拥有的:
HTML:
<div class="Blue">
Here is one color
</div>
<div class="Red">
Here is one color
</div>
<div class="Blue">
Here is one color
</div>
<div class="Red">
Here is one color
</div>
CSS:
.Blue {
width:100%; /* I want the width of the background to be 100% of the page ?*/
height: 30%; /* I want the height of the background container to be 30% of the page? */
background-color: blue;
}
.Red {
width:100%;
height: 30%; /*The next 30% of the page ? */
background-color: red;
}
http://jsfiddle.net/4DXDX/的边缘是偏移与白色的边缘在侧面。
我怎样才能让颜色从边缘一直到边缘呢?在div标签中放置适当的颜色是正确/或有效的方法吗?
下面是我想要创建的背景图片。
发布于 2014-03-06 08:42:15
将此添加到CSS规则中:
* {
margin: 0px;
padding: 0px;
}
这样就可以去掉保证金了。http://jsfiddle.net/TZRhn/
此外,请查看this question以获得更多详细信息。
在评论中,Kheema提到通用选择器可能是个坏主意。您可以使用reset.css
代替。
查看更多关于reset.css
here的讨论
发布于 2014-03-06 08:45:30
您必须从页面中删除margin
和padding
。最简单的方法是使用这种方式去除填充和边距。
html, body{margin:0; padding:0}
注意:使用reset.css
文件来避免这种奇怪的问题是一个很好的实践。
发布于 2014-03-06 08:54:16
确实如此
* {
margin: 0px;
padding: 0px;
}
如果您不希望div的内容接触到边缘,那么现在就必须在div中添加填充。
https://stackoverflow.com/questions/22230552
复制相似问题