【发布时间】:2017-12-12 11:19:51
【问题描述】:
我正在尝试将 div (overlay) 居中。我设法将它在div 居中。但是当父级的内容滚动时它会被切断并且不会粘在中心。不幸的是,overlay 不能只设置为固定:https://stackoverflow.com/a/20621323/1981832。
到目前为止,这是我的代码:
https://codepen.io/anon/pen/PjyYwV
.parent {
position: relative;
height: 50px;
width: 200px;
border: 1px solid blue;
white-space:nowrap;
overflow: scroll;
}
.overlay {
position: absolute;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100px;
width: 100px;
background-color: red;
}
<div class="parent">
<div class="overlay"></div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
【问题讨论】:
标签: css overflow css-position overlay centering