一个position为fixed的div,宽高自适应,怎样让它水平垂直都在窗口居中?
.div{ position: fixed; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); }
<div id="flex-wrap"> <div class="x"></div> </div> style #flex-wrap { width: 1000px; height: 300px; border: 1px solid red; margin: 0 auto; display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; } .x { width: 100px; height: 100px; background: red; }
声明 欢迎转载,但请保留文章原始出处:) 博客园:https://www.cnblogs.com/chenxiaomeng/
如出现转载未声明 将追究法律责任~谢谢合作