让一个已知宽高的div元素水平居中

<style>
#div1{
width:200px;
height:200px;
background:#F00;

margin:0 auto;
}

</style>
</head>

<body>
<div >

</div>
</body>
</html>

让一个已知宽高的div元素垂直居中

<style>

#div1{
width:300px;
height:200px;
background:#F00;
position:absolute;
top:50%;

margin-top:-100px;

}

</style>
</head>

<body>
<div >

</div>
</body>
</html>

相关文章:

  • 2021-08-10
  • 2022-12-23
  • 2022-01-16
  • 2021-10-29
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
相关资源
相似解决方案