javascript - 里面有透明方块的覆盖
问题描述
现在我有如下所示的内容。我希望正方形是透明的,这意味着背景有一个“叠加”效果,但是一个透明的正方形,所以我可以查看它下面的项目。
请问这是否可以实施?
.overlay{
display: flex;
align-items: center;
justify-content: center;
height: 250px;
width: 250px;
border: solid red 1px;
background-color: rgba(0, 0, 0, 0.3);
}
.square{
height: 100px;
width: 100px;
border: solid lime 1px;
background-color: transparent !important;
}
<div class="overlay">
<div class="square"></div>
</div>
解决方案
就用这样的巨人box-shadow
——
.overlay{
display: flex;
align-items: center;
justify-content: center;
height: 250px;
width: 250px;
border: solid red 1px;
background-color: green;
overflow:hidden;
}
.square{
height: 100px;
width: 100px;
border: solid lime 1px;
box-shadow: 0 0 0 500px red;
}
<div class="overlay">
<div class="square"></div>
</div>
实际上,如果您使用插入框阴影,则根本不需要方形 div
.overlay {
display: flex;
align-items: center;
justify-content: center;
height: 250px;
width: 250px;
border: solid red 1px;
background-color: green;
overflow: hidden;
margin: 1em auto;
box-shadow: inset 0 0 0 50px rgba(0, 0, 0, 1);
}
<div class="overlay">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Recusandae saepe hic sequi eveniet iusto est corrupti commodi porro! Dignissimos provident voluptas numquam iste corrupti at?</p>
</div>
推荐阅读
- html - Html input styling css:focus do not trigger
- android - 我可以在android中自定义多选警报对话框吗?
- php - 无法从 CodeIgniter 中的 php-facebook-login-sdk 获取用户数据?
- ios - 无法在表单样式控制器上显示控制器
- javascript - Dart wrapper over js library and use it in flutter app
- fiware - 将 lwm2m-node-lib 设置到 FIWARE 平台
- unity3d - 是否可以将根运动应用于非人形物体?
- expression - Error_Generator 表达式_spyder(python 3.6)
- mysql - Advanced Search Functionality - SQL
- javascript - 根据设备打开链接