其他分享
首页 > 其他分享> > css - flex 踩坑

css - flex 踩坑

作者:互联网

css - flex 踩坑

flex-shrink

  1. flex-shrink: 0 会导致元素宽度 无限拉长,不显示滚动或隐藏

ex

demo

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>flex-shrink 踩坑</title>
  </head>
  <body>
    <pre>
    `flex-shrink: 0` 会导致元素宽度 无限拉长,不显示滚动或隐藏 例举,问题和正常情况代码
    </pre
    >
    <div class="flex-shrink">
      <div class="item">left</div>
      <div class="item right scrollbar">
        <span class="lorem"
          >Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ut
          similique, quae eum, ullam aliquam aliquid veritatis magni dicta quod
          dolores debitis praesentium consequatur amet non fuga eos nostrum.
          Odio, sit?</span
        >
        <span class="lorem"
          >Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ut
          similique, quae eum, ullam aliquam aliquid veritatis magni dicta quod
          dolores debitis praesentium consequatur amet non fuga eos nostrum.
          Odio, sit?</span
        >
      </div>
    </div>
    <div class="flex-shrink scrollbar flex-shrink-bug">
      <div class="item">left</div>
      <div class="item right">
        <span class="lorem"
          >Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ut
          similique, quae eum, ullam aliquam aliquid veritatis magni dicta quod
          dolores debitis praesentium consequatur amet non fuga eos nostrum.
          Odio, sit?</span
        >
      </div>
    </div>
  </body>
  <style>
    :root {
      --size: 8px;
      --barColor: #999;
    }
    .flex-shrink {
      display: flex;
      overflow: auto;
    }
    .flex-shrink .item {
      border: 1px solid #ededed;
      background-color: aquamarine;
      flex-grow: 1;
      flex-shrink: 0;
      padding: 20px;
      overflow: auto;
    }
    .flex-shrink .right {
      background-color: bisque;
      flex-shrink: 1;
      display: flex;
    }
    .flex-shrink .right span {
      display: block;
      white-space: nowrap;
    }
    .flex-shrink-bug .right {
      flex-shrink: 0;
    }
    .scrollbar::-webkit-scrollbar {
      /*滚动条整体样式*/
      width: var(--size);
      /*高宽分别对应横竖滚动条的尺寸*/
      height: var(--size);
    }

    .scrollbar::-webkit-scrollbar-thumb {
      /*滚动条里面小方块*/
      border-radius: calc(var(--size) / 2);
      box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
      background: var(--barColor);
      background-clip: padding-box;
      border: 1px solid transparent;
    }

    .scrollbar::-webkit-scrollbar-track {
      /*滚动条里面轨道*/
      box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
      border-radius: 10px;
      background: #ededed;
    }
  </style>
</html>

标签:flex,sit,--,amet,scrollbar,shrink,css
来源: https://www.cnblogs.com/zc-lee/p/15841789.html