垂直居中问题、多行居中

2020-07-18  本文已影响0人  Amanda妍

实现效果

实现代码:
<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<style type="text/css">

.d1{

text-align: center;

width: 200px;

height: 100px;

background-color: greenyellow;

/*单行居中*/

line-height: 100px;

}

/*多行居中*/

.d2{

width:600px;

background-color: goldenrod;

/*内填充 多行居中*/

padding :20px 0;

text-align: center;

}

.d3{

width:600px;

height: 200px;

background-color: red;

margin-top: 50px;

/*标签转换*/

display: table-cell;

vertical-align:middle;

text-align: center;

}

</style>

</head>

<body>

<div class="d1">

明月几时有?把酒问青天

</div>

<div class="d2">

明月几时有?把酒问青天.不知天上宫阙,今夕是何年?

</div>

<div class="d3">

明月几时有?把酒问青天.不知天上宫阙,今夕是何年?

</div>

</body>

</html>

上一篇 下一篇

猜你喜欢

热点阅读