老师,为啥这里要设置一下text-indent呢?

来源:2-2 编程练习

慕勒8522502

2019-09-19 09:18:57

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>点击事件</title>
    <style type="text/css">
    div {
        float: left;
        margin: 10px;
        width: 100px;
        height: 100px;
        color: #fff;
        font-size: 50px;
        text-align: center;
        line-height: 100px;
        text-indent: -9999px;
        background-color: #333;
    }
    </style>
</head>

<body>
    <h1>添加事件处理</h1>
    <div>43</div>
    <div>21</div>
    <div>56</div>
    <div>16</div>
    <div>89</div>
    <div>94</div>
    <div>46</div>
    <div>26</div>
    <div>67</div>
    <div>90</div>
    <div>25</div>
    <div>10</div>
    <div>84</div>
    <div>76</div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script>
    //此处写代码
    $('div').click(function(){
        // 其实只写text-indent就可以了
        $(this).css({'text-indent':'0','background-color':'white', 'color':'red'});
    });
    
    </script>
</body>
</html>


写回答

1回答

好帮手慕夭夭

2019-09-19

你好同学,这是因为文本默认使用的text-indent属性设置的隐藏效果。text-indent:是设置首行缩进的,当这个值比较大的时候,文本就会超出屏幕隐藏了。所以要在js中,把text-indent:的值改为0 ,他就显示在div中了哦。

http://img.mukewang.com/climg/5d82ff2b095c93fa04480231.jpg

祝学习愉快,望采纳。

0

0 学习 · 14456 问题

查看课程