父元素遮住子元素的问题

本文介绍了一种使用CSS实现hover效果的方法。通过设置.parent和.children元素的样式,当鼠标悬停在.parent上时,.children元素会显示出来。该技巧利用了相对定位和绝对定位结合的方式,并调整了z-index确保正确显示。

这是一种样式实现方法,可能存在问题,做个笔记方便以后看

为两部分,第一部分橘色是parent,蓝色是children

hover时候,children出现 

效果图:

原理实现 :

.header .gwc{
    margin-right: 98px;
    background-color: #fff;
    float: right;
    margin-top: -60px;
    border: 1px solid #e3e4e5;
    color: #f10215;
    line-height: 35px;
    text-align: center;
    font-size: 12px;
    width: 190px;
    position: relative;
} 
.header .gwc:hover{
    border-color:#ccc;
    border-bottom: 2px solid #fff;
用白色的变遮住下面子元素灰色的边,实现不规则图形描边
}

  子元素:

.header .gwc:hover .gwc_box{
    display: block;
}
.header .gwc_box{
    display: none;
    position: absolute;
    width: 310px;
    height: 70px;
    border: 1px solid #ccc;
    bottom: -70px;
    right: -1px;
    box-sizing: border-box;
    padding: 10px;
    z-index:-1;必须为负值 父级元素才会显现上来
    background-color: #fff;
}

  这样就完成了 

hover 

 

转载于:https://www.cnblogs.com/GoTing/p/7225965.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值