我正在构建一个 UI,它需要在视口底部有一个固定位置/粘性元素,其宽度受主要内容区域的限制。主要内容区域的两侧可以选择具有固定宽度的(同级)左侧和/或右侧边栏,因此我使用 Flexbox 来构建三列结构flex-grow: 1
就主要内容而言。
我从 @Marc Audet 接受的答案中了解到如何使固定定位的 div 继承父级的宽度? https://stackoverflow.com/questions/27982966/how-can-i-make-a-fixed-positioned-div-inherit-width-of-parent那个设置width: inherit
固定元素上的问题通常是如何解决这个问题,但它似乎只有在其父元素上有指定宽度时才起作用,考虑到我需要主要内容区域来填充页面的剩余宽度,这对我没有帮助。
有人有解决这个问题的想法吗?看看我的Fiddle https://jsfiddle.net/wfc3n6zk/对于代码/示例。任何帮助,将不胜感激!
CSS
html {
box-sizing: border-box;
font: 400 16px/1.45 'Source Code Pro';
}
*,
*:before,
*:after {
box-sizing: inherit;
margin: 0;
padding: 0;
border: 0;
outline: none;
overflow-x: hidden;
}
body {
background: #121;
color: #FEF;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
width: 100vw;
height: 100vh;
}
.container {
display: flex;
color: #fff;
height: -moz-fit-content;
height: -webkit-fit-content;
height: fit-content;
background: blue;
}
.left {
background: blue;
min-height: 100vh;
min-width: 150px;
flex-shrink: 0;
}
.middle {
background: green;
min-height: 100vh;
overflow: hidden;
width: calc(100vw - 400px);
padding-bottom: 60px;
flex-grow: 1;
flex-shrink: 0;
}
.middle .fixed-footer {
background: orange;
position: fixed;
bottom: 0;
width: 100vw;
width: inherit;
padding: 16px 0;
overflow-x: hidden;
}
.right {
background: blue;
min-height: 100vh;
min-width: 250px;
flex-shrink: 0;
}
@media screen and (min-width: 640px) {
html {
margin-left: calc(100vw - 100%);
margin-right: 0;
overflow-y: auto;
}
}
添加了星球大战 ipsum 内容来演示.middle
的垂直灵活性以及如何.fixed-footer
是静止的并且是.middle
的宽度。
DEMO https://jsfiddle.net/zer00ne/je5nchcj/embedded/result/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)