Open OPY-bbt opened 4 years ago
绝对定位或者固定定位时,一定要设置两个方向的值(top,left)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> html, body { margin: 0; padding: 0; } .outer { position: fixed; top: 0; bottom: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: center; } .inner { width: 90%; height: 30%; top: 15%; left: 5%; // 如果不设置left, iOS10.3中会不居中(inner div的左侧在中央) position: absolute; background-color: red; } </style> </head> <body> <div class="outer"> <div class="inner"></div> </div> </body> </html>
绝对定位或者固定定位时,一定要设置两个方向的值(top,left)