2017-02-23 137 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>