在全屏光滑滑块上居中内容
Center content over full screen slick slider
我正在尝试将内容置于全屏滑动滑块 (kenwheeler.github.io/slick/) 的中心,
我尝试使用弹性框,但内容仍保留在视口的边缘,这似乎是 slick[=32] 的 position
标签的问题=] css 但我不知道我做错了什么。
这是我第一次使用 flex,所以我可能遗漏了什么?
HTML
<div class="wrapper">
<div class="main">
<img class="logo" src="img/logo.png">
<h1><a href="#">XXXXXX</a></h1>
<h2>XXXX is a collaboration between <a href="#">XXXX</a> & <a href="#">XXXX</a></h2>
</div>
<div class="background">
<div class="slide" style="background: url('bg/hlg1.jpg') no-repeat center center"></div>
<div class="slide" style="background: url('bg/hlg2.jpg') no-repeat center center"></div>
<div class="slide" style="background: url('bg/hlg3.jpg') no-repeat center center"></div>
<div class="slide" style="background: url('bg/hlg4.jpg') no-repeat center center"></div>
</div>
CSS
*{
min-height: 0;
min-width: 0;
cursor: crosshair;
}
html{
height: 100%;
min-height: 100%;
}
body{
font-family: sans-serif, "Helvetica", "Arial";
font-weight: bold;
font-size: 62.5%;
color: #fff;
text-align: center;
height: 100%;
margin: 0;
padding: 0;
width: 100%;
background: #000;
min-height: 100%;
overflow: hidden;
}
.wrapper {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.slide {
height: 100%;
width: 100%;
background-size: cover !important;
}
.background {
height: 100%;
width: 100%;
z-index: 0;
}
.slick-list,
.slick-track {
height: 100%;
}
.slick-prev {
position: fixed;
left: 2vw;
height: 4vh;
width: 3vw;
z-index: 2;
}
.slick-next {
position: fixed;
right: 2vw;
height: 4vh;
width: 3vw;
z-index: 2;
}
.slick-slider {
margin-bottom: 0;
}
.arrow:hover {
cursor: crosshair;
}
.main {
flex: none;
top: 3vh;
z-index: 1;
max-width: 50%;
position: absolute;
}
.logo {
width: 25vw;
margin: auto;
}
由于该元素(主要)一直保留在那里,您可以使用这些设置:
.main {
position: fixed;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
z-index: 1;
}
我正在尝试将内容置于全屏滑动滑块 (kenwheeler.github.io/slick/) 的中心,
我尝试使用弹性框,但内容仍保留在视口的边缘,这似乎是 slick[=32] 的 position
标签的问题=] css 但我不知道我做错了什么。
这是我第一次使用 flex,所以我可能遗漏了什么?
HTML
<div class="wrapper">
<div class="main">
<img class="logo" src="img/logo.png">
<h1><a href="#">XXXXXX</a></h1>
<h2>XXXX is a collaboration between <a href="#">XXXX</a> & <a href="#">XXXX</a></h2>
</div>
<div class="background">
<div class="slide" style="background: url('bg/hlg1.jpg') no-repeat center center"></div>
<div class="slide" style="background: url('bg/hlg2.jpg') no-repeat center center"></div>
<div class="slide" style="background: url('bg/hlg3.jpg') no-repeat center center"></div>
<div class="slide" style="background: url('bg/hlg4.jpg') no-repeat center center"></div>
</div>
CSS
*{
min-height: 0;
min-width: 0;
cursor: crosshair;
}
html{
height: 100%;
min-height: 100%;
}
body{
font-family: sans-serif, "Helvetica", "Arial";
font-weight: bold;
font-size: 62.5%;
color: #fff;
text-align: center;
height: 100%;
margin: 0;
padding: 0;
width: 100%;
background: #000;
min-height: 100%;
overflow: hidden;
}
.wrapper {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.slide {
height: 100%;
width: 100%;
background-size: cover !important;
}
.background {
height: 100%;
width: 100%;
z-index: 0;
}
.slick-list,
.slick-track {
height: 100%;
}
.slick-prev {
position: fixed;
left: 2vw;
height: 4vh;
width: 3vw;
z-index: 2;
}
.slick-next {
position: fixed;
right: 2vw;
height: 4vh;
width: 3vw;
z-index: 2;
}
.slick-slider {
margin-bottom: 0;
}
.arrow:hover {
cursor: crosshair;
}
.main {
flex: none;
top: 3vh;
z-index: 1;
max-width: 50%;
position: absolute;
}
.logo {
width: 25vw;
margin: auto;
}
由于该元素(主要)一直保留在那里,您可以使用这些设置:
.main {
position: fixed;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
z-index: 1;
}