我有一个有3个部分的网格。我想要的是中间的“地图”部分可以调整大小,当它变小时,“点”部分将扩展以占用所有剩余的空间。
#grid {
display: grid;
grid-template-rows: 1fr 6fr 2fr;
grid-template-areas:
"slider"
"map"
"points";
width: 200px;
height: calc(100vh - 10px);
}
.one {
grid-area: slider;
background-color: yellow;
}
.three {
grid-area: points;
background-color: green;
}
.resizeme {
grid-area: map;
resize: vertical;
overflow: auto;
background-color: orange;
}
<div id="grid">
<div id="item1" class="one">hello1</div>
<div id="item2" class="resizeme">you can resize me</div>
<div id="item3" class="three">three</div>
</div>
答案 0 :(得分:3)
不使用fr
作为可调整大小元素的高度,而是使用auto
。然后根据需要在项目本身上设置最小高度。
#grid {
display: grid;
grid-template-rows: 1fr auto 2fr;
grid-template-areas: "slider" "map" "points";
width: 200px;
height: calc(100vh - 10px);
}
.one {
grid-area: slider;
background-color: yellow;
}
.three {
grid-area: points;
background-color: green;
}
.resizeme {
grid-area: map;
resize: vertical;
overflow: auto;
background-color: orange;
/* min-height: 50px; */
}
<div id="grid">
<div id="item1" class="one">hello1</div>
<div id="item2" class="resizeme">you can resize me</div>
<div id="item3" class="three">three</div>
</div>