CSS实例:水平居中和垂直居中的多种解决方案
1、单行垂直居中
文字在层中垂直居中vertical-align 属性是做不到的.我们这里有个比较巧妙的方法就是:设置height的高度与line-height的高度相同!
Example Source Code [www.52css.com]
<div style="line-height:500px;height:500;"></div>
2、层水平居中
设置div的宽度小于父div的宽度,设置 margin:0 auto;,即可让div居中。
Example Source Code [www.52css.com]
#parentdiv
{
width: 500px;
}
#childdiv {
width: 200px;
margin:0 auto;
}
3、层中的文字水平居中
在childdiv的css加上text-align:center;
Example Source Code [www.52css.com]
#parentdiv
{
width: 500px;
}
#childdiv {
width: 200px;
margin:0 auto;
text-align:center;
}
4、div层垂直居中
Example Source Code [www.52css.com]
<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%;">
www.52css.com
</div>
</div>
</div>
</div>
5、div层垂直水平居中,英文超长换行
Example Source Code [www.52css.com]
<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;">
www.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.com
</div>
</div>
</div>
</div>
</div>
6、div垂直滚动
Example Source Code [www.52css.com]
<div style="width: 160px; height: 260px; overflow-y: scroll; border: 1px solid;">
</div>
7、垂直居中和使用text-align水平居中
Example Source Code [www.52css.com]
<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;">
www.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.com
</div>
</div>
</div>
</div>
</div>
</div>
8、垂直居中和使用margin水平居中
Example Source Code [www.52css.com]
<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;">
www.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.comwww.52css.com
</div>
</div>
</div>
</div>
</div>
CSS实例:水平居中和垂直居中的多种解决方案的更多相关文章
- CSS的水平居中和垂直居中解决方案
在写CSS样式的时候,有时为了美观,会添加水平居中和垂直居中,这时候你有可能会遇到很棘手的问题,有些水平居中和垂直居中的属性添加上去完全没反应,下面给大家列举一些CSS水平居中和垂直居中的终极解决方案 ...
- 主流 CSS 布局(水平居中、垂直居中、居中 )
什么是布局 html 页面的整体结构或骨架 布局不是某个技术内容 而是一种设计思想 [ 布局方式 ] 水平居中布局 垂直居中布局 居中布局( 水平 + 垂直 ) 什么是水平居中布局 水平居中布局 元素 ...
- 【CSS】水平居中和垂直居中
水平居中和垂直居中 2019-11-12 15:35:37 by冲冲 1.水平居中 (1)父级元素是行内元素,子级元素是行内元素,子级元素水平居中 ① 设置父级元素为块级元素 display:bl ...
- css的水平居中和垂直居中总结
Html代码: <div class="md-warp"> <div class="md-main">块级元素</div> ...
- css:元素水平垂直居中的多种方式
CSS元素(文本.图片)水平垂直居中方法 1.text-align:center; 2.margin:0 auto; 3.display:inline-block; + text-align:ce ...
- CSS:水平居中与垂直居中
CSS居中算是一个比较基础的问题,在实际运用中,需要考虑到的一般是两种情况,一种是主要是表现为文字,图片等行内元素的居中,一种是指 div 等块级标签元素的居中. 水平居中 1.行内元素 行内元素(主 ...
- css元素水平居中和垂直居中的方式
关于居中的问题,一直处于疑惑不解的状态,知道的几种方法好像也不是每一次都会起到作用,所以更加迷惑.主要是不清楚该 在什么情况下采用哪种解决方法,所以,整理了一些方法,梳理一下思路,做一个总结. 1. ...
- CSS元素水平居中和垂直居中的方法大全
水平居方法: 1.最熟悉的是给元素定义一个宽度,然后使用margin: body{ width:960px; margin:0 auto;}这个是当我们的定义元素的宽度时显现的,如果我们不能定义宽度时 ...
- 在CSS中水平居中和垂直居中:完整的指南
这篇文章将会按照如下思路展开: 一.水平居中 1. 行内元素水平居中 2. block元素水平居中 3. 多个块级元素水平居中 二.垂直居中 1. 行内元素水平居中 2. block元素水平居中 3. ...
随机推荐
- c#语句:分支
六.分支:(一)if (表达式){}说明:1.表达式,就是用来返回bool形的表达式.2.if的小括号后面千万不要加分号 (二)if(表达式){}else{} 例:1.输入年龄,大于等于18显示成年, ...
- 关于内层DIV设置margin-top不起作用的解决方案
from:http://www.cnblogs.com/huangyong8585/archive/2013/05/21/3090779.html (一) 近日在做另外一个站点的时候,又遇到这个问题, ...
- C#获取mac
验证计算机MAC地址进行软件授权是一种通用的方法,C#可以轻松获取计算机的MAC地址,本文采用实际的源代码讲述了两种获取网卡的方式,第一种 方法使用ManagementClass类,只能获取本机的计算 ...
- C - The Hardest Problem Ever
Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever ...
- (原+转)ROC曲线
转自:http://baike.baidu.com/link?url=_H9luL0R0BSz8Lz7aY1Q_hew3JF1w-Zj_a51ggHFB_VYQljACH01pSU_VJtSGrGJO ...
- 【Android 错误记录】android.os.NetworkOnMainThreadException 异常问题
最近自己学习开发一个小app,想根据网络来判断一些逻辑,但是运行应用时遇到了这个错误 android.os.NetworkOnMainThreadException 后来,查询了一些信息,发现原因就是 ...
- 【Lucene4.8教程之二】索引
一.基础内容 0.官方文档说明 (1)org.apache.lucene.index provides two primary classes: IndexWriter, which creates ...
- JavaScript的异步操作
http://sporto.github.io/blog/2012/12/09/callbacks-listeners-promises/
- mac osx 10.9 ftp server端口
开启 FTP Serversudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist 关闭 FTP Serversudo -s ...
- Leetcode 100 Same Tree python
题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...