请问这里设置text-align:center;的方式是正确的吗

来源:2-9 自由编程

慕仙1405838

2021-03-09 17:45:49

<!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>小黄鸭缓动过渡案例</title>

    <style>

        .box {

            width300px;

            overflowhidden;

            positionrelative;

        }


        .box img {

            width300px;

            height240px;


        }


        .box .info {

            width280px;

            height30px;

            padding-left20px;

            colorwhite;

            text-aligncenter;

            positionabsolute;

            line-height30px;

            top226px;

            background-colorrgba(000.5);

            transitiontop 0.5s linear 0s;

        }


        .box:hover .info {

            top200px;

        }

    </style>

</head>


<body>

    <div class="box">

        <img src="images/duck.png" alt="小黄鸭缓动过渡案例">

        <p class="info">这是一只小黄鸭</p>

    </div>

</body>


</html>


写回答

1回答

好帮手慕星星

2021-03-09

同学你好,问题解答如下:

1、文本居中设置方式是正确的,但是还没有实现完全居中

http://img.mukewang.com/climg/6047526509a945f703330113.jpg

p标签存在左侧间距20px,需要去掉并且修改p的宽度和父盒子宽度一致。

2、默认文字部分会显示一个边,这是定位top值的问题

http://img.mukewang.com/climg/604752b809accb0603310120.jpg

建议再调整一下,参考:

http://img.mukewang.com/climg/6047539d095ea5b004780350.jpg

​祝学习愉快!

0

0 学习 · 15276 问题

查看课程