2017-02-23 199 views
1

我對flexbox非常陌生,終於可以根據需要讓我的桌面瀏覽器顯示我的項目。但是,在平板電腦/手機視圖中,內容開始重疊,所以我試圖弄清楚如何讓他們響應堆疊在一起的垂直列。我知道這是通過媒體查詢完成的,但我只知道要使用哪些代碼。如果有人對此有任何建議,將不勝感激!謝謝!與flexbox重疊的內容

#recentwork { 
 
    background-color: #1DA0A3; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    flex-direction: row; 
 
    justify-content: flex-start; 
 
    align-items: stretch; 
 
} 
 

 
@media screen and (min-width:600px) { 
 
    #recentwork { 
 
     flex-wrap: nowrap; 
 
    } 
 
} 
 

 
#recentwork a { 
 
    text-decoration: none; 
 
} 
 

 
#recent { 
 
    padding: 20px; 
 
    text-decoration: none; 
 
} 
 

 
#recentwork img { 
 
    padding: 20px; 
 
    width: 200px; 
 
    height: 200px; 
 
} 
 

 
.more { 
 
    text-decoration: none; 
 
    color: black; 
 
} 
 

 
.more:hover { 
 
    color: white; 
 
} 
 

 
.titles { 
 
    text-decoration: none; 
 
    font-size: 20px; 
 
    color: black; 
 

 
} 
 

 
.parentdiv { 
 
    text-decoration: none; 
 
    flex: 1; 
 
    justify-content: space-between; 
 
} 
 

 
@media only screen and (min-width: 760px) { 
 
    #recentwork img { 
 
     width: 300px; 
 
     height: 300px; 
 
     text-decoration: none; 
 
    } 
 
} 
 

 
.content { 
 
    width: 400px; 
 
} 
 

 
@media only screen and (min-width: 760px) { 
 
    #recentwork img { 
 
     width: 300px; 
 
     height: 300px; 
 
    } 
 

 
    #recent{ 
 
     font-size: 50px; 
 
     padding: 40px; 
 
    } 
 
}
<section id="skills"> 
 
    <h2 id="recent">Most Recent Work</h2> 
 
    <div id="recentwork"> 
 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <div class="underline"> 
 
        <h3 class="titles"> Web Design</h3></div> 
 
      </a> 
 
      <p class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p> 
 
      <a href="" class="more"><h3>See More</h3></a> 
 
     </div> 
 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <h3 class="titles"> Photography</h3> 
 
      </a> 
 
      <p class="content">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
      <a href="" class="more"><h3>See More</h3></a> 
 
     </div> 
 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <h3 class="titles"> Print</h3> 
 
      </a> 
 
      <p class="content">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p> 
 
      <a href="" class="more"><h3> See More</h3></a> 
 
     </div> 
 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <h3 class="titles"> Logos</h3> 
 
      </a> 
 
      <p class="content">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p> 
 
      <a href="" class="more"><h3 > See More</h3></a> 
 
     </div> 
 
    </div> 
 
</section>

回答

3

嘗試:
1.刪除flex-wrap: nowrap(閱讀更多有關flex-wrap)。
2.將width: 400px.content元素移動到.parentdiv元素的flex屬性。
3.設置justify-content: center#recentwork元素。

#recentwork { 
 
    background-color: #1DA0A3; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    text-align: center; 
 
    text-decoration: none; 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    flex-direction: row; 
 
    justify-content: center; 
 
    align-items: stretch; 
 
} 
 

 
#recentwork a { 
 
    text-decoration:none; 
 
} 
 

 
#recent { 
 
    padding: 20px; 
 
    text-decoration: none; 
 
} 
 
#recentwork img { 
 
    padding: 20px; 
 
    width: 200px; 
 
    height: 200px; 
 
} 
 

 
.more { 
 
    text-decoration: none; 
 
    color: black; 
 
} 
 

 
.more:hover { 
 
    color: white; 
 
} 
 

 
.titles { 
 
    text-decoration: none; 
 
    font-size: 20px; 
 
    color: black; 
 
} 
 

 
.parentdiv { 
 
    max-width: 100%; 
 
    text-decoration: none; 
 
    flex: 0 1 400px; 
 
    justify-content: space-between; 
 
} 
 

 
@media only screen and (min-width: 760px) { 
 
    #recentwork img { 
 
     width: 300px; 
 
     height: 300px; 
 
     text-decoration:none; 
 
    } 
 
} 
 

 
@media only screen and (min-width: 760px) { 
 
    #recentwork img{ 
 
     width: 300px; 
 
     height: 300px; 
 
    } 
 

 
    #recent{ 
 
     font-size: 50px; 
 
     padding: 40px; 
 
    } 
 
}
<section id="skills"> 
 
    <h2 id="recent">Most Recent Work</h2> 
 
    <div id="recentwork"> 
 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <div class="underline"> 
 
        <h3 class="titles"> Web Design</h3> 
 
       </div> 
 
      </a> 
 
      <p class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. </p> 
 

 
      <a href="" class="more"><h3 > See More</h3></a> 
 
     </div> 
 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <h3 class="titles"> Photography</h3> 
 
      </a> 
 
      <p class="content">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p> 
 
      <a href="" class="more"><h3 > See More</h3></a> 
 
     </div> 
 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <h3 class="titles"> Print</h3> 
 
      </a> 
 
      <p class="content">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p> 
 
      <a href="" class="more"><h3 > See More</h3></a> 
 
     </div> 
 

 
     <div class="parentdiv"> 
 
      <a href="https://media.flaticon.com/img/tumble.svg" data-lightbox="website" data-title=""> 
 
       <img src="https://media.flaticon.com/img/tumble.svg" width="200px" height="200px"> 
 
       <h3 class="titles"> Logos</h3> 
 
      </a> 
 
      <p class="content">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p> 
 
      <a href="" class="more"><h3 > See More</h3></a> 
 
     </div> 
 
    </div> 
 
</section>