是否可以在具有背景的容器中的元素上创建透明边框?用盒阴影插入和开始尝试它。但它不起作用......
当前代码:
#main{
background-image: url('https://www.bensound.com/bensound-img/betterdays.jpg');
width:800px;
height:400px;
background-size:100%;
}
#anyNavi{
height:200px;
width:100%;
background-color:rgba(255,255,255,0.5);
position:absolute;
margin-top:100px;
}
.borderTransparent{
width:100px;
height:100px;
float:left;
background-color:blue;
margin:50px 10px;
border:5px solid rgba(255,255,255,0);
}

<div id="main">
<div id="anyNavi">
<div class="borderTransparent">
<span>A</span>
</div>
<div class="borderTransparent">
<span>B</span>
</div>
<div class="borderTransparent">
<span>C</span>
</div>
<div class="borderTransparent">
<span>D</span>
</div>
<div class="borderTransparent">
<span>E</span>
</div>
</div>
</div>
&#13;
答案 0 :(得分:0)
这是一个使用线性渐变来模拟此行为的想法,但这需要应用于容器:
#main{
background-image: url('https://www.bensound.com/bensound-img/betterdays.jpg');
width:800px;
height:400px;
background-size:100%;
}
#anyNavi{
height:200px;
width:100%;
background:
linear-gradient(rgba(255,255,255,0.5),rgba(255,255,255,0.5)) 0 0/100% 40px no-repeat,
linear-gradient(rgba(255,255,255,0.5),rgba(255,255,255,0.5)) 0 100%/100% 40px no-repeat,
repeating-linear-gradient(to right,rgba(255,255,255,0.5) 0,rgba(255,255,255,0.5) 10px,transparent 10px,transparent 120px) -5px 50%/100% calc(100% - 80px) no-repeat;
position:absolute;
margin-top:100px;
}
.borderTransparent{
width:100px;
height:100px;
float:left;
background-color:blue;
margin:50px 10px;;
}
&#13;
<div id="main">
<div id="anyNavi">
<div class="borderTransparent">
<span>A</span>
</div>
<div class="borderTransparent">
<span>B</span>
</div>
<div class="borderTransparent">
<span>C</span>
</div>
<div class="borderTransparent">
<span>D</span>
</div>
<div class="borderTransparent">
<span>E</span>
</div>
</div>
</div>
&#13;
答案 1 :(得分:0)
我设法通过玩psuedo-classes和一些绝对定位来制作它。虽然没有对它进行编码响应。
body {
margin: 0;
padding: 0;
background-image: url('https://www.bensound.com/bensound-img/betterdays.jpg');
background-size: 100%;
}
body > div {
overflow: hidden;
}
body > div > ul {
text-align: center;
list-style-type: none;
margin: 0;
padding: 100px 0 100px 0;
width: 100%;
position: relative;
font-size: 0;
line-height: 0;
z-index: 1;
}
ul > li {
position: relative;
}
ul:before {
content: "";
display: inline-block;
width: 100%;
height: 100px;
background-color: rgba(255,255,255,0.5);
position: absolute;
top: 0;
left: 0;
}
ul:after {
content: "";
display: inline-block;
width: 100%;
height: 100px;
background-color: rgba(255,255,255,0.5);
position: absolute;
bottom: 0;
left: 0;
}
ul li {
display: inline-block;
margin-left: 15px;
margin-right: 15px;
position: relative;
}
ul li:before {
content: "";
display: inline-block;
width: 15px;
height: 100%;
background: rgba(255,255,255,0.5);
position: absolute;
left: -15px;
top: 0;
}
ul li:after {
content: "";
display: inline-block;
width: 15px;
height: 100%;
background: rgba(255,255,255,0.5);;
position: absolute;
right: -15px;
top: 0;
}
ul li > div {
display: inline-block;
width: 200px;
height: 200px;
background: blue;
z-index: 1;
margin: 4px;
}
ul > li:first-child:before {
background: rgba(255,255,255,0.5);
width: 1400px;
position: absolute;
left: -1400px;
}
ul > li:last-child:after {
background: rgba(255,255,255,0.5);
width: 1400px;
position: absolute;
right: -1400px;
top: 0;
}
<div>
<ul>
<li><div></div></li>
<li><div></div></li>
</ul>
</div>
答案 2 :(得分:0)
嗯......所有答案都是。最后我找到了另一种解决方案。
#main{
background-image: url('https://www.bensound.com/bensound-img/betterdays.jpg');
width:800px;
height:500px;
background-size:100%;
}
#anyNavi{
height:160px;
width:100%;
/*background-color:rgba(255,255,255,0.5);*/
position:absolute;
margin-top:100px;
}
#anyNavi>div{
width:160px;
height:100%;
float:left;
box-shadow: inset 0 0 0px 20px rgba(255,255,255,0.5);
padding:20px;
}
#anyNavi>div>div{
width:140px;
height:140px;
margin:10px;
background-color:rgba(255,255,255,0.5)
}
&#13;
<div id="main">
<div id="anyNavi">
<div>
<div>
<span>A</span>
</div>
</div>
<div>
<div>
<span>B</span>
</div>
</div>
<div>
<div>
<span>C</span>
</div>
</div>
<div>
<div>
<span>D</span>
</div>
</div>
</div>
</div>
&#13;