修复了滚动列表顶部的标题。 Flex布局,所有列的高度相同

时间:2015-10-25 14:11:31

标签: html css

似乎无法让这个工作。想要为不使用div滚动的蓝色和绿色div添加固定标题。使这复杂化的原因是:

  • 左边的红色画布只是宽度缩小的元素
  • Canvas元素保持宽高比,高度也缩小
  • 随着画布高度的缩小,蓝色和绿色div的高度也会缩小。

JSFiddle

HTML

<div class="container">
  <div class="left">
    <canvas id="draw" width="250" height="300"></canvas>
  </div>
  <div class="center"><div id="center" class="scroll"></div></div>
  <div class="right"><div id="right" class="scroll"></div></div>
</div>

CSS

.container {
  max-width: 650px;
  margin: 0 auto;
  border: 1px solid black;
  display: flex;
}
.container > div {
  position: relative;
  min-width: 0;
}
.left {
  max-width: 250px;
  width: auto;
}
.left canvas {
  display: block;
  max-width: 100%;
  height: auto;
}
.center {
  flex: 0 0 200px;
  overflow-y: scroll;
  background-color: blue;
}
.right {
  flex: 0 0 200px;
  overflow-y: scroll;
  background-color: green;
}
.scroll {
  position: absolute;
  width: 100%;
}

的JavaScript

var c = document.getElementById("draw");
ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 250, 300);
ctx.fillStyle = "white";
ctx.font = "bold 40pt Arial";
ctx.fillText("CANVAS", 10, 100);

tmp = "";
for (var i = 0; i < 100; i++) {
    tmp += "<p>" + i + "</p>";
}

document.getElementById("center").innerHTML = tmp;
document.getElementById("right").innerHTML = tmp;

1 个答案:

答案 0 :(得分:1)

  

想要为不使用div滚动的蓝色和绿色div添加固定标题

检查以下内容是否适用于您:

&#13;
&#13;
var c = document.getElementById("draw");
ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 250, 300);
ctx.fillStyle = "white";
ctx.font = "bold 40pt Arial";
ctx.fillText("CANVAS", 10, 100);

tmp = "";
for (var i = 0; i < 100; i++) {
  tmp += "<p>" + i + "</p>";
}

document.getElementById("center").innerHTML = tmp;
document.getElementById("right").innerHTML = tmp;
&#13;
.container {
  max-width: 650px;
  margin: 0 auto;
  border: 1px solid black;
  display: flex;
}
.container > div {
  position: relative;
  min-width: 0;
}
.left {
  max-width: 250px;
  width: auto;
  flex: 1;
}
.left canvas {
  display: block;
  max-width: 100%;
  height: auto;
}
.center {
  flex: 0 0 200px;
  background-color: #0000ff;
}
.right {
  flex: 0 0 200px;
  background-color: green;
}
.scroll {
  position: absolute;
  width: 100%;
  top: 40px;
  bottom: 0;
  overflow-y: auto;
}
.header {
  height: 40px;
  line-height: 40px;
}
.center .header {
  background-color: #aaaaff;
}
.right .header {
  background-color: #aaff00;
}
&#13;
<div class="container">
  <div class="left">
    <canvas id="draw" width="250" height="300"></canvas>
  </div>
  <div class="center">
    <div class="header">fixed header</div>
    <div id="center" class="scroll"></div>
  </div>
  <div class="right">
    <div class="header">fixed header</div>
    <div id="right" class="scroll"></div>
  </div>
</div>
&#13;
&#13;
&#13;

相关问题