CSS实现居中代码大全
来源:互联网 发布:mirror软件 app 编辑:程序博客网 时间:2024/06/08 13:27
原文地址:CSS实现居中代码大全作者:之一
在设计网页模板时,经常要用CSS来控制块级元素的水平或是垂直位置,往往需要进行居中的操作。今天我就和大家一起来研究下如何用CSS来控制元素的居中。 <div style="float:left;width:275px;height:375px;border: solid red;">
<divstyle="height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<div style="position:static;position:absolute9; 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;">
</div>
</div>
</div>
</div>
</div> <div style="float:left;width:275px;height:375px;border: solid red;">
<divstyle=" height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<divstyle="position:static;position:absolute9; top: 50%;">
<divstyle="position: relative; top: -50%; ">
<div style="margin:0 auto;width: 160px;WORD-WRAP: break-word;TABLE-LAYOUT: fixed;word-break:break-all;">
</div>
</div>
</div>
</div>
</div>
1、单行垂直居中
文字在层中垂直居中vertical-align
<div style="line-height:500px;height:500;"></div>
2、层水平居中
设置div的宽度小于父div的宽度,设置
#parentdiv
{
width:500px;
}
#childdiv{
width:200px;
margin:0auto;
}
{
width:
}
#childdiv
width:
margin:0
}
3、层中的文字水平居中
在childdiv的css加上text-align:center;
#parentdiv
{
width:500px;
}
#childdiv{
width:200px;
margin:0auto;
text-align:center;
}
{
width:
}
#childdiv
width:
margin:0
text-align:center;
}
4、div层垂直居中
<div style="width:275px;height:375px;border: solid red;">
<divstyle=" background:green;height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<divstyle=" background:red;position:static;position:absolute9; top: 50%;">
<divstyle=" background:blue;position: relative; top: -50%;">
</div>
</div>
</div>
</div>
<div
</div>
5、div层垂直水平居中,英文超长换行
<divstyle="
</div>
6、div垂直滚动
<divstyle="width:
7、垂直居中和使用text-align水平居中
<div style="float:left;width:275px;height:375px;border: solid red;">
<divstyle="height: 375px; width: 275px; position: relative; display: table-cell; vertical-align: middle;">
<divstyle="position:static;position:absolute9;top: 50%;">
<divstyle="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;">
</div>
</div>
</div>
</div>
</div>
</div>
<divstyle="
</div>
8、垂直居中和使用margin水平居中
<div
</div>
8、背景图片居中
background-position:centercenter
- CSS实现居中代码大全
- CSS实现居中代码大全
- CSS实现居中代码
- CSS垂直居中实现方法大全
- css居中大全
- css居中代码
- CSS居中代码
- div+css居中代码
- html + css 居中方法大全
- 用CSS实现文字垂直居中的代码
- CSS实现垂直居中!
- 实现DIV居中 css
- CSS实现垂直居中
- CSS实现居中
- CSS居中实现
- CSS实现垂直居中
- CSS实现div居中
- CSS实现垂直居中
- 什么叫索引?索引的作用和分类
- java中静态方法和静态变量的…
- thinkphp session设置
- thinkphp3.0增加setInc、set…
- CSS实现居中代码大全
- CSS实现居中代码大全
- css字体样式(Font Style),属性
- 详细的网络体系协议图
- XAMPP使用教程
- Java第一个程序_HelloWorld…
- 《将博客搬至CSDN》
- 使用gsoap生成onvif代码框架
- Android开发之InstanceState详解
- su与sudo使用详解