Fixed a bug caused by scrollbar occupying space

Fixed a bug caused by scrollbar occupying space

background

This bug was caused by滾動條占據空間. I checked some information and finally solved it. By the way, I studied this property, made a summary, and shared it with you.

text

Yesterday, a tester raised a problem. The phenomenon was that聚焦提示偏了. Let me fix it, as shown below:

At first I thought the red box was in the wrong position, so I looked for the code:

<Input
  // ...
  onFocus={() => setFocusedInputName('guidePrice')}
  onBlur={() => setFocusedInputName('')}
/>

<Table
  data-focused-column={focusedInputName}
  // ...
/>

There is nothing wrong with the code, it is not set manually, and it works OK on mine, another colleague, and the PM's PC:

The initial judgment is that there is a difference in the red box position settlement, the difference is about 17px, but how did this difference come about?

I went to the tester's PC and noticed a detail. On my PC, the scroll bar was suspended:

On his PC, the scroll bar takes up space:

On his computer, he manually changed the original overscroll-y: scroll overscroll-y: overlay the problem was solved.

Therefore, it is determined that the bug is caused by滾動條占據空間.

overscroll-y: overlay

The overflow CSS property defines what to do when the content of an element is too large to fit in a block formatting context. It is a shorthand property for overflow-x and overflow-y.

/* default value. The content will not be trimmed and will be rendered outside the element box*/
overflow: visible;

/* The content will be trimmed and the rest of the content will not be visible */
overflow: hidden;

/* The content will be trimmed and the browser will display a scroll bar to view the remaining content */
overflow: scroll;

/* Determined by the browser, if the content is clipped, a scroll bar will be shown */
overflow:auto;

/* Specifies that the overflow attribute value is inherited from the parent element*/
overflow: inherit;

Official description:

overlay behaves the same as auto , but the scrollbars are drawn on top of the content instead of taking up space. Only supported in WebKit-based (e.g., Safari ) and Blink-based (e.g., Chrome or Opera ) browsers.

Performance:

html {
  overflow-y: overlay;
}

compatibility

I did not find compatibility for this property on caniuse, and someone also raised this question:

Problem scenarios and solutions

1. Scrollbar of the outer container

The external container here refers to HTML, which is added directly to the outermost layer:

html {
  overflow-y: scroll;
}

By adding this feature manually, there is always scroll width space occupied.

Disadvantages: There is a scroll bar even when there is no scrolling, which is not very beautiful.

Advantages: Convenient, no compatibility issues.

2. External container absolute positioning method

Using absolute positioning ensures that the width of the body always maintains the full space:

html {
  overflow-y: scroll; // compatible with ie8, not support: root, vw
}

:root {
  overflow-y: auto;
  overflow-x:hidden;
}

:root body {
  position: absolute;
}

body {
  width: 100vw;
  overflow: hidden;
}

3. Internal container compatibility

.wrapper {
    overflow-y: scroll; // fallback
    overflow-y: overlay;
}

Summarize

My personal recommendation is to use overlay , and then use scroll as a backup.

That’s all the content. I hope it can be inspiring to you.

If there are any errors in the article, please point them out in the comment section, thank you.

References

https://developer.mozilla.org/zh-CN/docs/Web/CSS/overflow

https://github.com/Fyrd/caniuse/issues/4027

This is the end of this article about fixing a bug caused by the scrollbar occupying space. For more information about bugs caused by the scrollbar occupying space, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  A brief discussion on MySQL select optimization solution

>>:  Web Design Experience: 5 Excellent Web Design Concepts Full Analysis (Pictures)

Recommend

Detailed example of removing duplicate data in MySQL

Detailed example of removing duplicate data in My...

Solution for Docker Swarm external verification load balancing not taking effect

Problem Description I created three virtual machi...

How to store text and pictures in MySQL

Large Text Data Types in Oracle Clob long text ty...

Modularity in Node.js, npm package manager explained

Table of contents The basic concept of modularity...

Angular Dependency Injection Explained

Table of contents Overview 1. Dependency Injectio...

How to align text boxes in multiple forms in HTML

The form code is as shown in the figure. The styl...

Vue.js implements timeline function

This article shares the specific code of Vue.js t...

The implementation of Youda's new petite-vue

Table of contents Preface Introduction Live Easy ...

In IIS 7.5, HTML supports the include function like SHTML (add module mapping)

When I first started, I found a lot of errors. In...

Example of Html shielding right-click menu and left-click typing function

Disable right-click menu <body oncontextmenu=s...

JS implements dragging the progress bar to change the transparency of elements

What I want to share today is to use native JS to...

Install Windows Server 2019 on VMware Workstation (Graphic Tutorial)

If prompted to enter a key, select [I don’t have ...

Why is the MySQL auto-increment primary key not continuous?

Table of contents 1. Introduction 2. Self-increme...

CSS float property diagram float property details

Using the CSS float property correctly can become...