居中是样式中常用的操作,这里简单做一下总结:
下面的是基础文件样式:
<!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> .parent { width: 200px; height: 100px; position: relative; background-color: red; } .parent .child { width: 100px; height: 50px; background-color: yellow; } </style> </head> <body> <div class="parent"> <div class="child"></div> </div> </body> </html>