前端 显示与隐藏

显示与隐藏

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>显示与隐藏</title>
    <style>
        body {
            margin: 0;
        }
        div {
            width: 200px;
            height: 200px;
            background-color: orange;
            font: 30px/200px 'Arial';
            color: red;
            text-align: center;
            margin: 0 auto;
            border-radius: 50%;
        }
    </style>
    <style>
        /*display
        值为none时,盒子会被隐藏,且不在页面中占位
        */
        .box2 {
            display: none;
            transition: 1s;
        }
        .box1:hover ~ .box2 {
            display: block;
        }
        .box2:hover {
            display: block;
        }
    </style>
    <style>
        /*opacity
        值为0~1,控制盒子的透明度,但是消失后,在页面中占位
        */
        .box4 {
            /*背景颜色不能操作文本*/
            /*background-color: rgba(0,0,0,0);*/
            opacity: 0;
            /*过度效果*/
            transition: 1s;
        }
        .box3:hover ~ .box4 {
            opacity: 1;
        }
        .box4:hover {
            opacity: 1;
        }
    </style>

    <style>
        .box6 {
            width: 0;
            height: 0;
            /*超出content以外的内容如何处理:hidden隐藏*/
            overflow: hidden;
            transition: 1s 0s ease;
            /*过渡得我属性个数可以自定义*/
            /*transition-property: width, background-color, height;*/
            transition-property: all;
        }
        .box5:hover ~ .box6 {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
        .box6:hover {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>
<body>
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
<div class="box4">4</div>
<div class="box5">5</div>
<div class="box6">6</div>
<div class="box7">7</div>
<div class="box8">8</div>
</body>
</html>

转载于:https://www.cnblogs.com/bladecheng/p/11284539.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
前端根据权限来控制某些元素的显示隐藏,通常可以采用以下两种方式: 1. 通过 v-if 或 v-show 控制元素的显示隐藏 在 Vue.js 中,可以通过 v-if 或 v-show 指令来控制元素的显示隐藏。v-if 指令可以根据表达式的值来动态添加或移除元素,而 v-show 指令则是根据表达式的值来控制元素的显示隐藏。 例如,以下代码中的按钮只有在用户具备某个权限时才会显示: ```html <template> <div> <button v-if="hasPermission">操作</button> </div> </template> <script> export default { data() { return { hasPermission: false // 根据用户权限来设置 }; } }; </script> ``` 2. 通过 CSS 样式控制元素的显示隐藏 通过设置 CSS 样式的 display 属性来控制元素的显示隐藏,这种方式通常需要在 HTML 元素上添加一个 CSS 类名,并在 CSS 样式中定义该类名的显示隐藏样式。 例如,以下代码中的按钮只有在用户具备某个权限时才会显示: ```html <template> <div> <button class="btn-permission">操作</button> </div> </template> <style> .btn-permission { display: none; /* 默认隐藏 */ } .has-permission .btn-permission { display: inline-block; /* 具备权限时显示 */ } </style> <script> export default { data() { return { hasPermission: false // 根据用户权限来设置 }; }, computed: { classObject() { return { 'has-permission': this.hasPermission }; } } }; </script> ``` 以上两种方式都可以根据用户的权限来控制某些元素的显示隐藏,具体使用哪种方式可以根据实际情况来选择。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值