gpt4 book ai didi

html - CSS 布局难题

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

我必须构建一个具有非常特定布局的网页。

  • 有一个固定的容器,它是整个浏览器窗口带有20px的有效边距,然后该容器内的两个面板。
  • 两个面板都必须消耗整个容器的宽度。
  • 小组 2 必须位于底部容器,需要向上生长取决于其内容。
  • 面板 1应该占据整个剩余容器的空内容物,尽管底部边距为 20px,并且滚动条应该出现在其中的内容溢出(即溢出:自动)。

这是一个示例,带有令人眼花缭乱的丑陋颜色:(容器和面板 2 正常工作 - 面板 1 出错了。)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style type="text/css">
body {
background-color: gray;
}

#container {
position: fixed;
top: 20px;
right: 20px;
bottom: 20px;
left: 20px;
border: dashed red;
overflow: hidden;
}

#panel1 {
background-color: green;
color: white;
margin-bottom: 20px;
padding: 20px;
overflow: auto;
}

#panel2 {
background-color: blue;
color: white;
padding: 20px;
position: absolute;
right: 0;
bottom: 0;
left: 0;
}
</style>
</head>

<body>
<div id="container">
<div id="panel1">
<h2>Panel 1</h2>
<p>This panel should occupy all space in the container not occupied by Panel 2, with a scrollbar appearing when content overflows (ie overflow: auto) and a 20px bottom margin.</p>
</div>
<div id="panel2">
<h2>Panel 2</h2>
<p>This panel should be positioned at the bottom of the container and grow upwards depending on its content.</p>
</div>
</div>
</body>
</html>

有谁知道实现此目标的最佳方法?我很少深入研究 CSS,所以我可能会遗漏一些明显的东西。理想情况下,解决方案应使用 CSS <= 2.1、符合标准、不依赖 JavaScript,并且不应依赖固定高度。

谢谢!

最佳答案

由于您的限制,您不能。

关于html - CSS 布局难题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4140008/

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