惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
SecWiki News
SecWiki News
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
Y
Y Combinator Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
K
Kaspersky official blog
T
The Exploit Database - CXSecurity.com
腾讯CDC
Scott Helme
Scott Helme
I
InfoQ
Cyberwarzone
Cyberwarzone
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Security Latest
Security Latest
The Register - Security
The Register - Security
Project Zero
Project Zero
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
C
Cisco Blogs
L
LINUX DO - 热门话题
P
Privacy International News Feed
IT之家
IT之家
U
Unit 42
P
Privacy & Cybersecurity Law Blog
H
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Palo Alto Networks Blog
F
Full Disclosure
宝玉的分享
宝玉的分享
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Hacker News: Front Page
Know Your Adversary
Know Your Adversary
PCI Perspectives
PCI Perspectives
Hugging Face - Blog
Hugging Face - Blog
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Recent Announcements
Recent Announcements
Forbes - Security
Forbes - Security
Cisco Talos Blog
Cisco Talos Blog

博客园 - 星空竹月

ASP入门基础教程-VBScript概述及基本元素 第一次安装sql2000挂起无法安装的问题 asp.net(c#)成条形码[转] 关于文章列表如何直接显示文章类别名的问题 Page_PreInit在网页传值的应用 利用.net的强大功能发送email - 星空竹月 - 博客园 在页面和Datalist控件中判断是否为今天 - 星空竹月 - 博客园 如何在asp.net中关闭B页面时,自动刷新A页面? - 星空竹月 - 博客园 ASP.net(c#)做返回上一页效果(后退)--代码 前进和后退按钮特效代码 - 星空竹月 - 博客园 文件上传实例(文件上传,自动重命名,自动添加文件夹) ASP.NET中文显示乱码之解决方法 限制显示字数 asp.net中,限制显示字数的问题? 将截断字符串或二进制数据。 IE6下透明PNG图片的显示 IE不支持PNG图片透明效果,怎么办 配置AjaxControlToolkit 怎样换网页中的鼠标图案??换成其他图片
Div中文字竖直居中的问题
星空竹月 · 2011-03-29 · via 博客园 - 星空竹月

有时候很需要使用CSSDiv中的文字在竖直方向和水平方向居中,今天查阅了一些资料,发现其实实现方法也不时很难。

CSS 中Div文字居中有两种情况,一种是Div文字水平居中,另外一种是Div文字竖直居中

一、首先说一下Div文字竖直居中。
1.单行文字
设置div的高度与文字的行高一样就可以了,即 line-height 和 height 的数值是一样的就可以了,最后给div一个 over-flow: hidden ,让超出的部分隐藏.
这种方法支持块级和内联极元素以及所有的浏览器,不过只能显示一行,而且IE中不支持< img >等的居中,之所以要用 overflow: hidden ,是因为当用户放大字体时,字会超出div的范围.
插入代码:

div{ 
height: 20px; 
line-height: 20px; 
overflow: hidden; 
}

2.多行文字
设定一样的 padding-bottom 和 padding-top
插入代码:

div{ 
padding-top: 20px; 
padding-bottom: 20px; 
}

这种方法同时支持块级和内联极元素以及非文本内容,包括图片等等,也支持所有浏览器,不足的就是不能固定高度。

二、再来说一下Div文字水平居中。
水平居中是很基本的:
align=”center”
就可以实现。

好了,以上就是我如何实现CSS Div文字水平居中和竖直居中方法。