css水平竖直居中方式
CSS水平和垂直居中的几种实现方法:
1、单行垂直居中
文字在层中垂直居中vertical-align 属性是做不到的.我们这里有个比较巧妙的方法就是:设置height的高度与line-height的高度相同!
<div style="line-height:500px;height:500;">
2、层水平居中
设置div的宽度小于父div的宽度,设置 margin:0 auto;,即可让div居中。
#parentdiv
{
width: 500px;
}
#childdiv {
width: 200px;
margin:0 auto;
}
3、层中的文字水平居中
在childdiv的css加上text-align:center;
#parentdiv
{
width: 500px;
}
#childdiv {
width: 200px;
margin:0 auto;
text-align:center;
}
4、div层垂直居中
<div style="width:275px;height:375px;border: solid red;">
<div style="background:green;height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<div style="background:red;position:static;position:absolute\9; top: 50%;">
<div style="background:blue;position: relative; top: -50%;">
book.chinaz.com
</div>
</div>
</div>
</div>
5、div层垂直水平居中,英文超长换行
<div style="float:left;width:275px;height:375px;border: solid red;">
<div style="height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<div style="position:static;position:absolute\9; top: 50%;">
<div style="position: relative; top: -50%; text-align: center;">
<div style="width: 85px;WORD-WRAP: break-word;TABLE-LAYOUT: fixed;word-break:break-all;margin:0 auto;">
book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com
</div>
</div>
</div>
</div>
</div>
6、div垂直滚动
<div style="width: 160px; height: 260px; overflow-y: scroll; border: 1px solid;">
book.chinaz.com
</div>
7、垂直居中和使用text-align水平居中
<div style="float:left;width:275px;height:375px;border: solid red;">
<div style=" height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<div style="position:static;position:absolute\9;top: 50%;">
<div style="position: relative; top: -50%; text-align:center;">
<div style="width: 275px;">
<div style="width: 160px;WORD-WRAP: break-word;TABLE-LAYOUT: fixed;word-break:break-all;text-align:left;">
book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com
</div>
</div>
</div>
</div>
</div>
</div>
8、垂直居中和使用margin水平居中
<div style="float:left;width:275px;height:375px;border: solid red;">
<div style=" height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<div style="position:static;position:absolute\9; top: 50%;">
<div style="position: relative; top: -50%; ">
<div style="margin:0 auto;width: 160px;WORD-WRAP: break-word;TABLE-LAYOUT: fixed;word-break:break-all;">
book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com book.chinaz.com
</div>
</div>
</div>
</div>
</div>
http://www.pc6.com/infoview/Article_45869.html
css水平竖直居中方式的更多相关文章
- 水平/竖直居中在旧版Safari上的bug
今天调了两个出现在旧版Safari上的layout bug. 它们最初是在同事的iPad上被发现的, 我在自己桌面上安装的Safari 5.1.7上也能够复现. Bug1: .vertical-cen ...
- html 水平竖直居中
line-height:容器高度 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- CSS -- 文字竖直居中
元素的height 和 lineheight 设置为一样即可.
- css水平居中,竖直居中技巧(二)
css水平居中,竖直居中技巧(二)===### 1.效果 ### 2.代码#### 2.1.index.html <!DOCTYPE html> <html lang="z ...
- css水平居中,竖直居中技巧(一)
css水平居中,竖直居中技巧(一)===### 1.效果 ### 2.代码#### 2.1.index.html <!DOCTYPE html> <html lang="z ...
- 常用布局,div竖直居中
常用两列布局,多列布局和div竖直居中 body { margin:; padding:; } .w200 { width: 200px; } .mar-left200 { margin-left: ...
- 讨论CSS中的各类居中方式
今天主要谈一谈CSS中的各种居中的办法. 首先是水平居中,最简单的办法当然就是 margin:0 auto; 也就是将margin-left和margin-right属性设置为auto,从而达到水平居 ...
- css控制竖直文字显示
假如有一天,你把水平文字看腻味了...... 我建议你不妨试试垂直文字显示,就像这样: 我 是 竖 直 显 示 的 : 哈哈! 言归正传,怎么把一段话,垂直显示呢? 方法1: //把下面代码另存为ht ...
- css中两种居中方式text-align:center和margin:0 auto 的使用场景
关于使用text-align:center和margin:0 auto 两种居中方式的比较 前言:最近由于要学习后端,需要提前学习一部分前端知识,补了补css知识,发现狂神在讲这一部分讲的不是特别清楚 ...
随机推荐
- k8s通过configmap管理应用配置信息
Secret 可以为 Pod 提供密码.Token.私钥等敏感数据:对于一些非敏感数据,比如应用的配置信息,则可以用 ConfigMap. ConfigMap 的创建和使用方式与 Secret 非常类 ...
- JSONObject常用的API
http://www.cnblogs.com/java-pan/archive/2012/04/07/jsonobject.html 1.介绍基于JSONObject 1.1的API 2.只介绍常用的 ...
- 【互动问答分享】第7期决胜云计算大数据时代Spark亚太研究院公益大讲堂
“决胜云计算大数据时代” Spark亚太研究院100期公益大讲堂 [第7期互动问答分享] Q1:Spark中的RDD到底是什么? RDD是Spark的核心抽象,可以把RDD看做“分布式函数编程语言”. ...
- vim 代码片段:通过vundle插件管理器安装ultisnips |centos6.5|vim7.2
背景:中午醒来,饭都没吃,突然想到要给vim增加个代码片段的功能,因为昨天使用了gedit的代码片段,感觉不错.为什么不直接使用gedit呢?因为我相信把时间投入到vim是不会错的,精通vim就好了. ...
- 设置每个datanode里面的map数目,提高运行效率
首先可以通过hdfs.site.xml下面的dfs.block.size来设置数据的块大小,这个参数会决定map的总数目(4194304=4m) 然后通过mapred.site.xml下面的mapre ...
- CF 917A The Monster 【括号匹配】
[链接]:CF Examples inputCopy ((?)) outputCopy 4 inputCopy ??()?? outputCopy 7 说明 For the first sample ...
- HDU 2504 又见GCD(数论,最大公约数)
又见GCD Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 中文名: 交通事故责任认定, 英文名称: Traffic accident responsibility identification
中文名: 交通事故责任认定, 英文名称: Traffic accident responsibility identification
- Mysql数据库的安装及配置
本文转载自http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 如果要在Linux上做j2ee开发,首先得搭建 ...
- Encode and Decode Strings -- LeetCode
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...