css - 页面中间的 CSS 中心图像动画
问题描述
我有以下代码将图像从底部转换到顶部,但我需要将其居中。在我的同事屏幕上,它居中,但在我的屏幕上,它更多地位于顶部。有没有办法确保它在所有屏幕上居中?(不会破坏我的 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%
中心,但显然不会为他。所以只是想知道如何使它在中间居中?
解决方案
您好,您可以尝试margin:50% auto 50% auto;
图像样式,将其添加到您的脚本中,这将帮助您将图像置于屏幕中间
推荐阅读
- excel - 如何将多列excel表格转换为附有标题的单列
- java - 在不更改类型的情况下在日期字段中发送没有“Z”的 xml 请求
- javascript - 表头上的自定义排序和功能
- python - Dask:合并后写入 csv 非常慢(python)
- reactjs - 什么是 useState 第二个参数?为什么我有“不是函数”错误
- java - Spring Boot kafka 消费者,未触发的两个侦听器之一
- java - 如何使用 java 自定义序列化此测试类以平面结构(未包装的 XYZ 类)的形式获取输出
- reactjs - 在 Jest / jsdom / React 测试库中触发键盘事件未按预期工作
- java - 无法使用 JpaRepository 执行更新
- python - 用其他数据框中的值替换值