-
Notifications
You must be signed in to change notification settings - Fork 707
Добавляет доку про псевдоэлемент ::-webkit-scrollbar
#6015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DrakesBot12
wants to merge
7
commits into
doka-guide:main
Choose a base branch
from
DrakesBot12:css/scrollbar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d92bfe
docs: webkit-scrollbar
DrakesBot12 06339c7
правки
DrakesBot12 7d5fa1b
Делаем доку лучше :^
DrakesBot12 ab35523
Merge branch 'main' into css/scrollbar
DrakesBot12 ce0a13e
Merge branch 'main' into css/scrollbar
DrakesBot12 48b9fea
Merge branch 'main' into css/scrollbar
DrakesBot12 baea7e3
правка
DrakesBot12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ groups: | |
| - selection | ||
| - marker | ||
| - backdrop | ||
| - scrollbar | ||
| - details-content | ||
| - cue | ||
| - file-selector-button | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="ru"> | ||
| <head> | ||
| <title>Базовый пример — ::-webkit-scrollbar — Дока</title> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <link rel="preconnect" href="https://fonts.googleapis.com"> | ||
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
| <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap"> | ||
| <style> | ||
| *, *::before, *::after { | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| html { | ||
| color-scheme: dark; | ||
| } | ||
|
|
||
| body { | ||
| min-height: 100vh; | ||
| padding: 50px; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| background-color: #18191C; | ||
| color: #FFFFFF; | ||
| font-family: "Roboto", sans-serif; | ||
| } | ||
|
|
||
| @media (max-width: 768px) { | ||
| body { | ||
| padding: 30px; | ||
| } | ||
| } | ||
|
|
||
| .scrollbox { | ||
| max-width: 400px; | ||
| max-height: 180px; | ||
| width: 100%; | ||
| overflow: auto; | ||
| padding: 16px; | ||
| background: #111216; | ||
| color: #fff; | ||
| border-radius: 12px; | ||
| font-size: 1.1rem; | ||
| line-height: 1.6; | ||
| box-shadow: 0 2px 16px 0 #0004; | ||
| } | ||
|
|
||
| .scrollbox::-webkit-scrollbar { | ||
| width: 12px; | ||
| height: 12px; | ||
| } | ||
|
|
||
| .scrollbox::-webkit-scrollbar-track { | ||
| background: #1e1f22; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| .scrollbox::-webkit-scrollbar-thumb { | ||
| background: #6b7280; | ||
| border-radius: 8px; | ||
| border: 3px solid #1e1f22; | ||
| min-height: 24px; | ||
| } | ||
|
|
||
| .scrollbox::-webkit-scrollbar-thumb:hover { | ||
| background: #9ca3af; | ||
| } | ||
|
|
||
| .supports-notification-container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| align-items: center; | ||
| position: fixed; | ||
| inset: 0; | ||
| backdrop-filter: blur(5px); | ||
| background-color: rgba(0, 0, 0, 0.7); | ||
| padding: 30px; | ||
| z-index: 1000; | ||
| } | ||
|
|
||
| .supports-notification { | ||
| max-width: 500px; | ||
| padding: 30px; | ||
| background-color: #2c2e33; | ||
| border-radius: 12px; | ||
| text-align: center; | ||
| color: #ffffff; | ||
| } | ||
|
|
||
| .supports-notification h3 { | ||
| margin: 0 0 15px; | ||
| font-weight: 500; | ||
| } | ||
|
|
||
| .supports-notification a { | ||
| color: #2E9AFF; | ||
| } | ||
|
|
||
| @supports selector(::-webkit-scrollbar) { | ||
| .supports-notification-container { | ||
| display: none; | ||
| } | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="scrollbox"> | ||
| <p> | ||
| Очень длинный контент, чтобы появилась полоса прокрутки.<br> | ||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, urna eu tincidunt consectetur, nisi nisl aliquam nunc, eget aliquam massa nisl quis neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. <br> | ||
| <br> | ||
| Ещё немного текста для вертикального скролла.<br> | ||
| Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br> | ||
| <br> | ||
| Добавим горизонтальный скролл:<br> | ||
| <span style="display:inline-block; min-width:600px;"> | ||
| Это очень длинная строка, которая не помещается по ширине контейнера и заставляет появиться горизонтальный скролл → | ||
| </span> | ||
| </p> | ||
| </div> | ||
| <div class="supports-notification-container"> | ||
| <div class="supports-notification"> | ||
| <h3>Ваш браузер не поддерживает ::-webkit-scrollbar 😢</h3> | ||
| <p> | ||
| Откройте демо в браузере с <a href="https://caniuse.com/mdn-css_selectors_-webkit-scrollbar">поддержкой</a> этого псевдоэлемента. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| --- | ||
| title: "`::-webkit-scrollbar`" | ||
| description: "Нестандартные псевдоэлементы для стилизации полосы прокрутки в движках WebKit/Blink. Позволяют изменять трек, ползунок и другие части скроллбара." | ||
| authors: | ||
| - drakesbot12 | ||
| related: | ||
| - css/overflow | ||
| - css/scrollbar-color | ||
| - css/pseudoelements | ||
| keywords: | ||
| - скроллбар | ||
| - scrollbar | ||
| - прокрутка | ||
| - полоса | ||
| - прокрутки | ||
| - webkit | ||
| - blink | ||
| tags: | ||
| - doka | ||
| --- | ||
|
|
||
| ## Кратко | ||
|
|
||
| `::-webkit-scrollbar` и родственные ему псевдоэлементы — это нестандартный способ стилизовать полосу прокрутки в браузерах на движках WebKit/Blink (Chrome, Edge, Safari, Opera). Можно менять толщину, цвета, скругления и состояния отдельных частей скроллбара. Спецификации у этих селекторов нет, поведение и поддержка могут меняться. | ||
|
|
||
| ## Пример | ||
|
|
||
| ```css | ||
| /* Общая ширина скроллбара */ | ||
| *::-webkit-scrollbar { | ||
| width: 12px; /* вертикальный */ | ||
| height: 12px; /* горизонтальный */ | ||
| } | ||
|
|
||
| /* Трек (фон) */ | ||
| *::-webkit-scrollbar-track { | ||
| background: #1e1f22; | ||
| } | ||
|
|
||
| /* Ползунок */ | ||
| *::-webkit-scrollbar-thumb { | ||
| background: #6b7280; | ||
| border-radius: 8px; | ||
| border: 3px solid #1e1f22; /* создаём «внутренний отступ» */ | ||
| } | ||
|
|
||
| /* Состояние при наведении */ | ||
| *::-webkit-scrollbar-thumb:hover { | ||
| background: #9ca3af; | ||
| } | ||
| ``` | ||
|
|
||
| ```html | ||
| <div class="scrollbox"> | ||
| Очень длинный контент... Очень длинный контент... Очень длинный контент... | ||
| </div> | ||
| ``` | ||
|
|
||
| ```css | ||
| .scrollbox { | ||
| max-height: 180px; | ||
| overflow: auto; | ||
| padding: 12px; | ||
| background: #111216; | ||
| color: #fff; | ||
| border-radius: 12px; | ||
| } | ||
| ``` | ||
|
|
||
| <iframe title="Пример с несколькими разными скроллбарами" src="demos/basic/" height="400"></iframe> | ||
|
|
||
| ## Как пишется | ||
|
|
||
| Семейство нестандартных псевдоэлементов: | ||
|
|
||
| - `::-webkit-scrollbar` — вся полоса прокрутки (задаёт размеры); | ||
| - `::-webkit-scrollbar-thumb` — ползунок; | ||
| - `::-webkit-scrollbar-track` — трек (фон); | ||
| - `::-webkit-scrollbar-track-piece` — участок трека, не занятый ползунком; | ||
| - `::-webkit-scrollbar-button` — кнопки со стрелками; | ||
| - `::-webkit-scrollbar-corner` — уголок при одновременных осях; | ||
| - `::-webkit-resizer` — «хваталка» для изменения размера в углу. | ||
|
|
||
| Используются как обычные псевдоэлементы: | ||
|
|
||
| ```css | ||
| .container::-webkit-scrollbar-thumb { background: #888; } | ||
| ``` | ||
|
|
||
| ## Как понять | ||
|
|
||
| - Это WebKit/Blink‑специфика. В Firefox эти селекторы не работают. Для Firefox есть стандартные свойства [`scrollbar-width`](/css/scrollbar-width/) и [`scrollbar-color`](/css/scrollbar-color/). | ||
| - Рендер и доступные свойства могут отличаться между браузерами и версиями. Считайте это «best‑effort» API без гарантий стабильности. | ||
|
|
||
| ## Подсказки | ||
|
|
||
| 💡 Избегайте слишком толстых/ярких скроллбаров — они могут мешать контенту. | ||
| 💡 Чтобы создать «зазор» внутри ползунка, используйте [`border`](/css/border/) цвета трека. | ||
| 💡 Проверьте тёмную/светлую темы и контрастность, особенно у `thumb` и `track`. | ||
| 💡 Для достижения наилучшей кроссбраузерности и контроля над стилями: | ||
|
|
||
| - Стандартные свойства ([`scrollbar-width`](/css/scrollbar-width/), [`scrollbar-color`](/css/scrollbar-color/)) работают во всех современных браузерах (Chrome 121+, Edge 121+, Firefox 64+, Safari 18.2+) и должны использоваться как основной способ стилизации; | ||
| - Для более тонкой настройки (скругления, цвета фона трека и точная ширина), которые не доступны через стандартные свойства, используйте семейство `::-webkit-scrollbar`; | ||
| - Важно! В браузерах на основе Chromium (Chrome, Edge) стандартные свойства имеют приоритет. Чтобы ваши стили на основе `::-webkit-scrollbar` гарантированно применялись, убедитесь, что вы не задали конфликтующие значения для [`scrollbar-width`](/css/scrollbar-width/) и [`scrollbar-color`](/css/scrollbar-color/) в том же блоке правил. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.