我试图纵向和横向集中,但没有成功:
https://jsfiddle.net/szg7hhph/1/embedded/result/
HTML:
<div id="new__event">
<div class="target">
<h2>Free Pass</h2>
</div>
</div>
body {
margin: 0;
}
#new__event {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
pointer-events: none;
opacity: 0;
transition: opacity 200ms;
}
#new__event {
pointer-events: all;
opacity: 1;
}
#new__event .target {
cursor: pointer;
position: relative;
display: inline-block;
padding: 48px;
width: 50%;
margin: 0 auto;
box-shadow: 0px 12px 24px rgba(0, 0, 0, 0.2);
background: white;
color: #f98835;
margin-top: 1.5rem;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了margin 0 auto,text-align,vertical-align,但是这个框仍然存在于角落里.
更改position的#new_event .target到absolute,去除margin-top性能,并添加了以下新特性:
box-sizing: border-box;
left: 25%;
top: 50%;
transform: translateY(-50%);
Run Code Online (Sandbox Code Playgroud)
这应该从IE 9开始.
结果

| 归档时间: |
|
| 查看次数: |
5744 次 |
| 最近记录: |