gpt4 book ai didi

html - 可滚动显示 :table-cell - not able to have fixed dimensions

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

我正在使用应用于某些 div 的 display:tabletable-rowtable-cell 样式。其中一个表格单元格中有一个巨大的图像。我想为单元格设置固定的宽度和高度,并使其可滚动,以便您可以在图像中移动。

问题是使用overflow:scroll,甚至是overflow:hidden,具有固定的宽度和高度似乎不会强制表格单元格的大小.

如何强制包含图像的 div 具有固定的高度/宽度?​​

    .table-wrap{
display:table;
}
.table-wrap > div{
display:table-row;
}
.table-wrap > div > div{
display:table-cell;
}
#map{
width:100px;
height:100px;
overflow:scroll;
}
<div id="interface">
<div class="table-wrap">
<div id="top">
<div id="map">
<img src="http://www.planwallpaper.com/static/images/ZhGEqAP.jpg">
</div>
<div id="sidebar">
sidebar
</div>
</div>
</div>
<div class="table-wrap">
<div id="bottom">
<div class="bla">
bla
</div>
<div class="bla">
bla
</div>
<div class="bla">
bla
</div>
</div>
</div>
</div>

最佳答案

由于 CSS 使用的 table 算法,您将无法将图像限制在 table-cell 中,除非您直接在img 元素。

我认为你最好的选择是使用 position img 作为 absolute 并让它看起来像你想要的那样。

下面的片段:

.table-wrap {
display: table;
width: 100%;
}
.table-wrap > div {
display: table-row;
}
.table-wrap > div > div {
display: table-cell;
border: 1px solid;
}
#map {
width: 100px;
height: 100px;
overflow: auto;
position: relative;
}
#map img {
position: absolute;
top: 0;
left: 0;
}
<div id="interface">
<div class="table-wrap">
<div id="top">
<div id="map">
<img src="http://www.planwallpaper.com/static/images/ZhGEqAP.jpg">
</div>
<div id="sidebar">
sidebar
</div>
</div>
</div>
<div class="table-wrap">
<div id="bottom">
<div class="bla">
bla
</div>
<div class="bla">
bla
</div>
<div class="bla">
bla
</div>
</div>
</div>
</div>

关于html - 可滚动显示 :table-cell - not able to have fixed dimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39307520/

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