How to remove scrollbar if user on windows - css

I have a react app and I want to remove the scrollbar if the user on a windows machine, regardless of browser being used. I tried to implement a function to get the user's OS (which works well) and then conditionally render some css using styled components but it does not seem to work (wondering if it is just an issue with my styled component?). Here is a snippet from my app component:
// getOS will pass 'win64' as a string to the OuterContainer if the user is browsing from windows
<OuterContainer os={getOS()}>
<ConnectedRouter history={history}>
<Fragment>
<Header />
<Routes />
<Footer />
</Fragment>
</ConnectedRouter>
</OuterContainer>
export const OuterContainer = styled.div`
position: relative;
display: flex;
flex-direction: column;
flex: 1;
height: 100%;
${({ os }) => os !== 'mac' &&
css`
&::-webkit-scrollbar {
display: none;
}
`
}
`;

In order to remove the scrollbar you can set a css property called overflow with value hidden.
Like this:
overflow: hidden;
Check the documentation about this property: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
To hide the scrollbars, but still be able to keep scrolling, you can use the following code:
/* Hide scrollbar for Chrome, Safari and Opera */
.example::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.example {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
Webkit browsers, such as Chrome, Safari and Opera, supports the non-standard ::-webkit-scrollbar pseudo element, which allows us to modify the look of the browser's scrollbar. IE and Edge supports the -ms-overflow-style: property, and Firefox supports the scrollbar-width property, which allows us to hide the scrollbar, but keep functionality.
Make sure which browser you are testing it, and if you keep getting error, try to set a fixed height value.

If you want to keep the scrolling functionality and just hide the scrollbar use:
/* Hide scrollbar for Chrome, Safari and Opera */
.example::-webkit-scrollbar {
width: 0px;
height: 0px;
}

Related

Make scrollbar always visible on iOS 15 doesn't work

I'm trying to make the scrollbar of a div (not the entire body) always visible, it works everywhere except on Safari & Chrome on iOS.
It looks like ::-webkit-scrollbar doesn't work on iOS.
The CSS that I've tried, that works everywhere but on iOS:
::-webkit-scrollbar {
width: 20px;
background: red;
}
Do you know any workaround to make it work? Do you know why iOS doesn't support that?
Thanks!
Try:
html,
html > * {
-moz-overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
body::-webkit-scrollbar {
width: 20px;
background: red;
}
Hope this works.

How can I disable my custom scrollbar from appearing horizontally?

I've set up my own custom scrollbar with CSS, and I'd like to know know how to only apply these settings to my vertical crossbar.
I've looked up other posts to fix this, but haven't been successful in implementing their solutions in my project.
Any fix that either removes my horizontal scrollbar completely or resets its settings to default would be greatly appreciated.
Here's my code:
::-webkit-scrollbar {
width: 20px;
}
::-webkit-scrollbar-track {
background-color: rgb(26, 23, 23);
}
::-webkit-scrollbar-thumb {
background-color: hsl(270, 2.9%, 48.7%);
border-radius: 20px;
border: 6px solid transparent;
background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
background-color: hsl(270, 2.9%, 78.7%);
}
edit: The problem seems to have been related to other pre-built styles overriding overflow-x. overflow-x: hidden !important; solved the issue.
The questioner have faced a problem that a WebKit engine won't allow him to remove customized horizontal scrollbar.
It seems that the implementation of such a removal vary from one browser to another and there's no universal way to hide scrollbars.
Using overflow: hidden will disable the scroll and that’s not what we want.
So we’ll need another way to hide the scrollbar.
Unfortunately, there is no universal CSS property that does something
like this
div {
scrollbar-visibility: hidden; /* <--- I wish we had this one !! */
}
We’ll need to implement different CSS properties for each browser.
For Firefox, we can set the scroll-bar width to none.
scrollbar-width: none; /* Firefox */
For IE, we’ll need to use -ms prefix property to define scrollbar style
-ms-overflow-style: none; /* IE 10+ */
For Chrome and Safari. We’ll have to use CSS scrollbar selector.
Then apply display: none to hide it.
::-webkit-scrollbar {
display: none; /* Chrome Safari */
}
Or you can set it’s width and height to 0.
::-webkit-scrollbar {
width: 0;
height: 0;
}
https://redstapler.co/css-hidden-scrollbar-while-scrollable-element/
Nevertheless, the following solution took effect in questioner's situation:
overflow-x: hidden !important;

CSS padding and border-radius not being applied on mobile

I have an email contact form, with a submit button, and some basic styling on the button. All of the styles work on Desktop, and most of the styles are applied on mobile, just not the padding or border-radius. I already tried switching to EM units instead of pixels. The url is http://sharperprogrammer.com/contact (not self-promoting, just thought it would help to see the full thing)
HTML:
<input type="submit">
CSS:
input[type=submit] {
background-color: #4CAF50;
color: white;
/* padding: 12px 20px; */
padding: 1.2em 2em;
border: none;
border-radius: 0.4em;
cursor: pointer;
margin: 10px;
}
I have even connected my iPhone to my Mac and opened the Safari Developer Tools, and I can check and uncheck to toggle different styles on the button, but the padding seems to do nothing. It's weird to me because the other styles like the background-color work fine, so I know everything is connected at least. Thanks for taking a look!
Edit: The style is just fine on an Android phone's Chrome browser, but the styling isn't applied correctly on my iPhone's Chrome or Safari browser. And I've cleared my browser cache just in case.
Here is a screenshot:
It looks to me like Safari / Chrome Mobile have some default button styles that are more specific than input [type=submit]. Perhaps the more specific styles don't specify background-color which is why yours is working.
I found two solutions, which I will link below, that both vouch for adding -webkit-appearance: none; as a solution.
CSS submit button weird rendering on iPad/iPhone
Why is my button style changing when on laptop and mobile
Hopefully this will work for you :)
Try to add this:
in the navbar.css file inside media query :
#media only screen and (max-width: 600px) {
.navbar{
flex-direction: column;
align-items: center;
}
}

How do I customize the cursor for scrollbar-hover in css?

I'm using tumblr. And I use the following code to change the cursor for the main body and hover on links:
body, a { cursor:url("http://i.imgur.com/2qleX.jpg"), auto}
a:hover { cursor:url("http://i.imgur.com/IepP2.jpg"), auto}
But it doesn't seem to affect the scrollbar I have added to one of the containers, which is:
overflow-y: auto;
overflow-x: hidden;
The cursor simply changes back to the default browser cursor when I hover/click the scrollbar. How do I customize the cursor for the scrollbar???
This code will customize the scrollbar
Here I'm adding a cursor image when we hover the scrollbar
This example will only work in webkit browsers like Chrome, Safari and Opera but not in Firefox or Edge/IE.
This is a non-standard way.
body::-webkit-scrollbar-thumb {
cursor:url("http://i.imgur.com/2qleX.jpg"), auto;
}
p {
/* force scrollbar */
height: 200vh;
}
<p></p>
and also you can customize the Scrollbar completely,
Use this
body::-webkit-scrollbar {
/*it will edit the scrollbar area*/
}
body::-webkit-scrollbar-track {
/*it will edit the scrollbar path*/
}
body::-webkit-scrollbar-thumb {
/*it will edit the scrollbar thumb which we use to scroll*/
}

Disable Navigation Swipe in Metro IE

I am trying to disable the navigation swiping.
I don't want the webpage to go back or forward when the user swipes left or right.
I noticed we can set the touch-action to none on the html element preventing the behavior.
However, when scrolling a child element that has some overflow, it will "chain" the scroll then will allow the back navigation.
So I thought of adding -ms-scroll-chaining: none on the html element, but it works only if the element scrolls.
So adding overflow: scroll on html actually does the trick. But now I have scrollbars showing on my other browsers.
What is the right way to do this?
html {
-ms-touch-action: none; /* Doesn't work if scrolling from child element */
-ms-scroll-chaining: none; /* Works only with the next line */
overflow: scroll; /* With this line all the other browsers have a scrollbar */
}
I used this:
#media screen and (-ms-high-contrast: none) {
// Windows 8+ IE only
html {
overflow-x: scroll;
-ms-touch-action: none;
-ms-overflow-style: none;
-ms-scroll-chaining: none;
}
}
Have you tried
body, html {
-ms-touch-action:none;
}
and for every class which can be scrolled (Y - axis) apply
-ms-scroll-chaining: none;
In my project we have special class for scrolling what is comfortable:
.scroll-y {
overflow-y: auto;
overflow-x: hidden;
-ms-scroll-chaining: none;
}
Worked for me

Resources