css 图片居中显示
<!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>
/* 行内元素与行内块元素可以当做文字一样去处理 */
.userinfo{ width: 200px; height: 60px; background-color: bisque; line-height: 60px; text-align: center; margin: 10px auto; }
/**添加图片的垂直方向居中*/ .userinfo img{ vertical-align: middle; } </style> </head> <body> <div class="userinfo"> <img src="./html+css/study/user.png" alt=""> <span>taotao</span> </div> </body> </html>
效果如下
只是查找方便的总结