我試著做一個像這個例子一樣的彈出容器
但是它顯示像這個錯誤的層或什么的
以下是我的代碼:
HTML:
& ltdiv class = & quot彈出容器頂部箭頭& quot& gt
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;
}
我相信這就是你想要實現的,你的代碼很好,但是你需要調整一些值來讓你的彈出窗口正確顯示。
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>