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

How to create users and manage permissions in MySQL

1. How to create a user and password 1. Enter the...

Basic use of subqueries in MySQL

Table of contents 1. Subquery definition 2. Subqu...

Use Vue3+Vant component to implement App search history function (sample code)

I am currently developing a new app project. This...

CentOS 7.2 builds nginx web server to deploy uniapp project

Panther started as a rookie, and I am still a roo...

About VSCode formatting JS automatically adding or removing semicolons

introduction It is okay to add or not add a semic...

HTML solves the problem of invalid table width setting

If you set the table-layer:fixed style for a tabl...

Detailed tutorial on installing mysql-8.0.20 under Linux

** Install mysql-8.0.20 under Linux ** Environmen...

The visual design path of the website should conform to user habits

Cooper talked about the user's visual path, w...

Detailed tutorial on installing VirtualBox and Ubuntu 16.04 under Windows system

1. Software Introduction VirtualBox VirtualBox is...

The difference between br and br/ in HTML

answer from stackflow: Simply <br> is suffic...

Eight rules for effective web forms

If you're collecting information from your us...

CentOS 6.4 MySQL 5.7.18 installation and configuration method graphic tutorial

The specific steps of installing mysql5.7.18 unde...

JavaScript commonly used array deduplication actual combat source code

Array deduplication is usually encountered during...