【发布时间】:2020-10-06 14:03:53
【问题描述】:
我偶然发现了一个前端问题,我无法弄清楚最好的方法是什么。 我需要实现的简化布局可以看这里:https://jsfiddle.net/kw56sa84/
content-block {
min-height: 100px;
background: #aaa;
border: 1px solid;
}
.end-of-body-block {
width: 50%;
margin: 0 auto;
padding: 30px;
border: 1px solid #a00;
position: relative;
transform: translateY(50%);
text-shadow: 0 0 2px #fff;
background: rgba(250, 180, 180, 0.9)
}
.footer {
min-height: 300px;
background: #0A152B;
color: #fff;
}
<div class="wrapper">
<div class="content">
<div class="content-block">Some content</div>
<div class="content-block">Some content</div>
<div class="end-of-body-block">
Some text here that can have into a dynamic height, and responsively height increases.
</div>
</div>
<div class="footer">
Links and other information that should be visible
</div>
</div>
基本上我所拥有的是内容和页脚,并且有一个块应该在正文中占 50%,在页脚中占 50%,并且两个元素内容都通过连接元素的动态半高移动。在 jsfiddle 示例中,页脚内容应该有某种填充。所有元素的高度都是动态的。
我想这里的主要问题是 - 是否可以使用 CSS 来实现这一点(解决方案可能包括网格、弹性框),还是我运气不好,应该寻求 JS 解决方案?
提前致谢!
【问题讨论】:
-
我无法想象您到底在寻找什么。你能添加一些图像或灰色线框吗?
-
抱歉,我想我可以在解释方面做得更好一些。但是,如果它是一个固定高度,如here,那么我只需为红色元素添加 margin-bottom: -halfHeight,然后为页脚 padding-top: halfHeight 添加。很快就会尝试绘制它。
标签: javascript html css layout frontend