全宽背景,没有包装

编程入门 行业动态 更新时间:2024-10-11 23:20:00
本文介绍了全宽背景,没有包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在一个网站上工作,我想我会看看是否有更好的方法来获得相同的结果。

问题: 网页由多个部分组成,每个部分都有自己的背景,应该是浏览器的整个宽度。每个部分中的内容以960px为中心。目前,我把每个部分包装在一个看似无神论的包装中。有没有人有更好的soloution?

示例代码:

;!doctype html> < html> < head> < meta charset =utf-8> < title>问题示例< / title> < style> .content { width:960px; margin:0 auto; padding:90px 0; background:rgba(0,0,0,0.5); } #header_wrapper { background:red } #content_wrapper { background:green } #footer_wrapper { background:yellow } < / style> < / head> < body> < div id =header_wrapper> < div class =content> 标题内容< / div> < / div> < div id =content_wrapper> < div class =content> 内容内容< / div> < / div> < div id =footer_wrapper> < div class =content> 页脚内容< / div> < / div> < / body> < / html>

理想解决方案:同一页面,但没有3个额外的封装div。

建议任何人?

解决方案

您的要求是相互矛盾的。 p>

您指定三个部分中的每一个应跨越页面的整个宽度(并包含不同的背景),但每个部分的内容必须限制为960像素。单个div不能同时具有100%宽度和960px宽度。没有做一些JavaScript魔术,你乱七八糟的间距,你不能实现这个没有折叠的div。

I'm working on a site, and thought I'd see if there is a better way to achive the same result.

The problem: The page is made up of several sections, each one with its own background, that should be the full width of the browser. The content within each section is in a 960px centered. At present I am wrapping each section in a, seemingly unnessary, wrapper. Does anyone have a better soloution?

Example Code:

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Problem Example</title> <style> .content{ width:960px; margin: 0 auto; padding: 90px 0; background: rgba(0,0,0,0.5); } #header_wrapper{ background: red } #content_wrapper{ background: green } #footer_wrapper{ background: yellow } </style> </head> <body> <div id="header_wrapper"> <div class="content"> Header Content </div> </div> <div id="content_wrapper"> <div class="content"> Content Content </div> </div> <div id="footer_wrapper"> <div class="content"> Footer Content </div> </div> </body> </html>

Ideal Solution: The same page but without the 3 extra wrapper divs.

Suggestions anyone?

解决方案

Your requirements are contradictory.

You specify that each of the three sections should span the entire width of the page (and contain different background) but the contents of each of these must be restricted to 960px. A single div can not simultaneously have 100% width and 960px width. Short of doing some JavaScript magic where you mess around with the spacing, you can not achieve this without folded divs.

更多推荐

全宽背景,没有包装

本文发布于:2023-11-23 04:11:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620039.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:背景

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!