<!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>
div{
background-color: aqua;/*背景颜色*/
width: 100px;/*div宽度*/
height: 100px;/*div高度*/
position: absolute;/*绝对布局*/
left: 50%;/*向右偏移50%*/
top: 50%;/*向右偏移50%*/
margin-left: -50px;/*由于定位的基准是以图形的左上角为基准,所以还需微调一下*/
margin-top: -50px;
text-align: center;/*文字左右居中*/
line-height: 100px;/*文字上下居中,行高*/
}
</style>
</head>
<body>
<div>hello world</div>
</body>
</html>
div与div中的字上下左右居中
最新推荐文章于 2023-01-02 14:59:08 发布