这是一个具有分配给身体的大背景图像的着陆页。它在Chrome和Firefox中运行良好,但它不在Internet Explorer 11的中心。下面是我的代码。请帮忙,谢谢!
HTML
<body>
<div class="landing-bg">
...
<a class="watch-trailer-btn" href="#"><span>Watch Trailer<span></a>
...
</div>
</body>
CSS
.landing-bg{
width: 100%;
height: 1350px;
display: block;
position: relative;
}
.watch-trailer-btn{
position: absolute;
display: inline-block;
width: 180px;
height: 20px;
color: #fff;
margin: 0 auto;
left: 0;
right: 0;
top: 490px;
font-size: 16px;
font-weight: 600;
text-decoration: none;
text-align: center;
text-transform: uppercase;
padding: 20px 0;
border-radius: 8px;
background: #f1d948;
}
更新 w / example
更新 w /直接链接
答案 0 :(得分:2)
垂直居中有各种技术,但在处理绝对定位时,最好使用
top:50%;
left: 50%;
transform:translate(-50%,-50%);
* {
margin: 0;
}
html, body {
height: 100%;
}
.landing-bg{
height: 100%;
position: relative;
background: #ccc;
}
.watch-trailer-btn{
position: absolute;
width: 180px;
height: 20px;
color: #fff;
top:50%;
left: 50%;
transform:translate(-50%,-50%);
font-size: 16px;
font-weight: 600;
text-decoration: none;
text-align: center;
text-transform: uppercase;
padding: 20px 0;
border-radius: 8px;
background: #f1d948;
}
<div class="landing-bg">
<a class="watch-trailer-btn" href="#"><span>Watch Trailer</span></a>
</div>
答案 1 :(得分:0)
你可以这样做:
.landing-bg{
width: 100%;
height: 1350px;
display: block;
position: relative;
}
.watch-trailer-btn{
position: relative; /*Change to relative*/
display: block;
width: 180px;
height: 20px;
color: #fff;
margin: 0 auto;
/*left: 0;*/
/*right: 0;*/
top: 490px;
font-size: 16px;
font-weight: 600;
text-decoration: none;
text-align: center;
text-transform: uppercase;
padding: 20px 0;
border-radius: 8px;
background: #f1d948;
}
你也可以这样做:
.landing-bg{
width: 100%;
height: 1350px;
display: block;
position: relative;
text-align: center; /*Add*/
}
.watch-trailer-btn{
position: relative; /*Change to relative*/
display: inline-box;
width: 180px;
height: 20px;
color: #fff;
/*margin: 0 auto;*/
/*left: 0;*/
/*right: 0;*/
top: 490px;
font-size: 16px;
font-weight: 600;
text-decoration: none;
text-align: center;
text-transform: uppercase;
padding: 20px 0;
border-radius: 8px;
background: #f1d948;
}
答案 2 :(得分:0)
这是HTML:
<div class="modal-box visible form-modal">
<!-- MODAL 01 -->
<div class="inner-container">
<div class="text-container">
<h2>Vivez Lorem</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. .....</p>
</div>
</div>
这是CSS:
.modal-box .inner-container {
position: relative;
width: 465px;
/*width: better put in percentage; */
left: 9px;
background-color: #FFF;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 10%;
margin-bottom: 10%;}
这是工作example。