gpt4 book ai didi

css - 自动继承另一个div的top属性的div高度?

转载 作者:行者123 更新时间:2023-11-28 18:28:10 24 4
gpt4 key购买 nike

这是我的工作示例:
http://jsfiddle.net/UGhKe/2/

CSS

#body {
height: 200px;
background: black;
width: 100%;
}
.header {
position: fixed;
top: 0;
background: #369;
z-index: 1;
width: 100%;
height: 5em;
}
.content {
position: absolute;
top: 5em;
overflow: hidden;
height: 1000px;
background: #936;
z-index: 0;
width: 100%;
}
.footer {
position: fixed;
bottom: 0;
background: #396;
width: 100%;
}
.large {
font-size: 120%;
padding: 2em;
}

HTML

<div id="body">
<div class="header">
<div class="large">Header</div>
</div>
<div class="content">
Content, you should be able to see this when you scroll to top.
</div>
<div class="footer">
<div class="large">Footer</div>
</div>
</div>

当您滚动顶部时,我希望内容位于标题下方(但当您向下滚动时隐藏在标题下方)- 这很好用...

但是我需要删除 top: 5em 并使用类似“继承标题的当前高度”之类的东西 - 没有 JS 可能吗?

如果没有 JS 真的不可能,那么我可以只使用 JS,但我宁愿尝试在纯 CSS 中找到解决方案。

编辑:

我应该注意,我不能使用 top: 5em 的原因是标题没有固定高度 - 图像(用于 Logo )将在文本内部使用,并将其设置为 max-width: 100% 以便它缩小到适合 iPhone 的宽度并且不会在 iPad 上扩展太多。

最佳答案

看看这是否适合您。 http://jsfiddle.net/UGhKe/3/

我添加了另一个具有相同高度但“非固定”的div 来模拟您的固定标题。

HTML

<div id="body">
<div id="blockHeader"></div>
<div class="header">
<div class="large">Header</div>
</div>
<div class="content">
Content, you should be able to see this when you scroll to top.
</div>
<div class="footer">
<div class="large">Footer</div>
</div>
</div>

CSS

html, body { margin:0;  padding:0; }

#blockHeader
{
width:100%;
height: 5em;
}

.content {
position: absolute;
overflow: hidden;
height: 1000px;
background: #936;
z-index: 0;
width: 100%;
}

关于css - 自动继承另一个div的top属性的div高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15097627/

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