本文主要包含div自适应屏幕大小,div自适应屏幕高度,div自适应屏幕宽度,div自适应屏幕,div屏幕居中等相关知识,佚名 希望在学习及工作中可以帮助到您
方法一:
对一个div进行以下设置即可实现居中。
</div>- <style>
- #a{
- position: fixed;
- top: 0px;
- left: 0px;
- rightright: 0px;
- bottombottom: 0px;
- margin: auto;
- }
- </style>
- <!doctype html>
- <html lang="zh-cn">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- <style>
- *{
- margin: 0px;
- padding: 0px;
- }
- #a{
- width: 200px;
- height: 200px;
- background-color: aquamarine;
- position: fixed;
- top: 0px;
- left: 0px;
- right: 0px;
- bottom: 0px;
- margin: auto;
- }
- </style>
- </head>
- <body>
- <p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p><p>123</p>
- <p>123</p><p>123</p><p>123</p><p>123</p><p>123