gpt4 book ai didi

javascript - “拉伸(stretch)”一个 div 到浏览器的边缘

转载 作者:搜寻专家 更新时间:2023-10-31 08:37:44 25 4
gpt4 key购买 nike

我正在尝试实现固定宽度的居中布局,其中的标题“延伸”到用户浏览器的边缘。像这样...

Layout Example

有什么办法可以实现吗?

最佳答案

这很好用。它可以进行一些改进,但这个想法非常可靠。

Live Demo ( edit )

CSS:

html, body {
margin: 0;
padding: 0;
border: 0;
overflow-x: hidden
}
body {
background: #eee
}
#container {
width: 80%;
margin: 0 auto;
background: #bbb;
}
#menu {
overflow: auto
}
#menu li {
float: left;
width: 40px;
margin: 5px;
height: 24px;
background: #fff
}
h1, h1 span, h2, h2 span {
padding: 3px 0;
height: 25px;
}
h1, h2 {
position: relative;
margin: 9px 0
}
h1 span, h2.left span {
display: block;
position: absolute;
width: 100%;
left: -100%;
top: 0
}
h2.right span {
display: block;
position: absolute;
width: 102%;
left: 100%;
top: 0
}

h1 {
background: red;
width: 80%
}
h1 span {
background: blue /* blue for demonstration purposes */
}
h2.left {
background: red;
width: 30%;
float: left
}
h2.left span {
background: blue /* blue for demonstration purposes */
}
h2.right {
background: red;
width: 30%;
float: right
}
h2.right span {
background: blue /* blue for demonstration purposes */
}

#content {
clear: both
}

HTML:

<div id="container">
<h1><span></span>Heading</h1>
<h2 class="left"><span></span>Sub-heading</h2>
<h2 class="right">Sub-heading<span></span></h2>
<div id="content">
Hi!
</div>
</div>

关于javascript - “拉伸(stretch)”一个 div 到浏览器的边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5119898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com