简体   繁体   English

属性滚动条宽度在css中不起作用

[英]Property scrollbar-width not working in css

I'm trying to set the width of the scrollbar to 'thin' and 'none', neither of them are working.我正在尝试将滚动条的宽度设置为“薄”和“无”,它们都不起作用。 I have also tried using -webkit- NOTE: I'VE SET THE OVERFLOW TO 'AUTO', IS IT THAT THE SCROLLBAR-WIDTH PROPERTY IS NOT WORKING?我也尝试过使用 -webkit- 注意:我已将溢出设置为“自动”,是否滚动条宽度属性不起作用?

The following is my HTML:以下是我的 HTML:

<div class="chat__chatting">
        <div class="chat__scrollable-chat">
          <div class="chat__chatting__header">
            <div class="chat__chatting__header--img">
              <img src="../../assets/person.png" />
            </div>
            <div class="chat__chatting__header--descr">
              <div class="chat__chatting__header--name">Alexender</div>
              <div class="chat__chatting__header--location">Birmingham, United Kingdom</div>
              <div class="chat__chatting__header--age">Age 24</div>
            </div>
          </div>
          <div class="chat__chatting__body">
            <div class="chat__chatting__body--rcv-msg">
              <div class="chat__chatting__body--rcv-msg--img">
                <img src="../../assets/person.png" />
              </div>
              <div class="chat__chatting__body--rcv-msg---text">How are you?</div>
            </div>
            <div class="chat__chatting__body--sent-msg">
              <div class="chat__chatting__body--sent-msg--img">
                <img src="../../assets/person.png" />
              </div>
              <div class="chat__chatting__body--sent-msg---text">I'm fine</div>
            </div>
          </div>
        </div>
        <div class="chat__chatting__footer">
          <textarea rows="1" class="chat__chatting__footer--textfield"></textarea>
          <div class="chat__chatting__footer--send-btn">
            <img src="../../assets/send.svg" />
          </div>
        </div>
      </div>

And SCSS:和 SCSS:

.chat{
&__scrollable-chat {
    overflow-y: auto;
    flex-grow: 1;
    scrollbar-width: none;
  }
  &__chatting {
    border-radius: 4px;
    flex: 3;
    height: 100%;
    background-color: #fff;
    display: flex;
    flex-flow: column;
    flex-grow: 3;
    &__header {
      display: flex;
      flex-direction: row;
      justify-content: center;
      padding: 2rem 0;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
      &--img {
        width: 11rem;
        height: 11rem;
        overflow: hidden;
        border-radius: 50%;
        overflow: hidden;
        margin-right: 1.5rem;
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
      &--descr {
        padding-top: 1rem;
      }
      &--name {
        font-size: 2.2rem;
        color: $color-text;
        padding-bottom: 0.6rem;
      }
      &--location,
      &--age {
        color: rgb(163, 163, 163);
        font-size: 1.5rem;
        display: block;
      }
    }

    &__footer {
      background-color: #f9f9f9;
      display: flex;
      flex-direction: row;
      padding: 1rem 3rem;
      position: sticky;
      left: 0;
      bottom: 0;
      align-items: stretch;
      &--textfield {
        border: 1px solid rgba(0, 0, 0, 0.1);
        resize: none;
        font-size: 1.7rem;
        font-family: "Lato", sans-serif;
        padding: 7px 1.4rem;
        color: $color-text;
        outline: none;
        width: 100%;
        scrollbar-width: none;
        border-radius: 15px;
        max-width: 100%;
        margin-right: 1.2rem;
      }
      &--send-btn {
        width: 4rem;
        height: 4rem;
        img {
          height: 100%;
          width: 100%;
          object-fit: fit;
        }
      }
    }
  }
}

Can someone please come up with a possible solution.有人可以提出一个可能的解决方案。

The scrollbar-width is too new for browser. scrollbar-width对于浏览器来说太新了。 Ref: Can I use scrollbar-width?参考:我可以使用滚动条宽度吗?

For other solution only for webkit browser (chrome, safari, and newer edge)仅适用于 webkit 浏览器的其他解决方案(chrome、safari 和更新的边缘)

 ::-webkit-scrollbar { width: 8px; } ::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); } ::-webkit-scrollbar-thumb { background-color: darkgrey; outline: 1px solid slategrey; }
 <textarea>ABCDE<br>ABCDE<br>ABCDE<br>ABCDE<br>ABCDE<br>ABCDE</textarea>

From the URL below, you can see the "scrollbar-width" is quite unpopular among browsers so that might be the reason why it's not working =>从下面的 URL,您可以看到“滚动条宽度”在浏览器中非常不受欢迎,因此这可能是它不起作用的原因 =>

https://caniuse.com/?search=scrollbar-width https://caniuse.com/?search=scrollbar-width

You can use WebKit like您可以像使用 WebKit

  1. You have an element with scroll functionality.您有一个具有滚动功能的元素。

  2. set "::-webkit-scrollbar" on the same scroll element =>在同一个滚动元素上设置“::-webkit-scrollbar” =>

    .scroll-element::-webkit-scrollbar { width: 4px; .scroll-element::-webkit-scrollbar { 宽度:4px; height: 100%;高度:100%; background-color: gray;背景颜色:灰色; } }

Keep in mind that this "background-color: gray" is for the scrollbar background and NOT for the actual scroller.请记住,此“背景颜色:灰色”用于滚动条背景,而不用于实际滚动条。

  1. Let's make the actual scroller (the moving part) a different color, now use the "::webkit-scrollbar-thumb" =>让我们让实际的滚动条(移动部分)变成不同的颜色,现在使用 "::webkit-scrollbar-thumb" =>

    .scroll-element::-webkit-scrollbar-thumb { background: #000; .scroll-element::-webkit-scrollbar-thumb { 背景:#000; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM