zhangzxpan 2023-01-17 17:01 采纳率: 76.5%
浏览 46

两个DIV横向并列,一个高度固定,另一个如何自由调整大小?

在DIV0中有两个DIV,其中DIV1的大小是固定的,DIV2无法改变高度,DIV0只会随着DIV1的改变而改变。应该如何调整?
现在希望的效果是:DIV2随着内容改变,高度会改变,DIV1大小不变,垂直居中。
CSS设置为:

DIV0{
        height: 100%;
        width: 100%;
        position: relative;}
DIV1{
         width: 14%;
          height: 14%;
          display: inline-block;
}
DIV2{
          display: inline-block;
          position: absolute;
          height: 100%;}

img

  • 写回答

3条回答 默认 最新

  • CSDN专家-showbo 2023-01-17 21:25
    关注

    DIV2 absolute定位需要设置宽度,要不是0无法显示出来。可以用flex布局,align-items: center;

    <!doctype html>
    <style>.wrap{width:640px;margin:50px auto}
        #DIV0 {
            height: 100%;
            width: 100%;
            position: relative;
            background: #ccc;
            padding: 100px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-sizing: border-box
        }
    
        #DIV1, #DIV2 {
            width: 200px;
            height: 200px;
            display: inline-block;
            background: blue
        }
    
        #DIV2 {
            height: auto;/*自动高度*/
            background: yellow
        }
    </style>
    <div class="wrap">
        <div id="DIV0">
            <div id="DIV1"></div>
            <div id="DIV2">
                1<br />2<br />3<br />
                1<br />2<br />3<br />
                1<br />2<br />3<br />
                1<br />2<br />3<br />
                1<br />2<br />3<br />
                1<br />2<br />3
            </div>
        </div>
    </div>
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 1月17日

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行