请问老师,为什么p标签设置了font后就不能垂直居中了?

来源:2-9 自由编程

慕九州0179892

2022-02-09 10:51:16

<!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>

        * {

            margin: 0;

            padding: 0;

        }


        .transition-test1 .test1-box1{

            width: 500px;

            height: 400px;

            margin:40px auto;

            position: relative;

            overflow: hidden;

        }

        .transition-test1 .test1-box1 img{

            width: 500px;

            height: 400px;            

        }

        .transition-test1 .test1-box1 p{

            position: absolute;

            bottom: 0;

            width: 500px;

            height: 80px;    

            line-height: 80px;      

            color: white;

            text-align: center;          

            /* 设置后不能垂直居中??? */  

            /* font:20px/1.5 Arial,"微软雅黑"; */

            background-color:rgba(200, 200, 200, .7);

            transition: opacity 1s ease 0s;

            opacity: 0;

        }

        .transition-test1 .test1-box1:hover p{

            opacity: 1;

        }

    </style>

</head>


<body>

    <!-- /* 动画过渡 */ -->

    <section class="transition-test1">

        <div class="test1-box1">

            <img src="headerimages/duck.png" alt="">

            <p>这是一只小黄鸭</p>

        </div>

    </section>

</body>


</html>


写回答

1回答

好帮手慕星星

2022-02-09

同学你好,关于垂直居中的问题,已经在另外一个问题中进行了回复,可以查看:

https://class.imooc.com/course/qadetail/316628

另外习题中要求动画效果是向上滑动,代码中用opacity属性是透明度过渡,建议修改,例如:

https://img.mukewang.com/climg/62032fe30934120506420532.jpg

祝学习愉快!

0

0 学习 · 15276 问题

查看课程