【发布时间】:2021-09-24 05:37:33
【问题描述】:
我正在创建一个名为 Catty Music 的示例 flexbox 项目。
我看到的是出现了一个垂直滚动条。我想要做的是在底部有一个固定的div 与播放器控件@ 987654327@ 高度和位于其正上方的可滚动主要内容区域,它将填充视口高度的剩余部分 - 没有滚动条.
您可以在HERE 或以下 sn-p 看到它的快照。
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
background-color: #fff;
margin: 0;
font-family: Lato, sans-serif;
color: #222;
font-size: 0.9em;
}
main {
flex: 1 0 auto;
height: calc(100vh - 90px);
overflow: auto;
display: flex;
}
.content {
display: flex;
flex-direction: column;
flex: 1 1 auto;
}
.music-head {
display: flex;
flex: 0 0 280px;
padding: 40px;
background-color: #4e4e4e;
}
.music-list {
flex: 1 0 auto;
list-style-type: none;
padding: 5px 10px 0px;
}
li {
display: flex;
padding: 0 20px;
min-height: 50px;
}
li p {
flex: 0 0 25%;
}
li span.catty-cloud {
border: 1px solid black;
font-size: 0.6em;
padding: 3px;
}
li:nth-child(2n) {
background-color: #f2f2f2;
}
.catty-music {
display: flex;
flex-direction: column;
flex: 1 1 auto;
font-weight: 300;
color: #fff;
padding-left: 50px;
}
.catty-music div:nth-child(1) {
margin-bottom: auto;
}
.catty-music div:nth-child(2) {
margin-top: 0;
}
.catty-music div:nth-child(2) i.fa {
font-size: 0.9em;
padding: 0 0.7em;
}
.catty-music div:nth-child(1) p:first-child {
font-size: 1.8em;
margin: 0 0 10px;
}
aside {
display: flex;
flex-direction: column;
flex: 0 0 40px;
justify-content: space-around;
align-items: center;
background-color: #f2f2f2;
}
aside i.fa,
aside i.fab {
font-size: 0.9em;
}
footer {
display: flex;
flex: 0 0 90px;
padding: 10px;
color: #fff;
background-color: rgba(61, 100, 158, 0.9);
}
footer img {
width: 90px;
}
.footer-current-song-details {
margin-left: 10px;
margin-right: auto;
}
.footer-music-controls {
display: flex;
width: 50%;
margin-right: 10px;
justify-content: space-between;
align-items: center;
}
@media screen and (max-width: 670px) {
.music-head {
flex-direction: column;
}
.catty-music {
padding: 0;
}
.catty-music * {
text-align: center;
}
.catty-music div:nth-child(1) p:first-child {
font-size: 1em;
margin: 10px 0 10px;
}
.music-head > img {
margin: auto;
max-width: 50%;
}
.artist-details,
.album-details {
display: none;
}
}
<main>
<aside>
<i class="fa fa-bars"></i> <i class="fa fa-home"></i>
<i class="fa fa-search"></i> <i class="fa fa-volume-up"></i>
<i class="fa fa-user"></i> <i class="fab fa-spotify"></i>
<i class="fa fa-cog"></i> <i class="fab fa-soundcloud"></i>
</aside>
<section class="content">
<div class="music-head">
<img src="images/cattyboard.jpg" />
<section class="catty-music">
<div>
<p>CattyBoard Top 100 Single Charts (11.06.36)</p>
<p class="artist-details">Unknown Artist</p>
<p class="album-details">2016 . Charts . 100 songs</p>
</div>
<div>
<i class="fa fa-play"> Play all</i>
<i class="fa fa-plus"> Add to</i>
<i class="fa fa-ellipsis-h"> More</i>
</div>
</section>
</div>
<ul class="music-list">
<li>
<p>1. One Dance</p>
<p>Crake feat CatKid & Cyla</p>
<p>2:54</p>
<p><span class="catty-cloud">CATTY CLOUD SYNC</span></p>
</li>
<li>
<p>2. Panda</p>
<p>Cattee</p>
<p>4:06</p>
<p><span class="catty-cloud">CATTY CLOUD SYNC</span></p>
</li>
<li>
<p>3. Can't Stop the Feeling!</p>
<p>Catin Cimberlake</p>
<p>3:56</p>
<p><span class="catty-cloud">CATTY CLOUD SYNC</span></p>
</li>
<li>
<p>4. Work From Home</p>
<p>Cat Harmony feat Colla</p>
<p>3:34</p>
<p><span class="catty-cloud">CATTY CLOUD SYNC</span></p>
</li>
<li>
<p>1. One Dance</p>
<p>Crake feat CatKid & Cyla</p>
<p>2:54</p>
<p><span class="catty-cloud">CATTY CLOUD SYNC</span></p>
</li>
<li>
<p>2. Panda</p>
<p>Cattee</p>
<p>4:06</p>
<p><span class="catty-cloud">CATTY CLOUD SYNC</span></p>
</li>
</ul>
</section>
</main>
<footer>
<img src="images/cattyboard.jpg" />
<div class="footer-current-song-details">
<p>If It Ain't Love</p>
<p>Catson Derulo</p>
</div>
<div class="footer-music-controls">
<i class="fa fa-step-backward"></i>
<i class="fa fa-pause"></i>
<i class="fa fa-step-forward"></i>
<i class="fas fa-redo"></i>
<i class="fa fa-random sm-hide"></i>
</div>
</footer>
我的计算或浏览器的计算似乎有误。
我看到的是我的电脑上<main> 和<footer> 元素的总和是744px。 window.innerHeight 也给出 744px。 <html> 元素的高度也为 744px。我不知道这个滚动条是从哪里出现的。 Firefox DevTools 在<html> 元素上有一个标签,上面写着“这个元素导致元素溢出”。 <html> 是根元素,不是吗?那么<html> 元素使哪个外部元素溢出?
如果有人帮助我了解这里发生了什么,我会很高兴。
【问题讨论】:
-
我们不希望在外部网站上对您的问题进行“快照”,您的问题的正确minimal reproducible example 直接属于您的问题。
-
@CBroe 我添加了一个堆栈片段。
-
@CBroe 谢谢!除了我的错误之外,Chrome 或 Firefox 中似乎还存在一个错误(他们还没有解决哪个是正确的实现)。你可以在这里看到:bugzilla.mozilla.org/show_bug.cgi?id=1720680 在这里:stackoverflow.com/questions/68391656/…
标签: html css flexbox scrollbar overflow