1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > div盒子水平垂直居中以及表格的居中的方法

div盒子水平垂直居中以及表格的居中的方法

时间:2018-04-19 01:24:55

相关推荐

div盒子水平垂直居中以及表格的居中的方法

目录

多种水平垂直居中方法

这里的方法和第二种一致,方便用来对系统后台进行布局

#admin {position: absolute;top: 50%;left: 50%;margin-top: -150px;margin-left: -200px;width: 400px;height: 300px;background: #fff;}

1.必需知道该div的宽度和高度,

2.然后设置位置为绝对位置,

3.距离页面窗口左边框和上边框的距离设置为50%,这个50%就是指页面窗口的宽度和高度的50%,

4.最后将该div分别左移和上移,左移和上移的大小就是该DIV宽度和高度的一半。

登录页面使用表格进行布局

<table><tr><td width='100'>用户名:</td><td width="300"><el-inputv-model="input"placeholder="请输入内容"style="width: 250px"></el-input></td></tr><tr><td width='100'>密&nbsp;&nbsp;&nbsp;码:</td><td width='300'><el-inputv-model="input"placeholder="请输入内容"style="width: 250px;"></el-input></td></tr></table>

table{width: 350px;margin: auto;}td{letter-spacing:1px; text-align: right;}

多种水平垂直居中方法

当然居中的方式还有很多,下面是水平和垂直居中的一些写法

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>/* 第一种居中方式 *//* .pre{width: 500px;height: 500px;background-color: aqua;position: relative;}.child{width: 100px;height: 100px;background-color: black;position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);} *//* 第二种方式 *//* .pre{width: 500px;height: 500px;background-color: aqua;position: relative;}.child{width: 100px;height: 100px;background-color: black;position: absolute;top: 50%;left: 50%;margin-left: -50px;margin-top: -50px;} *//* 第三种方式flex居中 */.pre{width: 500px;height: 500px;background-color: aqua;display: flex;align-items: center;justify-content: center;}.child{width: 100px;height: 100px;background-color: black;}</style></head><body><div class="pre"><div class="child"></div></div></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。