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. ...
随机推荐
- 推荐10款 好用的 Jquery 评分插件
Raty jQuery Raty这是一个能够自动生成可定制的星级评分jQuery插件.可以自定义图标,创建各种评级组合,星星数量,每一颗星星的注释,可以在当一个星星被点击时的加回调函数. 地址: Ra ...
- tablbView中section的间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { if (sect ...
- Sql Server相关的性能计数器
OS Memory and Paging 性能计数器: 1.Memory\Availability Mbytes 未使用的物理内存(非页面文件),通常情况下它应该大于100MB 2.Memory\ ...
- html基础之 表单提交方法
最普通最常用最一般的方法就是用submit type..看代码: <form name=”form” method=”post” action=”#"> <input ty ...
- HDU 5145 - NPY and girls
题意: cases T(1≤T≤10) (0<n,m≤30000) (0<ai≤30000) n个数ai 表示n个女孩所在教室 m次询问 [L,R](1 <= L <= ...
- (原)matlab中使用mex编译多个cpp文件
以前一直是mex一个文件.刚才需要编译多个文件(如a.cpp调用b.cpp的函数,b.cpp调用c.cpp的函数).如果只是mex a.cpp,提示函数找不到函数. 突然想到mex c.cpp b.c ...
- oracle 序列
查询序列值 select td_prodline_attr_seq.nextval from dual 查询用户建的所有序列 用户名 必须大写select SEQUENCE_OWNER,SEQ ...
- 向Oracle数据库中CLOB插入数据报错问题
今天在项目中向数据库的CLOB属性插入一段篇文章(1000~2000)字就会报一个字符串过长的错误. 网上说用流来处理,没有这么做.这像是一个Bug,只要把插入的数据,默认扩充到2000以上就ok了. ...
- Linux Power(一): kernel/power/earlysuspend.c
/* kernel/power/earlysuspend.c * * Copyright (C) 2005-2008 Google, Inc. * * This software is license ...
- Arcgis Engine 添加一个Symbol符号样式步骤
public static void DrawPictureMarkerSymbol(IGlobe globe, String layerName) { //添加一个图层 ESRI.ArcGIS.Ca ...