我的目标不是使用额外的块(这很容易将我的标记转换为 div-soup),但在这种情况下我必须这样做。解决方案是使用CSS的position属性,原始想法和技术细节可以在这里找到。为了实现滚动内容,我将紫色块变成了包装器,它是面向列的 Flex(蓝色块)的子级,其 Flex-grow 能力设置为 1。它占据了父级中的所有可用空间。包装纸相对定位。在这个块中,我有另一个块,它具有绝对位置,并且大小由top、bottom、left和right属性决定。这是内容所在的块,它已overflow设置为自动。
没有包装我没有解决方案。
这是现场演示:
var scrollElem = document.getElementById('scroll');
for (var i = 0; i < 100; i++) {
(function() {
var e = document.createElement('div');
e.classList.add('item');
e.innerText = "Content piece";
scrollElem.appendChild(e);
}());
}Run Code Online (Sandbox Code Playgroud)
HTML {
width: 100vw;
height: 100vh;
font-family: sans-serif;
font-weight: 700;
}
BODY,
#main {
width: 100%;
height: 100%;
margin: 0;
font-size: 0.75em;
}
/*||||*/
#scroll {
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: auto;
text-align: left;
}
#footer {
height: 30px;
}
/*||||*/
#main {
background-color: rgb(255, 215, 125);
}
#upper {
background-color: rgb(170, 215, 125);
}
#bottom {
background-color: rgb(200, 50, 180);
}
#left {
box-shadow: inset -3px 0 15px 0 rgba(60, 5, 20, 0.5);
}
#right {
box-shadow: inset 3px 0 15px 0 rgba(60, 5, 20, 0.5);
}
#footer {
box-shadow: inset 0 3px 15px 0 rgba(60, 5, 20, 0.5);
}
#left,
#right,
#footer {
color: rgba(60, 5, 20, 0.8);
}
/*||||*/
.D-f {
display: flex;
}
.A-I-c {
align-items: center;
}
.F-D-c {
flex-direction: column;
}
.F-D-r {
flex-direction: row;
}
.J-C-c {
justify-content: center;
}
.J-C-sa {
justify-content: space-around;
}
.J-C-sb {
justify-content: space-between;
}
.F-G-1 {
flex-grow: 1;
}
.F-G-2 {
flex-grow: 2;
}
.F-G-3 {
flex-grow: 3;
}
.F-G-4 {
flex-grow: 4;
}
.F-G-5 {
flex-grow: 5;
}
.F-W-nw {
flex-wrap: nowrap;
}
.F-W-w {
flex-wrap: wrap;
}
.Pos {
position: relative;
}
.Pos-a {
position: absolute;
}
/*||||*/
#upper,
#bottom {
padding: 1em;
text-align: center;
}
#upper .popout {
display: none;
}
#upper:hover .popout {
display: initial;
}
ASIDE SPAN { font-size : 0.6em; }Run Code Online (Sandbox Code Playgroud)
<div id="main" class="D-f F-D-c J-C-sb">
<div id="page" class="F-G-1 D-f J-C-sb">
<aside id="left" class="F-G-3 D-f J-C-c A-I-c">
Left aside
<br/>
<span><sup>3</sup>/<sub>12</sub></span>
</aside>
<div id="content" class="F-G-5 D-f F-D-c">
<div id="upper">
<h3>Upper block</h3>
<div class="popout">Ta-Da!</div>
</div>
<div id="bottom" class="F-G-1 D-f F-D-c">
<h3 class="header">Header</h3>
<div class="misc">Misc</div>
<div id="scroll-wrap" class="Pos F-G-1">
<div id="scroll" class="Pos-a"></div>
</div>
</div>
</div>
<aside id="right" class="F-G-2 D-f J-C-c A-I-c">
Right aside
<br/>
<span><sup>2</sup>/<sub>12</sub></span>
</aside>
</div>
<div id="footer" class="D-f A-I-c J-C-c">Footer</div>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3617 次 |
| 最近记录: |