12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box1{
- width: 100px;
- height: 100px;
- background-color: red;
- margin-bottom: 10px;
- }
- .box2{
- width: 100px;
- margin-bottom: 10px;
- }
- .box2::after{
- content: "";
- display: block;
- /* padding 百分比 相较于 父元素宽度 */
- padding-top: 100%;
- background-color: red;
- }
- .box3{
- width: 100px;
- height: 100px;
- position: relative;
- }
- .box3::after{
- content: "";
- display: block;
- position: absolute;
- top:0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: red;
- }
- </style>
- </head>
- <body>
- <div class="box1"></div>
- <div class="box2"></div>
- <div class="box3"></div>
- </body>
- </html>
|