伪元素 RGBA 箭头颜色与父元素不匹配
Pseudoelement RGBA arrow color doesn't match parent
我正在 div
(#telegram-join
) 下创建一个伪元素箭头,它们都具有 background/border 颜色作为 RGBA 值 (rgba(255, 255, 255, 0.25)
),但是箭头受到的影响不同,看起来比 div
更暗。是因为小吗?我怎样才能匹配它们?谢谢!
HTML
<div id="telegram-join" class="bg-combo">
<h1><i class="fa fa-telegram"></i> Chat with us on Telegram</h1>
</div>
CSS:
.bg-combo {
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
border-radius: 8px;
padding: 5px 10px;
width: fit-content;
background-color: white;
background-color: rgba(255, 255, 255, 0.25);
text-align: center;
}
.bg-combo h1 {
display: inline-block;
font-size: 2em;
line-height: 1.5;
text-transform: uppercase;
}
.bg-combo h1 i {
margin-right: 10px;
}
#telegram-join {
position: relative;
margin: 15px auto 25px;
}
#telegram-join :after {
position: absolute;
top: 100%;
left: 50%;
transform: rotate(-45deg);
transform-origin: 50% 50%;
margin-left: -15px;
margin-top: -15px;
border: 15px solid #fff;
width: 0;
height: 0;
border-color: transparent transparent rgba(255, 255, 255, 0.25) rgba(255, 255, 255, 0.25);
content: '';
}
演示:CodePen
您的(容器的)背景颜色具有 0.25% 的不透明度,伪元素(在该元素内)也具有 0.25% 的不透明度(因此它的背景不再是 body-background,而是容器元素的新背景 - 具有不透明度)。
你可以通过将伪元素的不透明度设置为 0.125% 来解决这个问题:
border-color: transparent transparent rgba(255,255,255,0.125) rgba(255,255,255,0.125);
或者将两个元素的背景设置为您想要的实际颜色:
border-color: transparent transparent #D7D7D7 #D7D7D7;
这是对您的代码笔的更新:
https://codepen.io/anon/pen/eEXqaO
我正在 div
(#telegram-join
) 下创建一个伪元素箭头,它们都具有 background/border 颜色作为 RGBA 值 (rgba(255, 255, 255, 0.25)
),但是箭头受到的影响不同,看起来比 div
更暗。是因为小吗?我怎样才能匹配它们?谢谢!
HTML
<div id="telegram-join" class="bg-combo">
<h1><i class="fa fa-telegram"></i> Chat with us on Telegram</h1>
</div>
CSS:
.bg-combo {
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
border-radius: 8px;
padding: 5px 10px;
width: fit-content;
background-color: white;
background-color: rgba(255, 255, 255, 0.25);
text-align: center;
}
.bg-combo h1 {
display: inline-block;
font-size: 2em;
line-height: 1.5;
text-transform: uppercase;
}
.bg-combo h1 i {
margin-right: 10px;
}
#telegram-join {
position: relative;
margin: 15px auto 25px;
}
#telegram-join :after {
position: absolute;
top: 100%;
left: 50%;
transform: rotate(-45deg);
transform-origin: 50% 50%;
margin-left: -15px;
margin-top: -15px;
border: 15px solid #fff;
width: 0;
height: 0;
border-color: transparent transparent rgba(255, 255, 255, 0.25) rgba(255, 255, 255, 0.25);
content: '';
}
演示:CodePen
您的(容器的)背景颜色具有 0.25% 的不透明度,伪元素(在该元素内)也具有 0.25% 的不透明度(因此它的背景不再是 body-background,而是容器元素的新背景 - 具有不透明度)。
你可以通过将伪元素的不透明度设置为 0.125% 来解决这个问题:
border-color: transparent transparent rgba(255,255,255,0.125) rgba(255,255,255,0.125);
或者将两个元素的背景设置为您想要的实际颜色:
border-color: transparent transparent #D7D7D7 #D7D7D7;
这是对您的代码笔的更新:
https://codepen.io/anon/pen/eEXqaO