黑松山资源网 Design By www.paidiu.com
在jb51.net中,大量的文章介绍了这些知识。在和别人合作的时候,你的代码的自适应性就需要做到最大程度的好。你自己在做自己的网页的时候或许可以保证在视觉上是居中的,但是如果让这个元素或者他的父元素变大了,你还能保证居中吗?
vertical-align是个不错的属性,但是这个属性起初是针对表格的cell的。当然这个属性虽然对块级元素不起作用,但是对行内元素比如span还是有作用的(这时候,这个属性设置为负值元素内容就下移,正值则上移)。
下面是比较专业的垂直居中的集中解决方案。记录于此,以便查阅。
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%;">
www.jb51.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;">
www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.com
</div>
</div>
</div>
</div>
</div>
6、div垂直滚动
<div
style="width: 160px; height: 260px; overflow-y: scroll; border: 1px solid;">
www.jb51.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;">
www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.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;">
www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.com
</div>
</div>
</div>
</div>
</div>
vertical-align是个不错的属性,但是这个属性起初是针对表格的cell的。当然这个属性虽然对块级元素不起作用,但是对行内元素比如span还是有作用的(这时候,这个属性设置为负值元素内容就下移,正值则上移)。
下面是比较专业的垂直居中的集中解决方案。记录于此,以便查阅。
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%;">
www.jb51.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;">
www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.com
</div>
</div>
</div>
</div>
</div>
6、div垂直滚动
<div
style="width: 160px; height: 260px; overflow-y: scroll; border: 1px solid;">
www.jb51.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;">
www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.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;">
www.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.comwww.jb51.com
</div>
</div>
</div>
</div>
</div>
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年07月04日
2024年07月04日
- 中国音乐地图之听见江苏昆曲经典唱段2020[WAV+分轨]
- 《路易吉鬼屋2HD》GS 7分:适合掌机模式短时间游玩
- 《路易吉鬼屋2HD》M站均分77:出色3DS游戏的升级版
- 不输官方!玩家设计《光环》等主题Switch Pro手柄
- 王识贤.2010-伤心手指【华特】【WAV+CUE】
- 尚雯婕.2009-时代女性Time.Lady【华谊兄弟】【FLAC+CUE】
- 萧亚轩.2006-1087【华纳】【WAV+CUE】
- 徐佳莹《无损音乐合集》2009-2023[FLAC/分轨][2.3GB]
- 群星《那些年的男神,那些年的女神》2CD[WAV+CUE][1.4GB]
- 张学友《2023头版蜚声环球合集》32CD[WAV+CUE][15.7G]
- 绝区零珂蕾妲关键天赋是什么 珂蕾妲天赋效果解析
- 绝区零珂蕾妲音擎武器怎么选 珂蕾妲音擎选择推荐
- 绝区零护盾鸣徽有哪些 绝区零护盾鸣徽效果介绍
- 爱浪音响测试碟-《经典传说》2CD[DTS-WAV]
- 群星《情歌1号-2号(紫银合金)4CD》[WAV+CUE]