无法获取div背景颜色来填充视口的全宽 [英] Can't get a div background colour to fill full width of viewport

查看:100
本文介绍了无法获取div背景颜色来填充视口的全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用背景颜色填充页面的某一部分。我想要的背景颜色填充视口的整个宽度,但有一个固定的高度。这是我尝试过的:

 < div id =theDivstyle =width:100%; height:200px ; background-color:black;> 
Blah blah blah,内容来到这里。
< / div>

但是无论我怎么做,这总是给我一个小白边,在div的边缘和视口的边界之间。如何使div填充视口的整个宽度?



我不想更改< c $ c>< body> 标签,因为我只需要填充屏幕的某个垂直部分。



想想我还没有尝试过是创建一个1px宽的bg图像并将其设置为x重复...是没有比这更优雅的解决方案?

body 和 html 的宽度设置为100%,然后选择 paddings和margin为0。



此外,您可能希望将CSS重置规则应用于样式表的开头。您可以使用此CSS重置 http://meyerweb.com/eric/tools/css/reset/ 或google的另一个。


I'm trying to fill a certain part of the page with a background color. I want the background colour to fill the entire width of the viewport, but have a fixed height. Here's what I've tried:

<div id="theDiv" style="width: 100%; height:200px; background-color:black;">
    Blah blah blah, content goes here.
</div>

But no matter what I try, this always give me a small white margin at either side of the div, between the edge of the div and the boundaries of the viewport. How can I make the div fill the entire width of the viewport?

I don't want to change the bg color of the <body> tag as I only need to fill a certain vertical section of the screen.

The only thing I can think of that I haven't tried yet is to create a 1px wide bg image and set it to x-repeat... is there not a more elegant solution than this?

解决方案

Try to set width of body and html to 100% and paddings and margins to 0.

Also you may want to apply CSS reset rules to the beginning of your style sheet. You can use this CSS reset http://meyerweb.com/eric/tools/css/reset/ or google for another one.

这篇关于无法获取div背景颜色来填充视口的全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆