上下左右垂直居中

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style type="text/css">

.out{

width: 400px;

height: 400px;

border: 2px solid red;

position: relative;

}

.inn{

width: 150px;

height: 150px;

background: #333;

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%, -50%);

}

.out2{

width: 400px;

height: 400px;

border: 2px solid red;

display:flex;

}

.inn2{

width: 150px;

height: 150px;

background: #333;

margin:auto

}

.out3{

width: 400px;

height: 400px;

border: 2px solid red;

display:table;

}

.inn3{

background: #333;

display: table-cell;

vertical-align: middle;

}

.out4{

width: 400px;

height: 400px;

border: 2px solid red;

display: flex;

align-items: center;

justify-content: center;

}

.inn4{

background: #333;

}

</style>

</head>

<body>

<div class="out">

<div class="inn">

</div>

</div>

<div class="out2">

<div class="inn2">

</div>

</div>

<div class="out3">

<div class="inn3">

文字并不知道具体有多少,可能有一行,也可能有很多行,那么遇到多行文字的这种问题我们要如何处理呢。

文字并不知道具体有多少,可能有一行,也可能有很多行,那么遇到多行文字的这种问题我们要如何处理呢。

</div>

</div>

<div class="out4">

<div class="inn4">

文字并不知道具体有多少,可能有一行,也可能有很多行,那么遇到多行文字的这种问题我们要如何处理呢。

文字并不知道具体有多少,可能有一行,也可能有很多行,那么遇到多行文字的这种问题我们要如何处理呢。

</div>

</div>

</body>

</html>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容