<分区>
标签 html css containers
<分区>
Possible Duplicate:
Convert HTML + CSS to PDF with PHP?
我似乎无法找到正确完成此任务的方法。我有两个容器。在一个容器中,我想使用背景图像水平占据整个上半部分,然后我想使用第二个容器并将其着色为红色。这将水平接管下半部分。
我试过这个:
HTML:
<div class="container1">
Some text and other divs go here. This is where the background will be an image.
</div>
<div class="container2">
Some text will also here along with divs. This is where I want to use the red background.
</div>
CSS:
.container1 {
background-image: url('img.png');
width:100%;
}
.container2 {
width: 100%;
color: #990000;
}
问题是对于图像容器,我在顶部留下了空白, 底部、左侧和右侧。
我该如何解决?
最佳答案
您需要将填充和边距设置为 0。大多数有经验的 UI 开发人员将使用所谓的 CSS 重置来消除任何特定于浏览器的默认样式表行为(例如提供填充)。
为了您的目的,一个基本的 CSS 重置:
body { padding: 0px; margin: 0px;}
div { padding: 0px; margin: 0px; }
在你的 CSS 文件的开头,应该会有帮助。
此外,CSS color
与文本颜色相关,与背景颜色无关。您需要使用 background-color
。
关于html - 如何创建两个具有不同背景的容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13504319/