How to add margin to scrollbar without changing its default style

I created an example in which i need to add margin (top and bottom) to the scrollbar.

NOTE: I need to solve the problem without changing default style of the scrollbar.

In the example below, the arrows indicate where the scrollbar should start and end.

body {
     display: flex;
     align-items: center;
     justify-content: center;
     min-height: 100vh;
     padding: 0;
     margin: 0;
}
 .phone {
     width: 370px;
     height: 750px;
     border: 10px solid #222;
     border-radius: 80px;
     position: relative;
}
 .phone--custom-scrollbar .content::-webkit-scrollbar {
     width: 8px;
}
 .phone--custom-scrollbar .content::-webkit-scrollbar-track {
     background: #777;
     margin-top: 100px;
     margin-bottom: 80px;
}
 .phone--custom-scrollbar .content::-webkit-scrollbar-thumb {
     background: #222;
}
 .content {
     height: 100%;
     overflow-y: auto;
     border-radius: 70px;
}
 .items {
     padding: 120px 20px 100px 20px;
     display: grid;
     grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
     column-gap: 10px;
     row-gap: 20px;
}
 .item {
     height: 100px;
     background: #222;
     border-radius: 8px;
}
 .head {
     position: absolute;
     top: 0;
     left: 0;
     right: 0;
     height: 100px;
     backdrop-filter: blur(5px);
     border-radius: 70px 70px 0 0;
}
 .foot {
     position: absolute;
     bottom: 0;
     left: 0;
     right: 0;
     height: 80px;
     backdrop-filter: blur(5px);
     border-radius: 0 0 70px 70px;
}
 .button {
     position: absolute;
     background: #222;
     width: 10px;
     border: none;
     border-radius: 10px;
     outline: none;
     padding: 0;
     margin: 0;
}
 .button--action {
     top: 140px;
     left: -14px;
     height: 40px;
}
 .button--volume-up {
     top: 220px;
     left: -14px;
     height: 60px;
}
 .button--volume-down {
     top: calc(220px + 10px + 60px);
     left: -14px;
     height: 60px;
}
 .button--lock {
     top: calc(220px + 20px);
     right: -14px;
     height: 100px;
}
 .arrow {
     position: absolute;
     right: -50px;
}
 .arrow--start {
     top: 85px;
}
 .arrow--end {
     bottom: 65px;
}
 
<div class="phone">
  <div class="phone__content content">
    <div class="items">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </div>

  <div class="head"></div>
  <div class="foot"></div>

  <button type="button" class="button button--action"></button>
  <button type="button" class="button button--volume-up"></button>
  <button type="button" class="button button--volume-down"></button>
  <button type="button" class="button button--lock"></button>

  <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" class="bi bi-arrow-left-short arrow arrow--start" viewBox="0 0 16 16">
    <path fill-rule="evenodd" d="M12 8a.5.5 0 0 1-.5.5H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H11.5a.5.5 0 0 1 .5.5"/>
  </svg>

  <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" class="bi bi-arrow-left-short arrow arrow--end" viewBox="0 0 16 16">
    <path fill-rule="evenodd" d="M12 8a.5.5 0 0 1-.5.5H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H11.5a.5.5 0 0 1 .5.5"/>
  </svg>
</div>

If we add ::-webkit-scrollbar-track top margin margin-top: 100px; and bottom margin margin-bottom: 80px; then it will work only when we add width: 8px; to ::-webkit-scrollbar and some colors so that it is visible – and this changed the standard scroll bar.

Below is an example with a modified scrollbar. In this example, the scrollbar position is done correctly, but the standard style has changed

body {
     display: flex;
     align-items: center;
     justify-content: center;
     min-height: 100vh;
     padding: 0;
     margin: 0;
}
 .phone {
     width: 370px;
     height: 750px;
     border: 10px solid #222;
     border-radius: 80px;
     position: relative;
}
 .phone--custom-scrollbar .content::-webkit-scrollbar {
     width: 8px;
}
 .phone--custom-scrollbar .content::-webkit-scrollbar-track {
     background: #777;
     margin-top: 100px;
     margin-bottom: 80px;
}
 .phone--custom-scrollbar .content::-webkit-scrollbar-thumb {
     background: #222;
}
 .content {
     height: 100%;
     overflow-y: auto;
     border-radius: 70px;
}
 .items {
     padding: 120px 20px 100px 20px;
     display: grid;
     grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
     column-gap: 10px;
     row-gap: 20px;
}
 .item {
     height: 100px;
     background: #222;
     border-radius: 8px;
}
 .head {
     position: absolute;
     top: 0;
     left: 0;
     right: 0;
     height: 100px;
     backdrop-filter: blur(5px);
     border-radius: 70px 70px 0 0;
}
 .foot {
     position: absolute;
     bottom: 0;
     left: 0;
     right: 0;
     height: 80px;
     backdrop-filter: blur(5px);
     border-radius: 0 0 70px 70px;
}
 .button {
     position: absolute;
     background: #222;
     width: 10px;
     border: none;
     border-radius: 10px;
     outline: none;
     padding: 0;
     margin: 0;
}
 .button--action {
     top: 140px;
     left: -14px;
     height: 40px;
}
 .button--volume-up {
     top: 220px;
     left: -14px;
     height: 60px;
}
 .button--volume-down {
     top: calc(220px + 10px + 60px);
     left: -14px;
     height: 60px;
}
 .button--lock {
     top: calc(220px + 20px);
     right: -14px;
     height: 100px;
}
 .arrow {
     position: absolute;
     right: -50px;
}
 .arrow--start {
     top: 85px;
}
 .arrow--end {
     bottom: 65px;
}
 
<div class="phone phone--custom-scrollbar">
  <div class="phone__content content">
    <div class="items">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </div>

  <div class="head"></div>
  <div class="foot"></div>

  <button type="button" class="button button--action"></button>
  <button type="button" class="button button--volume-up"></button>
  <button type="button" class="button button--volume-down"></button>
  <button type="button" class="button button--lock"></button>

  <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" class="bi bi-arrow-left-short arrow arrow--start" viewBox="0 0 16 16">
    <path fill-rule="evenodd" d="M12 8a.5.5 0 0 1-.5.5H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H11.5a.5.5 0 0 1 .5.5"/>
  </svg>

  <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" class="bi bi-arrow-left-short arrow arrow--end" viewBox="0 0 16 16">
    <path fill-rule="evenodd" d="M12 8a.5.5 0 0 1-.5.5H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H11.5a.5.5 0 0 1 .5.5"/>
  </svg>
</div>

Most likely, this problem can be solved in another way, for example, by combining with nested blocks or something like that.

New contributor

Vitalik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật