使用flexbox重叠内容

时间:2017-02-23 14:32:54

标签: html css css3 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>

1 个答案:

答案 0 :(得分:3)

尝试:
 1.删​​除flex-wrap: nowrap(详情了解flex-wrap)  2.将width: 400px.content元素移至.parentdiv元素的flex属性。
 3.为justify-content: center元素设置#recentwork

&#13;
&#13;
#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;
    }
}
&#13;
<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>
&#13;
&#13;
&#13;