css设置穿透元素

css设置穿透元素说明白点就是两个元素叠加在一起,没有设置的话就只能点击到上层元素,设置后只能单击到下层元素

将css属性pointer-events的值设置为none就可以实现这一种效果

虽然这个属性用处不是那么大,不用都行;但是使用这个属性可以为我们避免一些烦琐的样式设置,也可以为我们节省几行代码的量。

效果图

43be8d692ae84cfdb791e50dc0938082.gif

废话不多说,上代码  

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>css设置穿透元素</title>
		<style type="text/css">
			* {
				margin: 0px;
				padding: 0px;
			}

			body {
				min-width: 100vw;
				min-height: 100vh;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			body>div {
				width: 450px;
				height: 40px;
				font-size: 0px;
				border-radius: 25px;
				position: relative;
				box-sizing: border-box;
				border: 2px solid rgba(0, 0, 0, 0.9);
			}

			body>div>input[type=text] {
				width: 340px;
				height: calc(102% - 10px);
				padding: 5px;
				line-height: 40px;
				text-align: center;
				font-size: 20px;
				margin-top: -0.5px;
				border: none;
				outline: none;
				border-radius: 25px 0px 0px 25px;
			}

			body>div>input[type=submit] {
				width: 96px;
				height: 102%;
				border: none;
				color: #ffffff;
				font-size: 20px;
				margin-top: -0.5px;
				font-weight: bold;
				vertical-align: top;
				background-color: rgba(0, 0, 0, 0.9);
				border-radius: 0px 25px 25px 0px;
			}

			body>div>div {
				width: 350px;
				height: calc(102%);
				line-height: 37px;
				font-size: 15px;
				text-align: center;
				position: absolute;
				top: -0.5px;
				transition: 0.5s;
				pointer-events: none;
				background-color: #B3D33F;
				border-radius: 25px 0px 0px 25px;
			}

			.focus:before {
				content: "";
				width: 460px;
				height: 50px;
				position: absolute;
				left: -7px;
				top: -7px;
				z-index: -1;
				border-radius: 25px 25px 25px 25px;
				background-color: rgba(0, 0, 0, 0.2);
			}
		</style>
	</head>
	<body>
		<div>
			<input type="text" placeholder="没骗人吧">
			<input type="submit" value="确认" />
			<div>我是一个div,单击我也可以使得input获得焦点</div>
		</div>
	</body>
	<script type="text/javascript">
		document.querySelector('body>div>input[type=text]').onfocus = function() {
			document.querySelector('body>div').classList.add("focus");
			document.querySelector('body>div>div').style.cssText = 'width: 100%;top:50px;border-radius: 25px;';
		}
		document.querySelector('body>div>input[type=text]').onblur = function() {
			document.querySelector('body>div').classList.remove("focus");
			document.querySelector('body>div>div').style.cssText =
			'width: 350px;-0.5px;border-radius: 25px 0px 0px 25px;';
		}
	</script>
</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知勤者笔记

给点吧,没动力了!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值