javascript - 有没有办法制作一个带有 3 个透明框的实心 div?

标签 javascript html css flexbox

我在此处看到了在 div 中为一个透明框编写的代码,
但不是多个,我在让任何事情正常工作时遇到问题..
我有一个 outter div,里面有 3 个盒子,左边、中间和右边有一个边框。
我希望这 3 个框一直透明到主背景,不透明度为 0.3。
是否可以通过我使用的简单编码来完成此操作,而无需 FlexBoxJavaScript
我怎样才能使主 div 中包含 3 个透明框?
这是我的编码和图像..

body {
background-image: url("http://lorempixel.com/500/800/nature/3");
background-color: #ffffff;
background-position: top center;
background-repeat: no-repeat; 
background-size: cover;
height:600px;
width: 100%;
font-size: 20px;
margin: 0px;
padding: 0px;
background-attachment:fixed;
z-index: 9999px;  
}

main {
background: #336699;
width:90%;
height:600px;
margin: 300px 0px 0px 100px;
padding: 10px;
z-index: 1;
}
  
.divl {
background: url("http://lorempixel.com/500/800/nature/3") top center no-repeat, rgba(0,0,0,.3);
background-attachment: fixed;
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
float:left;
text-align:center;
width: 20%;
height: 100%;
margin:0px;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}

.divr {
background: url("http://lorempixel.com/500/800/nature/3") top center no-repeat, rgba(0,0,0,.3);
background-attachment: fixed;
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
float:right;
text-align:center;
width: 20%;
height: 100%;
margin:0px;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}

.divc {
background: url("http://lorempixel.com/500/800/nature/3") top center no-repeat, rgba(0,0,0,.3);
background-attachment: fixed;
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
text-align:center;
text-align:center;
width: 50%;
vertical-align: middle;
height: 100%;
margin:auto;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}
text-align:center;
width: 20%;
height: 100%;
margin:0px;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}

.divr {
background: transparent;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
float:right;
text-align:center;
width: 20%;
height: 100%;
margin:0px;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}

.divc {
background: transparent;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
text-align:center;
text-align:center;
width: 50%;
vertical-align: middle;
height: 100%;
margin:auto;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}
<!DOCTYPE html>
<html>
<head>
</head>
  <body>
    <main>
     <div class="divl">Left <br> Make This Box Transparent..</div>
     <div class="divr">Right <br> Make This Box Transparent..</div>
     <div class="divc">Center <br> Make This Box Transparent..</div>
    </main>
     <div style="clear:both;"></div>
  </body>
</html>

enter image description here

最佳答案

希望这就是您所需要的。当您指定 background-attachment: fixed 时,它相对于窗口而不是父 block 。

body {
background-image: url("http://lorempixel.com/500/800/nature/3");
background-color: #ffffff;
background-position: top center;
background-repeat: no-repeat; 
background-size: cover;
height:600px;
width: 100%;
font-size: 20px;
margin: 0px;
padding: 0px;
background-attachment:fixed;
z-index: 9999px;  
}

main {
background: #336699;
width:90%;
height:600px;
margin: 300px 0px 0px 100px;
padding: 10px;
z-index: 1;
}
  
.divl {
background: url("http://lorempixel.com/500/800/nature/3") top center no-repeat, rgba(0,0,0,.3);
background-attachment: fixed;
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
float:left;
text-align:center;
width: 20%;
height: 100%;
margin:0px;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}

.divr {
background: url("http://lorempixel.com/500/800/nature/3") top center no-repeat, rgba(0,0,0,.3);
background-attachment: fixed;
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
float:right;
text-align:center;
width: 20%;
height: 100%;
margin:0px;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}

.divc {
background: url("http://lorempixel.com/500/800/nature/3") top center no-repeat, rgba(0,0,0,.3);
background-attachment: fixed;
background-size: cover;
opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
text-align:center;
text-align:center;
width: 50%;
vertical-align: middle;
height: 100%;
margin:auto;
padding: 0px;
border: 2px solid black;
border-radius: 5px;
}
<!DOCTYPE html>
<html>
<head>
</head>
  <body>
    <main>
     <div class="divl">Left <br> Make This Box Transparent..</div>
     <div class="divr">Right <br> Make This Box Transparent..</div>
     <div class="divc">Center <br> Make This Box Transparent..</div>
    </main>
     <div style="clear:both;"></div>
  </body>
</html>

关于javascript - 有没有办法制作一个带有 3 个透明框的实心 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54771091/

相关文章:

javascript - NodeJs/Bluebird - 不断收到未处理的拒绝错误

javascript - REST 连接/资源检索混合。使用哪个 Controller ?

javascript - Html anchor 链接和hashbang,简单的解决方案吗?

javascript - 从键值字符串中获取值

CSS背景图片加4个 Angular 的渐变

javascript - 在 <embed> 标记上使用事件处理程序 - 其他选项?

javascript - 垂直文本滚动 jQuery

HTML/CSS 文本未对齐

javascript - 如何将滚动上的淡入淡出链接到滚动的位置?

html - 位置:固定;对我的 CSS 菜单做了一些时髦的事情