Customizing the scroll bar hue on Safari for Lion operating system (OS X 10.7)

In Lion, the new scrollbars in Safari change color based on the background color of the body element. Is there a way to manually control whether the scrollbar is dark or light? I am aware of webkit CSS options to style the scrollbar that existed before the introduction of Lion scrollbars. However, my concern with this method is that the scrollbar no longer behaves like the authentic Lion scrollbar, which fades out after scrolling stops. Although it may be possible to achieve this effect using CSS animations and JavaScript to detect the start and end of scrolling, it would be preferable to use the real scrollbar without any workarounds.

Answer №1

For those interested, there is a way to somewhat style the scrollbar in Lion OS X 10.7, although it can be quite tedious. Although Krinkle's fix (or something similar) is probably the best option.

html {
  overflow: auto;
}

body {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0px;
  left: 0px;
  overflow-y: scroll;
  overflow-x: hidden;
}

::-webkit-scrollbar {
    width: 7px;
}

::-webkit-scrollbar-track {
  visibility: hidden; /* does not always work */
}

::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background: rgba(0,0,0,0.5);
}

::-webkit-scrollbar:window-inactive {
    visibility: hidden;
}

This code mimics Lion's default dark scrollbar as closely as possible. Check out this article for more information on customizing scrollbars in Webkit browsers: http://css-tricks.com/9130-custom-scrollbars-in-webkit/.

Answer №2

While conducting tests on Safari and Chrome, it appears that the scrollbar style is determined by the background color of the body element specifically, rather than the content underneath the scrollbar.

Therefore, if your webpage has a dark background color for the body, the scrollbar will automatically appear in a brighter, contrasting color.

For instance, consider the code snippet below:

html {
    background: white;
}
body {
    width: 50%;
    background: black;
}

This setup will result in a white colored scrollbar (due to the black body background), even though the surface the scrollbar resides on (the right side of the html element) is white, creating an almost invisible effect with a subtle grey border.

Check out the demonstration on Safari at https://codepen.io/Krinkle/full/aPZNXp.

https://i.sstatic.net/4xIan.png

Answer №3

Big shoutout to @EdwardLoveall for sharing his solution and link. Here is my take on his method to create a scrollbar with more of an iOS-style look (I'm using Lion + Chrome 19).

::-webkit-scrollbar {
    background-color: black;
    width: 1.25em /* 20px / 16px */;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.33333);
    border: 0.25em /* 4px / 16px */ solid black;
    border-radius: 1.25em /* 20px / 16px */;
}

As mentioned by him, it's tricky to hide the track completely, but you can give it a background. Transparent background doesn't work well as it extends beyond the HTML element, creating white space below it. Some properties like margin, padding, or opacity may not work; however, adding a thick border in the same color as the background gives the thumb some breathing room.

Answer №4

To achieve this effect, you need to first set the light or dark background for the html and body elements so that the scrollbar will appear in a contrasting color. After that, you can add your desired background to the wrapper element.

html,body {
    height: 100%;
    background: #000;
}
.wrap {
    height: 100%;
    background: #FFF;
}

The use of height: 100%; in the CSS rules is important for making the wrapper stretch to fill the page even when there is minimal content.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The responsive design of Bootstrap NavBar seems to be malfunctioning when viewed on an iPhone device

Having an issue in Bootstrap Studio that I can't seem to resolve. I've seen recommendations to add the following meta tag to the <head> section: meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0", bu ...

Exclusive bug discovery: figcaption mysteriously disappearing in Safari browser

Having a CSS dilemma on my personal portfolio website that has me stumped. I’ve been using the and tags to switch from an image to a caption/button upon desktop hover or mobile click. It's working smoothly on all browsers except for Safari iOS. W ...

I require the flexbox children to be arranged in a regular manner

How can we set flexbox children to default layout behaviors? Let's make them behave like the disobedient kids they are. .wrapper { This should be a row } .column { Make all heights equal display: flex; } .child { Back to regular display...wit ...

Conceal Navigation Panel while Scrolling Down, Reveal when Scrolling Up, Compatible with Chrome, Incompatible with Safari (on smartphones

I have implemented a code to hide my navbar when scrolling down and show it when scrolling up. This code works perfectly on desktop and in all browsers, including Chrome on mobile (iPhone). However, in Safari, the navbar sometimes shows, hides, and shows a ...

Creating a bespoke Bootstrap 4 Modal experience without the backdrop

I'm attempting to show a Bootstrap 4 modal without a backdrop. I've tried the following code with no success: .modal.right. modal-backdrop.show { background-color: transparent !important; } When I try this modification, it works (but affect ...

Switching downlink to top link when scrolling downwards

I have a downward scrolling link on my homepage that moves the page down when clicked by the user. However, I am struggling to make it change to a "back to top" link as soon as the user scrolls 10 pixels from the top. Additionally, I am having trouble with ...

Safari browser cutting off POST parameters prematurely

I am encountering an issue where my code works perfectly on all browsers except Safari 6.1.2 on Mac OS Lion. Below is the AJAX post code that I am using - $.ajax({ type: 'POST', dataType: 'text/html', url:"/MyProxy.php ...

Enhancing text visibility in dompdf by making it bold or increasing its size

Recently, I began using dompdf v0.6.0beta3 along with the dompdf Codeigniter helper in Codeigniter. To address the issue of missing fonts, I manually moved the Arial font family tff files from the Windows 7 font folder to the /lib/fonts directory within do ...

The screen is cloaked in a dark veil, rendering it completely inaccessible with no clickable

Utilizing Bootstraps modals, here is my current layout. Within the site's header, there exists a "settings" button that triggers a modal containing various options. These options are not tied to the question at hand. The button responsible for displ ...

Issue encountered: The CSS provided is not valid as it is expecting a selector or at-rule after "body", but instead found "{". This error is located on line 4 of the code

As I was working on my code in style.scss, I encountered an error message from my Sass compiler (Koala) while trying to include the following code: body {margin-top:105px;} Here's the specific error snippet from style.scss: Error: Invalid CSS after ...

Is it possible to prevent the fade out of the image when hovering over the text after hovering over the div or image, causing the text to fade in?

Using React and CSS. I have set up my application to display a faded image on hover, with text that fades in over it. However, I am facing an issue where touching the text with my cursor removes the fade effect. Does anyone have a solution for preventing ...

The slider class in the div is not showing the image, but it is visible in the elements

Is the sequence of loading .css and .js files in the head section important for displaying images with the .slider class on MaterializeCSS? <!DOCTYPE html> <html> <head> <!--Import Google Icon Font--> <link href="htt ...

Step-by-step guide on replicating a website along with its CSS styles and scripts

I've been exploring the idea of cloning a webpage, such as Instagram's login page, along with its CSS elements and JavaScript, to use locally. Basically, I want to duplicate the login page and host it on my test server in a way that allows it to ...

When I click on the icon, I wish for it to revert back to its original state by spinning

Is there a way to revert the icons back to their original state when clicked again, without losing any of the current functionalities? When an icon is clicked for the first time, it rotates 180 degrees. The icon rotates back if another icon is clicke ...

Guide on altering a Tailwind Class depending on the React State or Props

Currently, I am working on a Progress Bar Component and utilizing the following versions: "next": "13.4.4", "react": "18.2.0", "react-dom": "18.2.0", "classnames": "^2.3.2", I ...

Surround Content with Rotated Container

I'm trying to achieve a unique layout where the heading is rotated with CSS transform rotation, and I want the body text to flow around the rotated text. The issue I'm facing is that when I apply float: left to the heading, the text wraps around ...

The Bootstrap modal is not properly clearing all attribute properties when it is hidden

Alrighty, so I've got this modal set up: <div id="modal-container" class="modal fade" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content center-block" style="displ ...

Trouble with CSS animation when incorporating JavaScript variables from a PHP array

Whenever I use a script to fetch an array of objects from PHP... I successfully display the results on my website by outputting them into Divs. The challenge arises when I introduce CSS animations. The animation only triggers if the variable length excee ...

"Create a sleek slider with a modern Apple store aesthetic using Javascript

While I am willing to put in some effort, I am a bit lost at the moment. I am attempting to create a slider similar to the one featured on the home section of the Apple website. How can I enable a click on an image to navigate through slides? Alternatively ...

Switch videos within the video tag as you scroll

I am trying to implement a video tag within a div element on my website. Here is the current code: <div class="phone" align="center"> <div class="phone-inner"> <video width="100%" height="100%" autoplay="" loop="" muted id="phonevideo ...