React-bootstrap Popover箭头的颜色在箭头垂直与水平时相反。

huangapple go评论58阅读模式
英文:

React-bootstrap Popover arrow colors are inverted when arrow is vertical vs. horizontal

问题

我有一个使用自定义样式的 react-bootstrap 弹出框(Popover)组件,其中箭头是灰色且透明度为 50%。CSS 如下所示:

.popover .popover-arrow::before, .popover .popover-arrow::after {
  border-color: #212529 !important;
  opacity: 0.5;
  border-top-color: transparent !important;
  border-bottom-color: transparent !important;
}

这对水平箭头(当弹出框位于目标的左侧或右侧时)效果良好:

React-bootstrap Popover箭头的颜色在箭头垂直与水平时相反。

然而,当箭头为垂直方向(弹出框位于目标的上方或下方)时,颜色发生反转,导致箭头变成透明的,而背景是灰色的且透明度为 50%:

React-bootstrap Popover箭头的颜色在箭头垂直与水平时相反。

我的问题是,为什么会发生这种反转,以及我应该如何修复它?

英文:

I have a react-bootstrap Popover component with custom styling for the arrow (gray color and 50% opacity). The CSS is as follows:

.popover .popover-arrow::before, .popover .popover-arrow::after {
  border-color: #212529 !important;
  opacity: 0.5;
  border-top-color: transparent !important;
  border-bottom-color: transparent !important;
}

This works fine for horizontal arrows (when the Popover is left or right of the target):

React-bootstrap Popover箭头的颜色在箭头垂直与水平时相反。

However, when the arrow is vertical (Popover above or below the target), the colors are inverted to give a transparent arrow on a grey background:

React-bootstrap Popover箭头的颜色在箭头垂直与水平时相反。

My question is, why does this inversion happen and what can I do to fix it?

答案1

得分: 0

以下是已翻译的CSS部分:

.popover .popover-arrow {
	display: block;
	opacity: 0.75;
}

.popover[x-placement^=top]>.popover-arrow:after {
    border-top-color: #212529;
}

.popover[x-placement^=bottom]>.popover-arrow:after {
    border-bottom-color: #212529;
}

.popover[x-placement^=right]>.popover-arrow:after {
    border-right-color: #212529;
}

.popover[x-placement^=left]>.popover-arrow:after {
    border-left-color: #212529;
}

感谢Michal Duszak提供的这个片段,它为我提供了一些启发。

英文:

Eventually I managed to fix this with the following CSS:

.popover .popover-arrow {
	display: block;
	opacity: 0.75;
}

.popover[x-placement^=top]>.popover-arrow:after {
    border-top-color: #212529;
}

.popover[x-placement^=bottom]>.popover-arrow:after {
    border-bottom-color: #212529;
}

.popover[x-placement^=right]>.popover-arrow:after {
    border-right-color: #212529;
}

.popover[x-placement^=left]>.popover-arrow:after {
    border-left-color: #212529;
}

Thanks to Michal Duszak for this snippet which gave me something to go on.

huangapple
  • 本文由 发表于 2023年2月19日 22:57:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75501013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定