【发布时间】:2016-12-14 08:58:32
【问题描述】:
我已使用vertical-align 将页面内的div 元素(.xasi-modal__login-modal) 对齐到中间,并使用position: relative 从顶部略微偏移-40px。
但是,当.xasi-modal__login-modal 到达/触摸页面顶部时,它会在其上方消失。有没有办法让.xasi-modal__login-modal“触摸”页面顶部时,top: -40px 通过 CSS 或 JS(最好是 CSS)禁用?
这是基本的 HTML 和 CSS:
.modal-login__align{
display: table-cell;
height: 390px;
vertical-align: middle;
}
.xasi-modal__login-modal{
position: relative;
top: -40px;
width: 340px;
height: 390px;
margin: 0 auto;
}
<div class="modal-login__align">
<div class="xasi-modal__login-modal"></div>
</div>
小提琴:https://jsfiddle.net/vde3pwtL/
谢谢。
【问题讨论】:
-
你真正想要达到的目标是什么?
-
@dreamhunter
Is there a way to make it so that when the div "touches" the top of the page, the top: -40px is disabled through CSS or JS (preferably CSS)? -
你能给我们演示一下吗,或者小提琴
-
@JishnuVS 检查新编辑 :)
-
是的,我已经检查了小提琴,有一个红框,里面有一个相对位置的空 div