javascript - 如何隐藏容器内的 div 的一小部分但显示另一个溢出部分
问题描述
是否可以隐藏容器内的 div 的一小部分但显示另一个左侧部分溢出。
我要说的是,您可以简单地设置overflow
为hidden
隐藏从特定溢出的所有内容,在这种情况下,我想要的是相反的。
代码:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
position: absolute;
width: 100%;
height: 100%;
background: #111;
}
.magnifier {
position: relative;
top: 0;
width: 30%;
height: 200px;
background: rgba(230, 230, 230, .1);
border-radius: 10px;
margin: 30px;
box-shadow: inset 1px 0 rgba(225, 225, 225, .1), inset 1px 2px 6px 7px rgba(225, 225, 225, .1);
}
.inside {
position: absolute;
top: 50%;
right: -6px;
width: 13px;
height: 13px;
transform: rotate(45deg);
background: rgba(230, 230, 230, .1);
}
<div class="container">
<div class="magnifier">
<div class="inside"></div>
</div>
</div>
正如您在上面右侧的片段中看到的那样div.magnifier
,div.inside
我只想显示外部部分看起来像一个箭头,但您会看到该 div 的所有部分都被显示。
我知道当没有应用不透明度时,上述问题是不寻常的,但在我的情况下,我想要它,而且问题不是由inset
on引起的box-shadow
。
如果有任何不同的方式我可以做到这一点,我会很感激。
解决方案
您可以使用 clip-path 功能来实现相同的目的。我尝试了这些值并得到了我想你需要的东西。在课堂内添加这个。
clip-path:polygon(0 0,100% 0 ,100% 100%,90% 100%);
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
position: absolute;
width: 100%;
height: 100%;
background: #111;
}
.magnifier {
position: relative;
top: 0;
width: 30%;
height: 200px;
background: rgba(230, 230, 230, .1);
border-radius: 10px;
margin: 30px;
box-shadow: inset 1px 0 rgba(225, 225, 225, .1), inset 1px 2px 6px 7px rgba(225, 225, 225, .1);
}
.inside {
position: absolute;
top: 50%;
right: -8px;
width: 15px;
height: 15px;
background: rgba(230, 230, 230, .1);
transform: rotate(45deg);
clip-path:polygon(0 0,100% 0 ,100% 100%,90% 100%);
}
<div class="container">
<div class="magnifier">
<div class="inside"></div>
</div>
</div>
推荐阅读
- sql - 使用 UPC 登录 SQL Management Studio
- javascript - 不必在 addEventListener 中传入参数?
- go - Go 找不到 sdl
- c - 使用 openssl 在客户端/服务器中进行 DES 加密/解密
- sql-server - 插入记录前的测试条件 SQL server
- c# - Xamarin 无法转换 System.Threading.Tasks
- javascript - 从下拉菜单的多个实例中获取值
- android-studio - Intellij 结构搜索功能接口
- ios - FlexBox 不适用于 iPhone 6
- jenkins - jenkins 和 cloudbees jenkins 有什么区别?