css盒子隐藏滚动条且内部盒子水平自适应宽度

发布于:2023-01-04 ⋅ 阅读:(261) ⋅ 点赞:(0)

1.css盒子隐藏滚动条且内部盒子水平自适应宽度

代码

 <div class="left-box">
      <div class="dang-list-out">
        <div class="continer-inner">
          <div class="content-box">
            hahahah你好你哈哈哈哈哈啊啊啊啊啊卡啊环境监控
          </div>
        </div>
      </div>
</div>
 .left-box {
        /* 无关代码 */
        width: 49%;
        height: 100%;
        border: 1.5px solid #d3d3d3;
        border-radius: 20px;
        box-shadow: 0 5px 14px #d3d3d3;
        padding-right: 20px;
        display: flex;
        justify-content: space-between;
        box-sizing: border-box;
        position: relative;
        padding: 10px;
      }
      .dang-list-out {
        width: 100%;
        height: 190px;
        margin: 0 auto;
        position: relative;
        overflow: hidden;
        background: #bfc;
      }
      .continer-inner {
        /* 主要计算代码,因为滚动条的宽度是17px ,所以这样做,可以实现自适应盒子,且自己滚动条会隐藏 */
        width: calc(100% + 17px);
        height: 200px;
        position: absolute;
        overflow-y: scroll;
        display: flex;
        flex-direction: column;
      }

在这里插入图片描述

2.如果没有 width: calc(100% + 17px);这段代码

只有width:100%,将会出现滚动条。
在这里插入图片描述

3.总结:可以隐藏滚动条,且能够盒子自适应

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到