How to use position:sticky to perfectly solve the problem of small programs adhering to the ceiling

How to use position:sticky to perfectly solve the problem of small programs adhering to the ceiling

Recently, the client of a project insisted on having two tab menus mounted on the top. I searched for a long time online but couldn’t find a satisfactory solution. Then I saw in a blog that I could use position:sticky to solve this problem. Since I had never seen this attribute before, I searched for it, learned how to use it, wrote a small demo, and found that it is very easy to use and perfectly solves the problem without lag.

insert image description here

insert image description here

html:

<template>
	<view class="">
		<view class="">
			<view class="box">
				
			</view>
			<view class="tabbar t1">
				tabbar
			</view>
			<view class="box">
				
			</view>
			<view class="tabbar t2">
				tabbar
			</view>
			<view class="item" v-for="(item,index) in 20" :key='index' >
				{{item}}
			</view>
		</view>
	</view>
</template>

<script>
</script>

CSS:

<style>
	.box{
		height: 30vh;
		border: 1px solid #007AFF;
	}
	.tabbar{
		background: #fff;
		position: -webkit-sticky;
		position: sticky;
		background: #4CD964;
		height: 50upx;
		
	}
	.t1{
		top: -1upx;
	}
	.t2{
		top: 50upx;
	}
	.item{
		height: 100upx;
		margin-bottom: 20upx;
		background: #007AFF;
	}
</style>

Mainly
position: -webkit-sticky; position: sticky;
Also add a top value, how far from the top the ceiling is

Interested students can go to
MDN – In-depth understanding

This concludes the article on how to use position:sticky to perfectly solve the problem of small programs being stuck to the ceiling. For more relevant position:sticky small programs being stuck to the ceiling content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  Recommend a cool flashing alarm button

>>:  Sample code for modifying the input prompt text style in html

Recommend

Windows Server 2016 Quick Start Guide to Deploy Remote Desktop Services

Now 2016 server supports multi-site https service...

How to install and configure WSL on Windows

What is WSL Quoting a passage from Baidu Encyclop...

SSM implements the mysql database account password ciphertext login function

introduction Our company is engaged in the resear...

JS implements Baidu search box

This article example shares the specific code of ...

How to prevent website content from being included in search engines

Usually the goal of building a website is to have...

Detailed explanation of MySQL and Spring's autocommit

1 MySQL autocommit settings MySQL automatically c...

Nginx reverse proxy springboot jar package process analysis

The common way to deploy a springboot project to ...

How to get the maximum or minimum value of a row in sql

Original data and target data Implement SQL state...

Detailed explanation of how to write mysql not equal to null and equal to null

1. Table structure 2. Table data 3. The query tea...

A complete guide to the Docker command line (18 things you have to know)

Preface A Docker image consists of a Dockerfile a...

Solution to MySQL remote connection failure

I have encountered the problem that MySQL can con...

Build a WebRTC video chat in 5 minutes

In the previous article, I introduced the detaile...

Use ab tool to perform API stress test on the server

Table of contents 1 A brief introduction to syste...