css

Posted zc-lee

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css相关的知识,希望对你有一定的参考价值。

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>
Lee2

以上是关于css的主要内容,如果未能解决你的问题,请参考以下文章

css [css:fadeout / fadein] css示例。 #css

css基础 CSS 组合选择符CSS 伪类CSS 伪元素

css 深度提示#css中的css base builder CSS

css基础 CSS 媒体类型CSS 属性 选择器CSS 表单CSS 计数器

什么是css

测开之CSS・第一篇《CSS语法基础》