0

is it possible to create transparent borders on elements that are in a container with a background? Tried it with box-shadows inset and outset. But it doesnt work...

Current code:

#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>

Current: enter image description here How it should look like: enter image description here

Hamta
  • 43
  • 1
  • 4

3 Answers3

0

Here is an idea using linear-gradient to simulate this behavior but this need to be applied on the container:

#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;;
}
<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>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
0

I managed to produce it by playing around with psuedo-classes and some absolute positioning. Didn't code it responsive though.

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>
Kidkie
  • 83
  • 1
  • 9
0

Well... ty all for the answers. Finally ive found another solution.

#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)
 
}
<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>
Hamta
  • 43
  • 1
  • 4