2017-02-03 70 views
0

我有一個flexbox充滿圖像,它們都將具有文本頂部的文本。我被困在試圖讓文本響應。文字需要留在div的內部並用圖像調整大小。任何人有任何提示或技巧如何最好地完成這一點?我的完整代碼示例如下鏈接。CSS flexbox中的圖像響應文本

enter image description here

<div class="container"> 
<div class="flex-row row"> 
    <div class="flex-column"> 
      <div class=" welcome overlay-parent"> 
        <img src="http://placehold.it/548x227"> 
        <div class="overlay-text"><h1>Welcome to My Place</h1></div> 
       </div> 
    <div><img src="http://placehold.it/548x459"></div> 
    </div> 
    <div class="flex-column"> 
    <div class="flex-row"> 
     <div><img src="http://placehold.it/812x459"></div> 
    </div> 
    <div class="flex-row"> 
     <div class="feature-about overlay-parent"> 
     <img src="http://placehold.it/406x227"> 
       <div class="overlay-text"><h2>About Something</h2> 
        <p>It’s the latest lorem ipsum dolor sit brief intro to the park goes here. ounded in 2016. It’s the latest lorem ipsum dolor sit brief intro to the park goes here. </p> </div> 
     </div> 
      <div><img src="http://placehold.it/406x227"></div> 
    </div> 
    </div> 
</div> 
<div class="flex-row row"> 
    <div><img src="http://placehold.it/812x459"></div> 
    <div><img src="http://placehold.it/548x459"></div> 
</div> 
</div> 

https://codepen.io/enigmas2/pen/ygKmGX

+0

使用媒體查詢來控制字體大小 – ZimSystem

+0

我正朝着@ZimSystem的方向前進,但想看看是否有選項。 – Johanna

回答

2

您可以使用視單位。這些將隨着視圖的大小而調整。

$(document).foundation();
*{box-sizing: border-box;} 
 
:root {font-size: calc(1vw + .1vmin);} 
 
.container{ 
 
    max-width: 1360px; 
 
    margin: 0 auto; 
 
} 
 

 
img{ 
 
    border:2px solid white; 
 
} 
 

 
.flex-row { 
 
    justify-content: flex-start; 
 
    align-items: flex-start; 
 
    width: 100%; 
 
    display: flex; 
 
    flex-direction: row; 
 
} 
 

 
.flex-column{ 
 
    align-items: flex-start; 
 
    height: 100%; 
 
    max-width: 1360px; 
 
    display: flex; 
 
    flex-direction: column; 
 
} 
 

 
.overlay-parent { 
 
    position: relative; 
 
} 
 

 
.overlay-text { 
 
    position: absolute; 
 
    left: 0; 
 
    top: 0; 
 
    width: 100%; 
 
} 
 

 
.welcome h1 { 
 
    padding: 20px 0 0 25px; 
 
    line-height: .8em; 
 
    font-size: 5em; 
 

 
} 
 

 
.feature-about h2, p { 
 
\t padding: 0 5px 0 20px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdn.jsdelivr.net/foundation/6.2.4/foundation.min.js"></script> 
 
<div class="container"> 
 
<div class="flex-row row"> 
 
    <div class="flex-column"> 
 
\t \t \t <div class=" welcome overlay-parent"> \t 
 
\t \t \t \t <img src="http://placehold.it/548x227"> 
 
\t \t \t \t \t <div class="overlay-text"><h1>Welcome to My Place</h1></div> 
 
\t \t \t \t </div> 
 
    <div><img src="http://placehold.it/548x459"></div> 
 
    </div> 
 
    <div class="flex-column"> 
 
    <div class="flex-row"> 
 
     <div><img src="http://placehold.it/812x459"></div> 
 
    </div> 
 
    <div class="flex-row"> 
 
     <div class="feature-about overlay-parent"> 
 
     <img src="http://placehold.it/406x227"> 
 
     \t \t \t <div class="overlay-text"><h2>About Something</h2> 
 
\t \t \t \t \t <p>It’s the latest lorem ipsum dolor sit brief intro to the park goes here. ounded in 2016. It’s the latest lorem ipsum dolor sit brief intro to the park goes here. </p> </div> 
 
     </div> 
 
\t \t <div><img src="http://placehold.it/406x227"></div> 
 
    </div> 
 
    </div> 
 
</div> 
 
<div class="flex-row row"> 
 
    <div><img src="http://placehold.it/812x459"></div> 
 
    <div><img src="http://placehold.it/548x459"></div> 
 
</div> 
 
</div>

+0

熱潮!這是光滑的@邁克爾! – Johanna

+0

@Johanna這是熱辣的新熱點!使響應文本變得輕鬆。 –

+0

心靈公式爆發!謝謝! – Johanna

0

你可以嘗試定義您的字體大小相對於視口的寬度。例如,嘗試在H1上設置font-size: 5vw