Home Web Front-end CSS Tutorial How to hide scroll bars with CSS

How to hide scroll bars with CSS

Jun 09, 2018 pm 03:33 PM

This article mainly uses three methods to share with you how to hide scroll bars in CSS. Here I recommend the second method, of course, based on the actual situation. Friends who are interested in this article should learn together

Hide scroll bars in xhtml
When using ie6 to browse a framed xhtml page, the horizontal and vertical scroll bars will appear together by default. This is ie6 A bug, which is normal on Firefox, occurs due to a flaw in its interpretation of the XHTML 1.0 transitional doctype. There are generally three solutions to this bug,
Method 1:
Code :
Program code

html { overflow-y: scroll; }
Copy after login

Principle: Force the display of IE's vertical scroll bar, while ignoring the horizontal scroll bar
Advantages: Completely solves this problem, allowing you to maintain the complete XHTML doctype.
Disadvantages: Vertical scroll bars appear even when the page does not require vertical scroll bars.
Method 2: (Recommended)
Code:
Program code

html { overflow-x: hidden; overflow-y: auto; }
Copy after login

Principle: Hide horizontal scrolling, vertical scrolling is adaptive according to the content
Advantages: This problem is solved visually. The vertical scroll bar is not forced to appear when it is not necessary.
Disadvantages: Only the horizontal scroll bar is hidden. If the page really needs the horizontal scroll bar,
content outside the screen It will not be visible because the user cannot scroll horizontally.
Method 3:
Code:
Program code

body { margin-right: -15px; margin-bottom: -15px; }
Copy after login

Principle: This will add a negative value in the horizontal and vertical directions of margin, IE adds the Once the value is accurate, the illusion of the need for scroll bars will be removed.
Advantages: This problem is solved visually. Vertical scrolling is adaptive according to the content
Disadvantages: Due to the "artificially created" 15px margin ( margin), so the filled screen area cannot be used.
---------------------------------- --
Set the style
In the original html, we can define the scroll bar of the entire page like this
Program code

body{
scrollbar-3dlight-color:#D4D0C8; /*- 最外左 -*/
scrollbar-highlight-color:#fff; /*- 左二 -*/
scrollbar-face-color:#E4E4E4; /*- 面子 -*/
scrollbar-arrow-color:#666; /*- 箭头 -*/
scrollbar-shadow-color:#808080; /*- 右二 -*/
scrollbar-darkshadow-color:#D7DCE0; /*- 右一 -*/
scrollbar-base-color:#D7DCE0; /*- 基色 -*/
scrollbar-track-color:#;/*- 滑道 -*/
}
Copy after login

But the same code will not work when we apply it to xhtml It worked. I believe many good friends have encountered the same problem
So how can I apply the scroll bar style under xhtml? Look at the following code
Program code

html{
scrollbar-3dlight-color:#D4D0C8; /*- 最外左 -*/
scrollbar-highlight-color:#fff; /*- 左二 -*/
scrollbar-face-color:#E4E4E4; /*- 面子 -*/
scrollbar-arrow-color:#666; /*- 箭头 -*/
scrollbar-shadow-color:#808080; /*- 右二 -*/
scrollbar-darkshadow-color:#D7DCE0; /*- 右一 -*/
scrollbar-base-color:#D7DCE0; /*- 基色 -*/
scrollbar-track-color:#;/*- 滑道 -*/
}
Copy after login

The only difference between this code and the previous paragraph is that in the elements defined by css, one is body and the other is html. Let's test it again and change the
"body" of the html page to "html" to test it and find that the effect can still be achieved. So why?
Literally, xhtml has one more x than html, so this x is actually xml. Why do we need to add an xml in it? In fact, the most fundamental reason is to make html more structured and standardized (because html is really bad).
What we define in html is body. Because html is not very standard, this can work, but in xhtml it does not work.
Looking at the picture, it is obvious that the body tag itself is not the root element, only HTML is the root element, and the scroll bar of the page also belongs to the root element, so this is why our definition of body has no effect, because what we define is only a child element. ok, we know the principle, let's do an experiment. If the definition "body" or "xhtml" is replaced by "*",
Program code

*{ 
scrollbar-3dlight-color:#D4D0C8; /*- 最外左 -*/
scrollbar-highlight-color:#fff; /*- 左二 -*/
scrollbar-face-color:#E4E4E4; /*- 面子 -*/
scrollbar-arrow-color:#666; /*- 箭头 -*/
scrollbar-shadow-color:#808080; /*- 右二 -*/
scrollbar-darkshadow-color:#D7DCE0; /*- 右一 -*/
scrollbar-base-color:#D7DCE0; /*- 基色 -*/
scrollbar-track-color:#;/*- 滑道 -*/
}
Copy after login

passes in both html and xhtml, because *It is to define any tag on the page, of course, including the "html" tag.

(ps: In fact, it is not so much the difference between html and xhtml as it is the difference between whether there is XHTML 1.0 transitional doctype, but if you remove the XHTML 1.0 transitional doctype from the page, then this page There is no doctype, and the default display method is html4.01, but you have to change the XHTML 1.0 transitional doctype to HTML 4.01 doctype. The same page definition body will not have any effect, although the standard of this page is html 4.01)

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

css html to implement a simple calendar

CSS3 to create rounded images and oval images

The above is the detailed content of How to hide scroll bars with CSS. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles