Sample code for implementing DIV suspension with pure CSS (fixed position)

Sample code for implementing DIV suspension with pure CSS (fixed position)

The DIV floating effect (fixed position) is implemented purely with CSS, and is compatible with commonly used browsers: IE8, 360, FireFox, Chrome, Safari, Opera, Maxthon, Sogou, The World, etc. The effect is as follows:

Implementation code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>DIV suspension example - pure CSS implementation</title>
<style type="text/css">
/*Set the height, you can scroll up and down*/
body {
height: 1800px;
background:#dddddd;
}

/*div general style*/
div{
background: #1a59b7;
color:#ffffff;
overflow: hidden;
z-index: 9999;
position: fixed;
padding:5px;
text-align:center;
width: 175px;
height: 22px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}

/*upper right corner*/
div.right_top{
right: 10px;
top: 10px;
}

/*lower right corner*/
div.right_bottom{
right: 10px;
bottom: 10px;
}

/*Middle of the screen*/
div.center_{
right: 45%;
top: 50%;
}

/*upper left corner*/
div.left_top{
left: 10px;
top: 10px;
}

/*lower left corner*/
div.left_bottom{
left: 10px;
bottom: 10px;
}
</style>
</head>
<body>
<div class="right_top"> I am the div floating in the upper right corner</div>
<div class="right_bottom"> I am the div floating in the lower right corner</div>
<div class="center_"> I am the div floating in the middle of the screen</div>
<div class="left_top"> I am the div suspended in the upper left corner</div>
<div class="left_bottom"> I am the div suspended in the lower left corner</div>
</body>
</html>

This concludes this article about sample code for implementing DIV suspension with pure CSS (fixed position). For more relevant CSS DIV suspension content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  Two ways to clear float in HTML

>>:  JavaScript destructuring assignment detailed explanation

Recommend

MySQL Router implements MySQL read-write separation

Table of contents 1. Introduction 2. Configure My...

Use of Linux ipcs command

1. Command Introduction The ipcs command is used ...

Detailed steps to install Hadoop cluster under Linux

Table of contents 1. Create a Hadoop directory in...

Mini Program to implement Token generation and verification

Table of contents process Demo Mini Program Backe...

How to build pptpd service in Alibaba Cloud Ubuntu 16.04

1. To build a PPTP VPN, you need to open port 172...

Detailed explanation of how to restore database data through MySQL binary log

Website administrators often accidentally delete ...

Create a screen recording function with JS

OBS studio is cool, but JavaScript is cooler. Now...

Implementing login page based on layui

This article example shares the specific code of ...

Mysql NULL caused the pit

Using NULL in comparison operators mysql> sele...

Vue implements an example of pulling down and scrolling to load data

Table of contents Step 1: Installation Step 2: Ci...

Detailed explanation of computed properties in Vue

Table of contents Interpolation Expressions metho...