gpt4 book ai didi

html - 使 div 固定在另一个 div 之上的底部

转载 作者:太空宇宙 更新时间:2023-11-04 04:47:09 25 4
gpt4 key购买 nike

我一直在开发带有水平滚动条的移动布局。

但是现在我遇到了一个问题:

页面底部有一个 NAV 元素,没问题,但我想在顶部和底部实现“软木板”的效果,并带有相应的“框架”。再一次,顶部的完全没有问题,但我在试图让底部的保持在底部并高于 NAV 栏时遇到了很多麻烦。

事情是这样的: enter image description here

基本上,红色方 block 是当前 View /屏幕,导航栏固定在底部,如果我滚动到另一个部分,它会按预期停留在屏幕底部,顶部蓝色条(顶部框架)也是如此).

如何使底部的蓝色条保持在预期/示例的位置?

HTML:

    <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<title>Ptfolio</title>
<link rel="stylesheet" href="css/style.css">
<script src="js/less.js" type="text/javascript"></script>
<link href='http://fonts.googleapis.com/css?family=Faster+One' rel='stylesheet' type='text/css'>
</head>
<body>
<nav>
<ul>
<li><a href="#splash">Home</a></li>
<li><a href="#next">About</a></li>
<li><a href="#circuit">Circuit</a></li>
</ul>
</nav>
<div id="wrapper">
<section id="splash">
<header>About Me</header>
<div>
Lorem ipsum just testing things
</div>
</section>
<section id="next">
<div id="frame-top">
<header>Portfolio</header>

<div id="content">&nbsp</div>
</div>
<div id="frame-bottom">&nbsp</div>
</section>
<section id="circuit">
<header>Contact</header>
<div class="main">
</div>
</section>
</div> <!-- wrapper -->
<script type="text/javascript" src="cordova-2.3.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>

和CSS:

        /* --Meyerweb */
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/* --Meyerweb */

html, body {
height: 100%;
overflow-x: auto;
}

#wrapper {
display: table;
width: 350%;
height: 100%;
-webkit-box-sizing: border-box;
padding-bottom: 3em;
position: relative;
}

#wrapper > section {
display: table-cell;
height: 100%;
width: 25%;
}

header {
min-height: 2em;
font-size: 2em;
}


section#splash {
background: url("../img/bg_grey.png") repeat;
}

section#splash > header {
font-family: 'Faster One', cursive;
}

section#next {
background: url("../img/cork.jpg") repeat;
z-index: 1;
padding-bottom: 3.938em;
}

#frame-top {
background: url("../img/frame.png") repeat-x;
background-position: top;
z-index: 3;
width: 100%;
padding-top: 1em;
}

#frame-bottom {
background: url("../img/frame.png") repeat-x;
height: 16px;
background-position: top;
z-index: 4;
}

#content {
height: 100%;
z-index: 2;
}

section#circuit {
background: url("../img/circuit-tile-02.png") repeat;
}

.st-scroll {
top: 0;
left: 0;
transition: all 0.6s ease-in-out;

/* Let's enforce some hardware acceleration */
-webkit-transform: translate3d(0, 0, 0);
-webkit-backface-visibility: hidden;
}

nav {
bottom: 0;
position: absolute;
background: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.3, #303030),
color-stop(0.5, #212121),
color-stop(0.7, #575657)
);
height: 3em;
width: 100%;
z-index: 99;
}

nav ul {
width: 50%;
height: 100%;
color: #FFF;
margin-right: auto;
margin-left: auto;
}

nav ul li{
width: 25%;
height: 100%;
display: inline-block;
}

我已经尝试了所有方法,包括边距、填充、高度和最小高度,但无法达到预期的效果。谁能指出我做错了什么?

编辑:当前页面的屏幕截图: Chrome - enter image description here

Safari - enter image description here

最佳答案

如果我没看错,问题是背景卡在元素的顶部而不是底部?

background-position: bottom; 添加到该元素的样式中。


编辑以添加我的解决方案 css:

  • HTML 与原始帖子没有变化
  • “Meyerweb”CSS 保持不变
  • 更改的 CSS:
html, body { 
height: 100%;
overflow: hidden;
}
body {
overflow-x: auto;
/* allows that horizontal scrolling */
}

#wrapper {
width: 350%;
position: absolute;
top: 0px;
bottom: 0px;
/* ^-- these three lines replace height:100%
* and correct some layout quirks */
}
#wrapper > section {
display: inline-block;
height: 100%;
margin-left: -4px;
margin-bottom: -4px;
}

#wrapper > section:first-child {
margin-left: 0px;
/* combined with -4px margin above, eliminates gaps between sections */
}

#wrapper > section, section > header, section > div {
width: 25%;
/* not sure why 25%, since you seem to only
* have three sections... but either way,
* the same value is needed in multiple locations
* so it's pulled out on its own here for
* ease of maintenance */
}

section > header {
position: absolute;
top: 0px;
height: 3em;
}
section > div {
position: absolute;
top: 0px;
height: 100%;
padding-top: 3em;
padding-bottom: 3em;
box-sizing: border-box;
}

section#splash { /*unchanged*/
background: url("../img/bg_grey.png") repeat;
}
section#next { /*unchanged*/
background: url("../img/cork.jpg") repeat;
z-index: 1;
}
section#next > header#frame-top { /*unchanged*/
background: url("../img/frame.png") repeat-x;
background-position: top;
z-index: 3;
}
section#next > div#frame-bottom {
background: url("../img/frame.png") repeat-x;
background-position: bottom;
background-origin: content-box;
z-index: 3;
}
section#circuit { /*unchanged*/
background: url("../img/circuit-tile-02.png") repeat;
}

.st-scroll { /*unchanged*/
top: 0;
left: 0;
transition: all 0.6s ease-in-out;

/* Let's enforce some hardware acceleration */
-webkit-transform: translate3d(0, 0, 0);
-webkit-backface-visibility: hidden;
}

nav {
bottom: 0;
left: 0;
position: fixed;
background: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.3, #303030),
color-stop(0.5, #212121),
color-stop(0.7, #575657)
);
background: linear-gradient(to top, #303030 30%, #212121 50%, #575657 70%);
/* ^-- for non-webkit */
height: 3em;
width: 100%;
z-index: 5;
}

nav ul { /*unchanged*/
width: 50%;
height: 100%;
color: #FFF;
margin-right: auto;
margin-left: auto;
}

nav ul li{ /*unchanged*/
width: 25%;
height: 100%;
display: inline-block;
}

关于html - 使 div 固定在另一个 div 之上的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14285034/

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