css - 我页面周围的边框正在阻止元素悬停工作
问题描述
我的网页周围有一个边框,可以防止将鼠标悬停在元素上。在下面的示例中,绿色框在悬停时进行缩放,但没有。
如果我添加一个否定标签它可以工作z-index
。body::before
但是,当页面滚动时,所有文本都会超出边框。
我需要边框始终位于顶部,并且悬停仍然有效。
.zoom {
padding: 50px;
background-color: green;
transition: transform .2s;
width: 50px;
height: 50px;
margin: 0 auto;
}
.zoom:hover {
-ms-transform: scale(1.5);
/* IE 9 */
-webkit-transform: scale(1.5);
/* Safari 3-8 */
transform: scale(1.5);
}
.lorem {
width: 300px;
margin: auto;
}
body::before {
content: '';
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
border: 15px solid #30582b;
padding: 0px;
}
<div class="zoom"></div>
<div class="lorem">
What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen
book it has? What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to
make a type specimen book it has?What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type
and scrambled it to make a type specimen book it has? What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer
took a galley of type and scrambled it to make a type specimen book it has? What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when
an unknown printer took a galley of type and scrambled it to make a type specimen book it has?What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book it has?
</div>
解决方案
pointer-events: none
在边框的伪元素上设置:
.zoom {
padding: 50px;
background-color: green;
transition: transform .2s;
width: 50px;
height: 50px;
margin: 0 auto;
}
.zoom:hover {
-ms-transform: scale(1.5);
/* IE 9 */
-webkit-transform: scale(1.5);
/* Safari 3-8 */
transform: scale(1.5);
}
.lorem {
width: 300px;
margin: auto;
}
body::before {
content: '';
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
border: 15px solid #30582b;
padding: 0px;
pointer-events: none;
}
<div class="zoom"></div>
<div class="lorem">
What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen
book it has? What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to
make a type specimen book it has?What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type
and scrambled it to make a type specimen book it has? What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer
took a galley of type and scrambled it to make a type specimen book it has? What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when
an unknown printer took a galley of type and scrambled it to make a type specimen book it has?What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book it has?
</div>
推荐阅读
- java - 从 java 的 LinkedList 类中获取“sub-LinkedLlists”(用于 MergeSort 目的)
- c# - 如何从 twilio 跟踪用户消息和用户电话号码到我们的应用程序
- python - 当 2 个列表与 + 运算符连接时会创建多少个列表副本?
- javascript - Javascript自定义HTMLElement问题
- internationalization - 如何使用 Hugo 和 NetlifyCMS 管理国际化
- javascript - 从 XML 标记中获取文本时如何删除空格?
- python - 我在 ubuntu18.04 上执行了 Python 2,但没有导入“tkinter”
- webpack - webpack - 奇怪的控制台消息(提供输出,404 将回退,提供不是来自 webpack 的内容......等等)
- ios - UIImagePicker 在 Objective c 和 Swift 中给出错误的裁剪图像
- email - 带有气流的电子邮件