gpt4 book ai didi

javascript - 根据CSS中 parent 的高度使 child 居中

转载 作者:太空宇宙 更新时间:2023-11-04 02:31:57 28 4
gpt4 key购买 nike

我正在尝试重新显示如下所示的显示,其中箭头根据主容器的高度放置在中间。

Display Im trying to realize

除了无法将箭头放在中间之外,我也无法增加图标的高度(来自 http://fortawesome.github.io/Font-Awesome/)

然而,这是我到目前为止所意识到的:

What I have done

.container {
width: 90%;
margin: 0 auto;
}

/*Text over image*/
h2.header {
bottom: 0;
position: absolute;
text-align: center;
margin: 0;
width: 100%;
background-color: rgba(0,0,0,0.7);
padding: 35px 0px 35px 0px;
font-family: FeaturedItem;
}
.item {
position: relative;
width: 100%;
}

.item img {
display: block;
max-width:100%;
}

.item .overlay {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
color:white;
}

/*Carousel Nav Buttons*/

.carousel-nav-left{
font-size: 30px;
margin-left: -40px;
top: 50%;
}

.carousel-nav-right{
font-size: 30px;
margin-right: -40px;
top: 50%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>owlcarousel</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/owl.carousel.css" />
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
</head>

<body>
<div class="container">
<div class="carousel">

<div class="item">
<img src="images/2.jpg" alt="" />

<div class="overlay">
<h2 class="header">A Movie in the Park: Kung Fu Panda</h2>
</div>
</div>

<div class="item">
<img src="images/1.jpg" alt="" />

<div class="overlay">
<h2 class="header">A Movie in the Park: Kung Fu Panda</h2>
</div>
</div>

<div class="item">
<img src="images/3.jpg" alt="" />

<div class="overlay">
<h2 class="header">A Movie in the Park: Kung Fu Panda</h2>
</div>
</div>

<div class="item">
<img src="images/4.jpg" alt="" />

<div class="overlay">
<h2 class="header">A Movie in the Park: Kung Fu Panda</h2>
</div>
</div>

<div class="item">
<img src="images/5.jpg" alt="" />

<div class="overlay">
<h2 class="header">A Movie in the Park: Kung Fu Panda</h2>
</div>
</div>

<div class="item">
<img src="images/6.jpg" alt="" />

<div class="overlay">
<h2 class="header">A Movie in the Park: Kung Fu Panda</h2>
</div>
</div>

</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script>
(function($){

$('.carousel').owlCarousel({
items: 3,
loop:true,
margin:10,
nav:true,
navText: ["<span class='carousel-nav-left'><i class='fa fa-chevron-left'></i></span>","<span class='carousel-nav-right'><i class='fa fa-chevron-right'></i></span>"],
dots: true,
responsive:{
0:{
items:1
},
430:{
items:2
},
800:{
items:3
},
1400:{
items:4
},
1800:{
items:6
},
2400:{
items:7
},
3000:{
items:9
}
}
})

})(jQuery);
</script>
</body>
</html>

最佳答案

如果可以在箭头上设置固定高度,则可以使用绝对位置和边距技巧来执行以下操作;

注意 - 这可能还需要 .container 上的固定高度。

.container {
width: 90%;
margin: 0 auto;
position: relative;
}

.carousel-nav-left{
height: 30px;
font-size: 30px;
position: absolute;
top: 0%;
bottom: 0%;
margin: auto 0;
margin-left: -40px;
}

.carousel-nav-right{
height: 30px;
font-size: 30px;
position: absolute;
top: 0%;
bottom: 0%;
margin: auto 0;
margin-right: -40px;
}

关于javascript - 根据CSS中 parent 的高度使 child 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36353585/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com