I'm trying to recreate a horizontal scroll navbar with tailwind without a scrollbar on the bottom like this example (reduce the width of your screen to be able to scroll)
https://getbootstrap.com/docs/5.0/examples/blog/
I tried the following using Tailwind but I wasn't able to figure out how to remove the horizontal scrollbar that appears like the bootstrap example above. Could someone help?
<ul class="flex overflow-x-auto whitespace-nowrap p-4">
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
<li><a href="/" class="p-2">Nav Item</a></li>
</ul>
How to Hide the Vertical Scrollbar in CSS. To hide the vertical scrollbar and prevent vertical scrolling, use overflow-y: hidden like so: HTML.
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
Use overflow-x-scroll to allow horizontal scrolling and always show scrollbars unless always-visible scrollbars are disabled by the operating system.
Notice that 'overflow:hidden' is in the HTML file of the embedded element. Show activity on this post. Use your embed tag inside a container with overflow hidden. Then set the width of the embed with 100% + 17px (the default width of a scrollbar).
To hide the scrollbar you'll need to style it directly:
/* Hide scrollbar for Chrome, Safari and Opera */
.no-scrollbar::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.no-scrollbar {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
You could easily add these as Tailwind utilities using a plugin in your config: https://tailwindcss.com/docs/plugins#adding-utilities
Further reading:
https://css-tricks.com/almanac/properties/s/scrollbar/ https://www.w3schools.com/howto/howto_css_hide_scrollbars.asp
/*
https://github.com/tailwindlabs/tailwindcss/discussions/2394
https://github.com/tailwindlabs/tailwindcss/pull/5732
*/
@layer utilities {
/* Chrome, Safari and Opera */
.no-scrollbar::-webkit-scrollbar {
display: none;
}
.no-scrollbar {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
}
Then you just add the class no-scrollbar
as you would typically like so, notice I added overflow-y-auto to keep the scrollbar automatically the correct size too.
<div className="no-scrollbar overflow-y-auto">
ALTERNATIVELY:
You could try this tailwindcss
plugin for hide scrollbar
https://github.com/reslear/tailwind-scrollbar-hide
To answer @wataru's question in the comments, the syntax to add these classes as a plugin to tailwind.config.js
is this:
const plugin = require('tailwindcss/plugin')
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx}",
"./components/**/*.{js,ts,jsx}",
],
theme: {
extend: {},
},
plugins: [
plugin(function ({ addUtilities }) {
addUtilities({
'.scrollbar-hide': {
/* IE and Edge */
'-ms-overflow-style': 'none',
/* Firefox */
'scrollbar-width': 'none',
/* Safari and Chrome */
'&::-webkit-scrollbar': {
display: 'none'
}
}
}
)
})
],
}
The lines to inspect are the const plugin
and the plugins: []
array
I learned this by inspecting the source code of the https://github.com/reslear/tailwind-scrollbar-hide package linked by @jasonleonhard above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With