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

11 Reasons Why Bootstrap Is So Popular

Preface Bootstrap, the most popular front-end dev...

Mysql uses stored procedures to quickly add millions of data sample code

Preface In order to reflect the difference betwee...

Example of stars for CSS rating effect

What? What star coat? Well, let’s look at the pic...

A Brief Analysis of Patroni in Docker Containers

Table of contents Create an image File Structure ...

Docker installation and configuration command code examples

Docker installation Install dependency packages s...

Implementation of fuzzy query like%% in MySQL

1, %: represents any 0 or more characters. It can...

How to use docker to deploy spring boot and connect to skywalking

Table of contents 1. Overview 1. Introduction to ...

The complete version of the common Linux tool vi/vim

Why learn vim Linux has a large number of configu...

CSS to achieve floating customer service effect

<div class="sideBar"> <div>...

Node+Express test server performance

Table of contents 1 Test Environment 1.1 Server H...

Improvement experience and sharing of 163 mailbox login box interactive design

I saw in the LOFTER competition that it was mentio...

JavaScript canvas implements graphics and text with shadows

Use canvas to create graphics and text with shado...

Solution to EF (Entity Framework) inserting or updating data errors

Error message: Store update, insert, or delete st...

Teach you how to use vscode to build a react-native development environment

question The code has no prompt: Many non-front-e...

HTML tutorial, easy to learn HTML language

1. <body background=image file name bgcolor=co...