Ways to conceal scrollbar when it is not in use

Typically, the scrollbar is visible only when scrolling through a page and then disappears immediately after.

I attempted to modify the default scrollbar properties using basic CSS. While this made the scrollbar always visible, adding "overflow-y: auto" did not effectively hide it when not in use.

Could someone adjust the CSS code to resolve this issue?


/* width */
::-webkit-scrollbar {
    width: 5px;
}

/* button */
::-webkit-scrollbar-button {
    background: #222; 
}

/* Handle */
::-webkit-scrollbar-thumb {
    background: blue; 
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
    background: #666; 
}

/* Track */
::-webkit-scrollbar-track {
    background: #000; 
}

/* The track NOT covered by the handle.
::-webkit-scrollbar-track-piece {
    background: #000; 
}

/* Corner */
::-webkit-scrollbar-corner {
    background: #999; 
}

/* Resizer */
::-webkit-resizer {
    background: #111; 
}

HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pellentesque eget enim non fringilla. Nullam sit amet lectus a augue bibendum volutpat. Vivamus massa nibh, placerat eu urna vel, auctor vestibulum velit. Vestibulum et purus a nisi accumsan luctus vel et eros. Nam eu dignissim ligula, sit amet volutpat lacus. Vivamus in massa semper, dapibus arcu a, malesuada dui. Praesent tristique rhoncus metus, non consectetur neque congue at. Etiam varius, lectus quis ultrices laoreet, mauris metus vehicula nisi, ut fringilla metus mi at dolor. Nunc nec congue nisi.

Aliquam ornare aliquet consequat. Donec in luctus dui. Nulla est velit, finibus quis interdum in, tristique auctor est. Fusce aliquet ullamcorper nisi eget interdum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce porttitor sapien quis velit rhoncus varius. Integer egestas at neque nec egestas.

Duis semper lacinia mi non facilisis. Suspendisse varius mauris eu risus tempus tempus. Ut nec auctor lacus. Vivamus urna nulla, accumsan a arcu a, commodo dapibus tortor. Ut viverra enim vel arcu eleifend mollis. Sed aliquam egestas neque ac feugiat. Sed porta imperdiet erat, vel mattis nunc malesuada non. Maecenas consectetur metus sit amet est rhoncus, quis aliquet urna blandit. Donec imperdiet pretium nibh, a pellentesque diam volutpat ac. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis nunc risus, porta vel tincidunt nec, gravida at magna. Vestibulum luctus quam id metus pretium blandit. Nulla tellus ligula, venenatis id tellus quis, iaculis elementum enim. Proin sodales orci felis, tempor lobortis turpis lobortis auctor. Nam at rhoncus eros.

Quisque eget urna ac quam dapibus pharetra id id augue. Duis aliquam, lacus nec sagittis ultrices, massa nulla volutpat leo, eu fermentum lorem lectus et nisl. Duis sed finibus odio. Vivamus ullamcorper mauris vel lectus pellentesque, vel interdum odio fermentum. Aliquam quis varius orci. Vestibulum at tempor nulla. Quisque eleifend tortor elit, at pellentesque tortor volutpat vitae. Aenean sed diam non elit eleifend sodales ac quis sem. Cras vel pharetra urna. Nunc et convallis nulla, finibus feugiat ipsum. Etiam mattis nulla neque, eu rutrum metus mollis vel.

Aenean nec metus lorem. Sed non sollicitudin lacus. Donec vitae dui vulputate, venenatis nulla at, posuere quam. In hac habitasse platea dictumst. Nullam interdum arcu risus, sit amet tincidunt dui consequat vitae. Cras at erat vel purus imperdiet ornare. Curabitur ultricies vel metus sed dapibus. Etiam vitae feugiat risus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Maecenas eu est commodo, luctus sapien hendrerit, dictum sem. Curabitur rhoncus egestas feugiat. Donec auctor scelerisque nibh at efficitur. Pellentesque euismod interdum sodales.
</p>
</body>
</html>

Answer №1

Give this a shot.

    body {
    overflow: -webkit-scrollbars-vertical; 
    overflow-y: auto;
}

Answer №2

If you want to achieve this effect, place the P tag inside the div element like so:

 div {
  height: 100px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

div:hover {
  overflow-y: scroll;
} 

This will make the content visible when hovering over it.

 <div>
    <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit...
    </p>
</div>

I hope this answers your question correctly. Let me know if you need any further assistance.

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

Troubleshooting Hover Problem with D3 Chord Example on Internet Explorer 11

I came across an interesting tutorial on how to create chord diagrams in D3, which I'm currently experimenting with. The tutorial can be found at One example that caught my attention is about hair color preferences. When you hover over a group on the ...

Align a flex item in the center horizontally, even when neighboring items are different sizes

In a section element, I have 3 divs inside, and I am trying to horizontally center 'div 2'. The issue I am facing is that the adjacent divs are not the same size, so using "justify-content:center" is not effective. I came across a solution here ...

Revive the design of a website

As I work on creating my own homepage, I came across someone else's page that I really liked. I decided to download the page source and open it locally in my browser. However, I noticed that while the contents were all there, the style (frames, positi ...

Is it possible to set a single variable value for multiple attributes simultaneously in Javascript?

I would like to specify the horizontal padding of a styled element as variable 'x' and the vertical padding as variable 'y'. Here's one way to achieve this: var docex = document.getElementById.style; docex.paddingTop = y; docex.pa ...

Why does my CSS attribute selector fail to update when the property's value changes?

Context: I'm working on a React-based web app that utilizes traditional CSS loaded through an import statement. In order to create a slider functionality, I have applied a CSS selector on the tab index attribute. Challenge: The issue I am facing is t ...

Clicking on a link initiates the dropdown menu for selecting an option

This project is specifically designed for mobile use, so there's no need to worry about how it will appear on desktop screens. In this project, I have an "a href" with an icon next to it that simulates a button. When a user clicks on it, a dropdown me ...

Is there a CSS alternative to using <br clear=all> on divs that do not have set heights?

Back in the day, I used to rely on <br clear=all> at the end of a div, without specifying a height value in CSS, just to control its height. These divs would expand and contract based on the content within. Is there a more elegant approach to make ...

Twitter Bootstrap 3 - Change column order for extra small screens

My Twitter Bootstrap layout consists of two columns structured like this: <div class="col-md-4 col-sm-6 col-xs-12"> <div class="post"> Content here </div> </div> <div class="col-md-8 col-sm-6 col-xs-12"> <di ...

Issues arise with Bootstrap's navbar dropdown menus, rendering them inoper

Currently I am developing a bootstrap website using the "Butterfly" template. Everything is functioning properly except for the navbar when viewed on mobile devices. The dropdown menu fails to open on mobile devices, and I suspect it might be related to th ...

Creating a tailored React component for a dynamic table with varying column and row sizes

I'm attempting to convert this into a React component for integration on my website: https://i.sstatic.net/MUwE3.png Figuring out the process of creating this, and if there are any libraries required is currently unknown to me. ...

What makes CSS so intricate and challenging to navigate?

While going through a CSS tutorial, I encountered this detailed definition: .content div { -moz-box-shadow:inset 0px 1px 0px 0px #ffffff; -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff; box-shadow:inset 0px 1px 0px 0px #ffffff; backgroun ...

Creating a customizable theme for a website built with Bootstrap, incorporating changes to brand colors and more, by utilizing a .less file

I have built my asp site using bootstrap as the client-side CSS framework. I am currently working on implementing a feature that allows users to customize their site's brand color and other aspects, with these changes being saved permanently. While I ...

Guide to automatically adjust child div width to match parent container dimensions

I need assistance with structuring my HTML page, which consists of header, main, and footer sections. Below is the HTML and CSS code I'm utilizing: HTML code : <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

Tips for keeping the "BUTTON LINK" navbar item from wrapping on your website

Having trouble with the navigation bar on smaller screens. The "BUTTON LINK" is wrapping under the BRAND NAME toggle. How can I fix this? Here is the HTML code: bmenu test <nav class="navbar navbar-expand-md fixed-top navbar-dark" style="background ...

Adjust the top spacing in relation to the paragraph tag using jQuery

I wish to create multiple div elements with nested p tags that are initially hidden. Upon hovering over each div, I want the corresponding p tag to move up by the negative value of its own height. For instance: The first p tag has a height of 60px and a m ...

Is there a way to configure the text box to allow for range values input?

Is there a way to create an input box that only accepts values between 20 and 40? I want to restrict single numbers within that range. How can I define the range for this specific input box? If anyone can help me achieve this, it would be greatly apprecia ...

Safari Glitch in Bootstrap 4

For a simplified version, you can check it out here: https://jsfiddle.net/dkmsuhL3/ <html xmlns="http://www.w3.org/1999/xhtml"> <title>Testing Bootstrap Bug</title> <!-- Bootstrap V4 --> <link rel="stylesheet" href="https://m ...

The textboxes are not displaying the floating numbers correctly

My issue involves 3 textareas with numbers displayed next to them. While I previously used a CSS table layout, it became inefficient when adding content between each row. I am puzzled as to why the second number, "2)", appears positioned next to the first ...

Include a triangle shape at the top of a div container that has a background image using CSS

Struggling to add a point or triangle shape to my div with a background image, finding it difficult to create enough open space. This is the desired outcome: https://i.sstatic.net/LZVaF.png This is what I have implemented so far: <div class="bg"> ...

Adjusting the bottom property to a negative value in CSS will stretch the page downwards

I want to hide a portion of an HTML element at the bottom of the page and then reveal the entire element by sliding it upwards upon clicking with the help of CSS3 transitions. The expected behavior is for the part of the element extending below the page t ...