我修改了您的代码。试试这个
.container {
position: relative;
width: 100%;
height:100vh;
}
.btn-container{
display:flex;
justify-content: center;
align-items: center;
height:100%;
width:100%;
}
.container img {
width: 150%;
opacity: 0.85;
height: auto;
}
.container .btn {
opacity: 0.8;
filter: alpha(opacity=80);
background-color: #555;
color: white;
font-size: 1.5em;
padding: 12px 24px;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
line-height: 100%;
margin: 0 30px;
}
我添加了一个名称为btn-container的div,该div包含按钮并位于中间
<div class="container">
<img img="" src="" alt="">
<div class="btn-container">
<a href="" class="btn">Registracija Kaune</a>
<a href="" class="btn">Registracija Vilniuje</a>
</div>
</div>
,
尝试移除高度:10%;来自.container .btn,因为您为此添加了填充
.container {
position: relative;
width: 100%;
max-width: 2400px;
}
.container img {
width: 150%;
opacity: 0.85;
height: auto;
}
.container .btn {
width: 30%;
/* height: 10%; */ /* Remove this height */
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 70%;
transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
background-color: #555;
color: white;
font-size: 2vw;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
.container .btns {
width: 30%;
/* height: 10%; */ /* Remove this height */
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 30%;
transform: translate(-50%,-50%);
background-color: #555;
color: white;
font-size: 2vw;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
<div class="container">
<img img="" src="" alt="">
<a href="" class="btn">Registracija Kaune</a>
<a href="" class="btns">Registracija Vilniuje</a>
</div>
,
许多解决方案
将图像设为容器的背景图像,然后使用flexbox
或
将图像位置设为绝对,在按钮上添加边距,然后使用下面的esample这样的flaxbox
.container {
display: flex;
justify-content: space-evenly;
width: 100%;
max-width: 2400px;
position: relative;
overflow: hidden;
}
.container img {
position: absolute;
width: 100%;
opacity: 0.85;
height: auto;
}
.container .btn,.container .btns{
display: flex;
align-items: center;
justify-content: center;
width: 30%;
height: 10%;
min-height: calc(2vw + 24px);
opacity: .8;
background-color: #555;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
text-decoration: none;
margin: 40% 0;
}
.container .btn {
left: 70%;
font-size: 1.5vw;
}
.container .btns {
left: 30%;
font-size: 2vw;
}
<div class="container">
<img src="https://data.whicdn.com/images/50959200/original.jpg" alt="">
<a href="" class="btns">Registracija Vilniuje</a>
<a href="" class="btn">Registracija Kaune</a>
</div>
,
我摆脱了按钮上的宽度和高度,并将填充更改为%,这样它可以响应,并且在调整大小时,文本将始终居中显示。
.container {
position: relative;
width: 100%;
max-width: 2400px;
}
.container img {
width: 150%;
opacity: 0.85;
height: auto;
}
.container .btn {
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 70%;
transform: translate(-50%,-50%);
background-color: #555;
color: white;
font-size: 1.5vw;
padding: 1% 5%;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
.container .btns {
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 30%;
transform: translate(-50%,-50%);
background-color: #555;
color: white;
font-size: 2vw;
padding: 1% 5%;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
<div class="container">
<img img="" src="" alt="">
<a href="" class="btn">Registracija Kaune</a>
<a href="" class="btns">Registracija Vilniuje</a>
</div>
,
只需将bootstrap类添加到按钮的标签中
class =“ text-center”;
本文链接:https://www.f2er.com/3098669.html