【发布时间】:2021-03-28 02:48:23
【问题描述】:
我有以下代码将图像从底部转换到顶部,但我需要将其居中。在我的同事屏幕上,它居中,但在我的屏幕上,它更多地位于顶部。有没有办法确保它在所有屏幕上居中? (不会破坏我的 CSS 的其余部分,哈哈)
JS:
const showAlerts = () => {
getElements().forEach((alert) => {
focus-alert.style.display = "";
focus-alert.style.bottom = "25%"; // <--- *This is what does the transition to the 'center'*
});
};
HTML
<div class="mobile-wrapper">
<div id="mobile" class="focus-alert">
<img src="assets/images/mobile-moments-away-img.png">
<img id="mobile-close-btn" class="mobile-close-btn" src="assets/images/mobile-close-button-img.png" onclick="handleClose(this)">
<img id="mobile-continue-btn" class="mobile-continue-btn" src="assets/images/mobile-continue-now-img.png" onclick="handleGetQuotesClick(this)">
</div>
</div>
CSS:
.mobile-wrapper {
display: flex;
align-items: center;
justify-content: center;
/*height: 100vh;*/
}
#mobile {
position: fixed;
z-index: 9999;
transition: all 1s ease;
}
如果我将focus-alert.style.bottom = 25% 更改为20%,它会在我的屏幕上居中,但显然不适合他。所以只是想知道如何使它在中间居中?
【问题讨论】:
标签: css css-transitions center