CSS 居中
transform
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> #parent { width: 500px; height: 500px; background: lightgray; position: relative; } #child { background: white; width: 250px; height: 250px; position: absolute; top: 50%; transform: translate(50%, -50%); } </style> </head> <body> <div id="parent"> <div id="child"></div> </div> </body> </html>
felx
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> #parent { width: 500px; height: 500px; background: lightgray; display: flex; align-items: center; justify-content: center; } #child { background: white; width: 250px; height: 250px; } </style> </head> <body> <div id="parent"> <div id="child"></div> </div> </body> </html>
相关推荐
多读书读好书 2020-11-03
drdrsky 2020-06-16
gufudhn 2020-06-12
aSuncat 2020-06-11
PioneerFan 2020-06-10
沈宫新 2020-05-04
swiftwwj 2020-03-28
HSdiana 2020-03-28
葉無聞 2020-03-23
lyg0 2020-03-07
nercon 2020-02-22
STPace 2020-02-17
STPace 2019-12-30
冰蝶 2020-01-10
玫瑰小妖 2019-12-31
爱好HtmlCssJs 2019-12-31
行吟阁 2019-12-08