代码之家  ›  专栏  ›  技术社区  ›  kaitlynmm569

指定滑块样式

  •  0
  • kaitlynmm569  · 技术社区  · 1 年前

    我目前正在尝试设计一个html滑块的样式,使其看起来类似于以下内容:

    Desired Result

    然而,我的造型不太好,滑块拇指离条的边缘太近(忽略颜色,现在不用担心):

    Current result

    我已经对如何做到这一点做了一些研究,这里的大部分造型都来自于此,但我仍然无法使其正常工作,也未能找到有效的解决方案。


    编辑:已添加代码段

    /* STUDY DAY SLIDER */
    .days {
        -webkit-appearance: none;
        width: 25%;
        height: 30px;
        border-radius: 20px;
        outline: none;
        background-color: green;
        -webkit-transition: 0.2s;
        transition: opacity 0.2s;
      }
    
      .days::-webkit-scrollbar-track {
    
      }
      
      .days::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        border: 0;
        background-color: red;
        cursor: pointer;
      }
    
      .days::-webkit-slider-thumb::before {
        content: var(--thumbContent);
        color: white;
      }
      
      .days::-moz-range-thumb {
        -webkit-appearance: none;
        width: 30px;
        height: 30px;
        border: 0;
        cursor: pointer;
      }
    <!DOCTYPE html>
    <html>
        <head>
            <link href="./example.css" rel="stylesheet" type="text/css" />
        </head>
        <body>
            <input type="range" min="1" max="100" class="topic-row-style days" id="topic-row-style">
        </body>
    </html>
    1 回复  |  直到 1 年前
        1
  •  1
  •   PsychoMx    1 年前

    试试这个 :

    我想这就是你想要做的。

    .days {
        -webkit-appearance: none;
        width: 25%;
        height: 30px;
        border-radius: 20px;
        outline: none;
        padding: 3px 8px; /* new line */
        background-color: green;
        -webkit-transition: 0.2s;
        transition: opacity 0.2s;
      }
    
      .days::-webkit-scrollbar-track {
    
      }
      
      .days::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        border: 0;
        background-color: red;
        cursor: pointer;
      }
    
      .days::-webkit-slider-thumb::before {
        content: var(--thumbContent);
        color: white;
      }
      
      .days::-moz-range-thumb {
        -webkit-appearance: none;
        width: 30px;
        height: 30px;
        border: 0;
        cursor: pointer;
      }
    <html>
        <head>
            <link href="./example.css" rel="stylesheet" type="text/css" />
        </head>
        <body>
            <input type="range" min="1" max="100" class="topic-row-style days" id="topic-row-style">
        </body>
    </html>