【TailwindCSS】스크롤 바를 보이지 않게 한다
8245 단어 tailwindcssReactnext.js
소개
평소 개발에서 TailwindCSS를 사용하고 있지만,이 스크롤 바를 지우고 싶습니다.
CSS에서는 쉽게 구현할 수 있지만 TailwindCSS 표준으로 스크롤을 지울 수 없었습니다. . . (Tailwind라면 상당히 이런 일이 있다)
원래 코드 .tsx
const Index: React.VFC = () => {
return (
<>
<div className="flex overflow-x-auto mt-10 text-white text-xl">
<button className="p-3 bg-green-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-blue-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-green-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-blue-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-green-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-blue-400 rounded-full w-30 -mr-96">スクロール</button>
</div>
</>
)
}
export default Index
구현 방법
TailwindCSS의 구멍은 styled-component를 사용하여 구현하는 것이 좋을 것 같습니다.
먼저 command로 설치합니다.
# with yarn and TypeScript
yarn add @types/styled-components
설치가 끝나면 import하여 구현합니다.
구현한 코드.tsx
import styled from "styled-components"
const Index: React.VFC = () => {
// 追加したコード
const HiddenScrollBar = styled.div`
::-webkit-scrollbar {
display: none;
}
`
return (
<>
// divからstyled-componentに定義したCSSに変更
<HiddenScrollBar className="flex overflow-x-auto mt-10 text-white text-xl">
<button className="p-3 bg-green-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-blue-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-green-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-blue-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-green-400 rounded-full w-30">スクロール</button>
<button className="p-3 bg-blue-400 rounded-full w-30 -mr-96
">スクロール</button>
</HiddenScrollBar>
</>
)
}
export default Index
안전하게 구현할 수있었습니다
사이고에게
Tailwind처럼 styled-component의 설명이 되어 버렸습니다만, 가장 편한 방법일까라고 생각합니다.
참고 사이트
Reference
이 문제에 관하여(【TailwindCSS】스크롤 바를 보이지 않게 한다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/okamotoyu/items/d5b8be20f5a7ba897203텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)