案例2:图片实现水平垂直居中
- 代码块
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>图片实现水平垂直居中</title>
<style type="text/css">
div{
width: 600px;
height: 600px;
background-color: pink;
/* 图片的居中:在img的父代码中添加如下代码 */
text-align: center;
line-height: 600px;
}
img{
vertical-align: middle;}
</style>
</head>
<body>
<div>
<img src="/0-img/02.jpeg" width="300px">
</div>
</body>
</html>