博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
元素垂直或居中定位
阅读量:4322 次
发布时间:2019-06-06

本文共 1033 字,大约阅读时间需要 3 分钟。

HTML格式为

Test

下面的styles 皆为.child所用。

1. 垂直定位

inline element:

selector{
inline-height: parent-height;}

block element:

div_with_exact_height{
position: absolute; height: 50px; margin-top: auto; margin-bottom: auto; top: 0; bottom: 0; }
div_can_stretch{
position: absolute; height: auto; margin-top: 10px; margin-bottom: 10px; top: 0; bottom: 0;}

2. 水平居中

(1) position: static/relative

div_with_exact_width{
width: 50px; text-align: center; margin-left: auto; margin-right: auto;}
div_can_stretch{
width: auto; text-align: center; margin-left: 20px; margin-right: 20px;}

(2) position: absolute;

div_with_exact_width{
position: absolute; width: 50px; margin-left: auto; margin-right: auto; left: 0; right: 0;}
div_can_stretch{
position: absolute; width: auto; margin-left: 20px; margin-right: 20px; left: 0; right: 0;}

 

转载于:https://www.cnblogs.com/etianqq/p/3166008.html

你可能感兴趣的文章
flume+elasticsearch+kibana遇到的坑
查看>>
【MM系列】在SAP里查看数据的方法
查看>>
C#——winform
查看>>
CSS3 transform制作的漂亮的滚动式导航
查看>>
《小强升职记——时间管理故事书》读书笔记
查看>>
Alpha 冲刺(3/10)
查看>>
Kaldi中的Chain模型
查看>>
spring中的ResourceBundleMessageSource使用和测试示例
查看>>
css规范 - bem
查看>>
电梯调度程序的UI设计
查看>>
转自 zera php中extends和implements的区别
查看>>
Array.of使用实例
查看>>
【Luogu】P2498拯救小云公主(spfa)
查看>>
如何获取网站icon
查看>>
几种排序写法
查看>>
java 多线程的应用场景
查看>>
dell support
查看>>
[Hive - LanguageManual] Alter Table/Partition/Column
查看>>
可持久化数组
查看>>
去除IDEA报黄色/灰色的重复代码的下划波浪线
查看>>