如何在子 div 创建的形状周围应用边框
How to apply border around shape created by child divs
我有许多重叠的 div,我将它们视为一个单一的形状。形状需要是半透明的,所以我将它们放置在父级 div 中,并对父级 div 应用不透明度,如下所示:
#top_housing_bg_div {
opacity: 0.55;
filter: alpha(opacity=55);
}
#top_bg_div {
z-index: 9999;
padding: 3px;
position: absolute;
width: -webkit-calc(100% - 14px - 9px);
width: -moz-calc(100% - 14px - 9px);
width: calc(100% - 14px - 9px);
top: 7px;
left: 7px;
background-color: black;
color: white;
font-size: 12px;
border-radius: 5px;
overflow: hidden;
}
#logo_bg_div {
z-index: 9999;
position: absolute;
top: 12px;
left: 12px;
background-color: black;
border-radius: 5px;
overflow: hidden;
width: 50px;
height: 50px;
}
<div id="top_housing_bg_div">
<div id="top_bg_div">
</div>
<div id="logo_bg_div">
<!--empty for now-->
</div>
</div>
我需要有一个 单 边框,它遵循半透明形状的轮廓(而不是每个子 div 都有自己的边框,侵占进入其他元素的半透明主体)我已经尝试 - 但失败了 - 通过在父元素上使用 box-shadow div,设置边框等
是否有可能实现我想要实现的目标?
由于您已经开始添加特定值(高度、宽度、位置等),您可以使用 pseudo-element
通过将其添加到较小的 div 之上来实现此目标,并且所以,覆盖 div.
的边界
见下文(希望我理解正确你想要什么)
body {
margin:0
}
#logo_bg_div:before {
height: 20px;
top: -1px;
width: calc(100% + 2px);
background: black;
position: absolute;
left: -1px;
content: "";
}
#top_housing_bg_div {
opacity: 0.55;
filter: alpha(opacity=55);
}
#top_bg_div {
z-index: 9999;
padding: 3px;
position: absolute;
width: -webkit-calc(100% - 14px - 9px);
width: -moz-calc(100% - 14px - 9px);
width: calc(100% - 14px - 9px);
top: 7px;
left: 7px;
background-color: black;
color: white;
font-size: 12px;
border-radius: 5px;
overflow: hidden;
border: 1px solid red;
}
#logo_bg_div {
z-index: 9999;
position: absolute;
top: 12px;
left: 12px;
background-color: black;
border-radius: 5px;
width: 50px;
height: 50px;
border: 1px solid red;
position: relative
}
<div id="top_housing_bg_div">
<div id="top_bg_div">
</div>
<div id="logo_bg_div">
<!--empty for now-->
</div>
</div>
我有许多重叠的 div,我将它们视为一个单一的形状。形状需要是半透明的,所以我将它们放置在父级 div 中,并对父级 div 应用不透明度,如下所示:
#top_housing_bg_div {
opacity: 0.55;
filter: alpha(opacity=55);
}
#top_bg_div {
z-index: 9999;
padding: 3px;
position: absolute;
width: -webkit-calc(100% - 14px - 9px);
width: -moz-calc(100% - 14px - 9px);
width: calc(100% - 14px - 9px);
top: 7px;
left: 7px;
background-color: black;
color: white;
font-size: 12px;
border-radius: 5px;
overflow: hidden;
}
#logo_bg_div {
z-index: 9999;
position: absolute;
top: 12px;
left: 12px;
background-color: black;
border-radius: 5px;
overflow: hidden;
width: 50px;
height: 50px;
}
<div id="top_housing_bg_div">
<div id="top_bg_div">
</div>
<div id="logo_bg_div">
<!--empty for now-->
</div>
</div>
我需要有一个 单 边框,它遵循半透明形状的轮廓(而不是每个子 div 都有自己的边框,侵占进入其他元素的半透明主体)我已经尝试 - 但失败了 - 通过在父元素上使用 box-shadow div,设置边框等
是否有可能实现我想要实现的目标?
由于您已经开始添加特定值(高度、宽度、位置等),您可以使用 pseudo-element
通过将其添加到较小的 div 之上来实现此目标,并且所以,覆盖 div.
见下文(希望我理解正确你想要什么)
body {
margin:0
}
#logo_bg_div:before {
height: 20px;
top: -1px;
width: calc(100% + 2px);
background: black;
position: absolute;
left: -1px;
content: "";
}
#top_housing_bg_div {
opacity: 0.55;
filter: alpha(opacity=55);
}
#top_bg_div {
z-index: 9999;
padding: 3px;
position: absolute;
width: -webkit-calc(100% - 14px - 9px);
width: -moz-calc(100% - 14px - 9px);
width: calc(100% - 14px - 9px);
top: 7px;
left: 7px;
background-color: black;
color: white;
font-size: 12px;
border-radius: 5px;
overflow: hidden;
border: 1px solid red;
}
#logo_bg_div {
z-index: 9999;
position: absolute;
top: 12px;
left: 12px;
background-color: black;
border-radius: 5px;
width: 50px;
height: 50px;
border: 1px solid red;
position: relative
}
<div id="top_housing_bg_div">
<div id="top_bg_div">
</div>
<div id="logo_bg_div">
<!--empty for now-->
</div>
</div>