2016-04-01 236 views
0

我試着像以下箭頭放置在中間的顯示器一樣根據主容器的高度進行顯示。以css中父級的高度爲中心兒童

Display Im trying to realize

除了一個事實,即林無法放置箭頭在中間,我也不能增加圖標的高度(從http://fortawesome.github.io/Font-Awesome/

但是這是我迄今實現:

What I have done

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

 
/*Text over image*/ 
 
h2.header { 
 
    bottom: 0; 
 
    position: absolute; 
 
    text-align: center; 
 
\t margin: 0; 
 
    width: 100%; 
 
    background-color: rgba(0,0,0,0.7); 
 
\t padding: 35px 0px 35px 0px; 
 
\t font-family: FeaturedItem; 
 
} 
 
.item { 
 
    position: relative; 
 
\t 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{ 
 
\t font-size: 30px; 
 
\t margin-left: -40px; 
 
\t top: 50%; 
 
} 
 

 
.carousel-nav-right{ 
 
\t font-size: 30px; 
 
\t margin-right: -40px; 
 
\t top: 50%; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 
    <head> 
 
     <title>owlcarousel</title> 
 
\t \t <meta charset="UTF-8" /> 
 
\t \t <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
 
\t \t <link rel="stylesheet" type="text/css" href="css/style.css" /> 
 
\t \t <link rel="stylesheet" type="text/css" href="css/owl.carousel.css" /> 
 
\t \t <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"> 
 
    </head> 
 
\t 
 
    <body> 
 
\t \t <div class="container"> 
 
\t \t \t <div class="carousel"> 
 
\t \t \t 
 
\t \t \t \t <div class="item"> 
 
\t \t \t \t \t <img src="images/2.jpg" alt="" /> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <div class="overlay"> 
 
\t \t \t \t \t \t <h2 class="header">A Movie in the Park: Kung Fu Panda</h2> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t \t <div class="item"> 
 
\t \t \t \t \t <img src="images/1.jpg" alt="" /> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <div class="overlay"> 
 
\t \t \t \t \t \t <h2 class="header">A Movie in the Park: Kung Fu Panda</h2> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t \t <div class="item"> 
 
\t \t \t \t \t <img src="images/3.jpg" alt="" /> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <div class="overlay"> 
 
\t \t \t \t \t \t <h2 class="header">A Movie in the Park: Kung Fu Panda</h2> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t \t <div class="item"> 
 
\t \t \t \t \t <img src="images/4.jpg" alt="" /> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <div class="overlay"> 
 
\t \t \t \t \t \t <h2 class="header">A Movie in the Park: Kung Fu Panda</h2> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t \t <div class="item"> 
 
\t \t \t \t \t <img src="images/5.jpg" alt="" /> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <div class="overlay"> 
 
\t \t \t \t \t \t <h2 class="header">A Movie in the Park: Kung Fu Panda</h2> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t \t <div class="item"> 
 
\t \t \t \t \t <img src="images/6.jpg" alt="" /> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <div class="overlay"> 
 
\t \t \t \t \t \t <h2 class="header">A Movie in the Park: Kung Fu Panda</h2> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t </div> 
 
\t \t </div> 
 
\t \t <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
\t \t <script src="js/owl.carousel.min.js"></script> 
 
\t \t <script> 
 
\t \t \t (function($){ 
 
\t 
 
\t \t \t \t $('.carousel').owlCarousel({ 
 
\t \t \t \t \t items: 3, 
 
\t \t \t \t \t loop:true, 
 
\t \t \t \t \t margin:10, 
 
\t \t \t \t \t nav:true, 
 
\t \t \t \t \t 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>"], 
 
\t \t \t \t \t dots: true, 
 
\t \t \t \t \t responsive:{ 
 
\t \t \t \t \t \t 0:{ 
 
\t \t \t \t \t \t \t items:1 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t \t 430:{ 
 
\t \t \t \t \t \t \t items:2 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t \t 800:{ 
 
\t \t \t \t \t \t \t items:3 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t \t 1400:{ 
 
\t \t \t \t \t \t \t items:4 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t \t 1800:{ 
 
\t \t \t \t \t \t \t items:6 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t \t 2400:{ 
 
\t \t \t \t \t \t \t items:7 
 
\t \t \t \t \t \t }, 
 
\t \t \t \t \t \t 3000:{ 
 
\t \t \t \t \t \t \t items:9 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 
\t \t \t \t }) 
 
\t \t \t \t 
 
\t \t \t })(jQuery); 
 
\t \t </script> 
 
\t </body> 
 
</html>

回答

1

如果您可以在箭頭上設置固定高度,您可以使用絕對位置和邊緣技巧執行以下操作;

注意 - 這可能還需要在.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; 
} 
+0

感謝您的幫助。它現在正在工作,但Iam仍然無法增加我的圖標所在的跨度高度。請幫我解決這個問題。 –

+0

對不起,我不是100%確定你的意思。 – Lewis

+0

我仍然無法增加prev/next按鈕的高度 –

1

如果你可以使用Flexbox的(browser support是相當不錯的這些天),這應該是很容易,即使箭頭的高度是不知道:

.container { 
 
    display: flex; 
 
    flex-direction: row; 
 
} 
 

 
.image { 
 
    width: 200px; 
 
    height: 300px; 
 
    background: #ffc; 
 
} 
 

 
.arrow { 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
} 
 

 
.button { 
 
    flex: 0 0 auto; 
 
    background: #fcc; 
 
}
<div class="container"> 
 
    <div class="arrow"> 
 
    <span class="button">&lt;</span> 
 
    </div> 
 
    <div class="image"> 
 
    </div> 
 
    <div class="image"> 
 
    </div> 
 
    <div class="arrow"> 
 
    <span class="button">&gt;</span> 
 
    </div> 
 
</div>

+0

感謝您的幫助。它現在正在工作,但Iam仍然無法增加我的圖標所在的跨度高度。請幫我解決這個問題。 –

+0

您可以在跨度上設置一個高度。 – Thomas

0

外貌對我來說就像你錯過了CSS導航元素(.carousel-nav-right和carousel-nav-left)中的'position'元素。此外,使用Chrome瀏覽器,您可以右鍵單擊導航元素,單擊「檢查元素」並查看CSS路徑,以確保您擁有正確的CSS選擇器。可能需要考慮很多嵌套元素。