CSS 以 100% 宽度居中
我试图将页面的所有内容居中,以便当您调整浏览器的大小时,内容会随着调整而移动。我使用 CSS 代码:
margin: 0px auto;
width: 670px;
但是,我想要一个彩色标题覆盖 100% 的宽度,而标题中的文本则根据页面的其余部分进行调整。我如何同时做这两件事?
I'm trying to center all the content of a page so that when you adjust the size of the browser, the content moves along with the adjustment. I use the CSS code:
margin: 0px auto;
width: 670px;
However, I want a colored header to cover 100% of the width, while the text within the header adjusts with the rest of the page. How do I simultaneously do these two things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
像这样的东西,当然你应该使用完整规范的 html 和链接的 css 样式表......
something like this, of course you should use full spec html and linked css style sheets...
下面是一个页面示例,其标题延伸到屏幕的整个宽度,但内容仅限于 670 像素区域。
http://jsfiddle.net/CaUD3/
希望能帮助您入门。
鲍勃
Here is an example of a page with a header that stretches the full width of the screen, but has content that is limited to the 670px area.
http://jsfiddle.net/CaUD3/
Hope that gets you started.
Bob
margin
属性中使用的值之间不应有逗号。相反,它应该显示如下:You shouldn't have a comma between the values used in the
margin
property. Instead, it should appear as follows:将文本嵌套在文本当前所在容器内的段落中,并将段落的样式设置为您需要的样式,同时将容器的样式设置为 100% 宽度。
Nest the text in a paragraph within the container the text is currently in, and set the paragraph's style to what you need it to be, while setting the container's style to be 100% width.
使用margin-left:20%;
右边距:20%
这应该集中你的内容。
如果你想要一个现成的解决方案。看看 Matthew taylor 的布局
Use
margin-left:20%;
margin-right:20%
That should centre your content.
If u want a readymade solution. take a look at Matthew taylor's Layouts
您将需要嵌套一些 div...
这应该将您的 div#container 居中,然后您可以将内容放入该容器中。
编辑:上面的内容只会将您的页面容器居中。我错过了标题部分。这是...
You will need to nest some divs...
That should center your div#container and you can put your content within that container.
EDIT: The above will just center your page container. I missed the header part. Here is that...