Home > Web Front-end > Front-end Q&A > scroll bar hidden css

scroll bar hidden css

WBOY
Release: 2023-05-29 09:47:37
Original
11551 people have browsed it

In the process of making web pages, scroll bars are an inevitable design element. However, sometimes the appearance of scroll bars breaks the design of the entire page. In this case, we need to use some tricks to hide the scroll bars.

CSS provides a variety of methods to hide scroll bars, we will introduce them one by one below.

1. Use the overflow attribute

In CSS, we can use the overflow attribute to control whether the content of an element should overflow its container. When the overflow attribute is set to hidden, the element content will be clipped, which can achieve the effect of hiding the scroll bar. The following is the sample code:

body{
  overflow: hidden;
}
Copy after login

The above code will hide the scroll bar of the entire page. If you only want to hide the scroll bar of a certain element, you can find the CSS selector of the element and set the overflow attribute in it. Set to hidden.

#container{
  overflow: hidden;
}
Copy after login

2. Use Webkit styles

Webkit is a CSS engine that supports most modern browsers, including Chrome and Safari. Here are some ways to hide the scrollbar using Webkit styles:

  1. Hide the vertical scrollbar:
::-webkit-scrollbar{
  width: 0px;
}
Copy after login

The above code will hide the vertical scrollbar as it is by default The width of the vertical scrollbar is 17px.

  1. Hide the horizontal scroll bar:
::-webkit-scrollbar{
  height: 0px;
}
Copy after login

Similarly, the above code will hide the horizontal scroll bar because the height of the horizontal scroll bar is also 17px by default.

  1. Hide all scroll bars:
::-webkit-scrollbar{
  display: none;
}
Copy after login

The above code will completely hide all scroll bars.

3. Use jQuery

If you use jQuery, you can also use it to hide the scroll bar. Here are some ways to hide scroll bars using jQuery:

  1. Hide vertical scroll bar:
$(document).ready(function(){
  $('body').css('overflow-y', 'hidden');
});
Copy after login

After using the above code, the vertical scroll bar in the page will be hide.

  1. Hide the horizontal scroll bar:
$(document).ready(function(){
  $('body').css('overflow-x', 'hidden');
});
Copy after login

The above code will hide the horizontal scroll bar.

4. Using JavaScript

If you want to use native JavaScript to hide the scroll bar, here are some methods you can use:

  1. Hide the vertical scroll bar:
document.getElementsByTagName("body")[0].style.overflowY = "hidden";
Copy after login

The above code will hide the vertical scrollbar.

  1. Hide the horizontal scroll bar:
document.getElementsByTagName("body")[0].style.overflowX = "hidden";
Copy after login

The above code will hide the horizontal scroll bar.

To sum up, the above are some common methods to hide scroll bars. Depending on your needs, you can choose one or more of these methods. However, it should be noted that hiding the scroll bar will affect the user experience, so trade-offs and simulation tests are required in actual use.

The above is the detailed content of scroll bar hidden css. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template