如何调整CSS以确保箭头与弹出容器显示在同一层中?

izkcnapc  于 2023-06-07  发布在  其他
关注(0)|答案(1)|浏览(131)

我尝试使弹出容器像this example
但它显示像this wrong layer or something
下面是我的代码:
HTML:
<div class="popup-container arrow-top ">
CSS:

.popup-container {
    display: none;
    padding: 20px 10px 0 0;
    position: absolute;
    margin: 0 auto;
    z-index: 999;
    top: 100%;
    right: 50%;
    border-radius: 10px 0px 10px 10px;
    background-color: #FFFFFF;
    box-shadow: rgb(170, 170, 170, 0.6) 0 1px 14px
}

.popup-container:before {
  content: "";
  width: 20px;
  height: 20px;
  transform: rotate(90deg) skewX(45deg) scaleY(cos(45deg));
  box-shadow: 0 1px 14px rgba(0,0,0,.2);
  background-color: #FFFFFF;
  position: absolute  ;
  z-index: 999;
}
.popup-co`ntainer.arrow-top:before {
  right: -3px;
  top: -4px;
}
x4shl7ld

x4shl7ld1#

我相信这就是你想要实现的,你的代码很好,但是你需要调整一些值,以便弹出窗口正确显示。

function showPopup(elem){

  let style = elem.querySelector(".popup-container").classList.toggle("show-popup");
}
body{
  background: whitesmoke;
  
}
.text-with-popup{
  display: inline-block;
  position: relative;
  cursor: pointer;
  user-select:none;
}
.show-popup{
  display: block!important;
}
.popup-container {
    display: none;
    padding: 20px 10px 0 0;
    position: absolute;
    margin: 0 auto;
    z-index: 999;
    top: calc(100% + 16px);
    right: 0;
    width: 100px;
    height: 100px;
    border-radius: 10px 0px 10px 10px;
    background-color: #FFF;
    box-shadow: rgb(170, 170, 170, 0.6) 0 1px 14px
}

.popup-container:before {
  content: "";
  width: 20px;
  height: 20px;
  transform: rotate(90deg) skewX(45deg) scaleY(cos(45deg));
  background-color: #FFF;
  position: absolute  ;
  z-index: 999;
}
.popup-container.arrow-top:before {
  right: -3px;
  top: -4px;
}
<div class="text-with-popup" onclick="showPopup(this)">
 Click here to toggle popup display
 <div class="popup-container arrow-top ">
<div>

相关问题