---
title: "如何在div中文字垂直居中"
author: "LD_21"
date: "2010-05-05T13:54:15Z"
tags: ["UI"]
categories: ["Web前端"]
slug: "div"
draft: false
lastmod: "2010-05-05T13:54:15Z"
id: 659482
url: "https://ld-21.iteye.com/blog/659482"
---

文字在div中文字垂直居中有两种情况：单行文字、多行文字

一、单行文字

       只需设置div的高度与文字的行高一样就OK了，即 line-height 和height 的数值一样。
       例如：div{ height: 20px; line-height: 20px; }

二、多行文字

       只要设定 padding-bottom 和 padding-top 一样的就OK了。
       例如：div{ padding-top: 20px; padding-bottom: 20px; }
 
