【发布时间】:2017-06-09 12:47:20
【问题描述】:
.msg-ex {
display: flex;
align-items: center;
justify-content: center;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
.msg-ex .msg-ex-overlay {
position: relative;
background-color: rgba(0, 0, 0, 0.4);
width: 100%;
height: 100%;
opacity: 0;
z-index: 2;
}
.msg-ex .msg-ex-overlay .msg-ex-cta {
position: absolute;
color: red;
background-color: #DCE0E3;
font-size: 1.1em;
font-weight: 700;
border-radius: 18px;
height: 38px;
width: 100px;
cursor: pointer;
top: 50%;
left: 50%;
transform: translateX(-48%) translateY(-47%);
}
.msg-ex .msg-ex-overlay:hover {
opacity: 1;
}
.msg-ex-box {
position: relative;
background-color: $voiceColor;
}
.msg-ex-box::after {
content: '';
bottom: 0;
right: 0;
width: 32px;
height: 32px;
background-image: url(../pics/data/img1.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
z-index: 1;
}
}
.msg-ex-voice:hover {
background-color: rgba(0, 0, 0, 0.4);
}
<div class="msg-ex msg-ex-box">
<div class="msg-ex-overlay">
<button class="msg-ex-cta">Show</button>
</div>
</div>
我使用transform: translateX(-48%) translateY(-47%); 将我的“显示”按钮定位在中心,但理想情况下它应该是transform: translateX(50%) translateY(50%);,它位于中心 - 无法弄清楚我做错了什么。请帮忙。
【问题讨论】:
标签: html css flexbox css-position