该部分在Mozilla中消失了

时间:2019-04-25 11:15:58

标签: html css css3 flexbox

在某些媒体查询(仅影响flex-direction max-width:1200px)之后,我有一个在mozilla中消失的部分。

我认为这可能与图像及其大小有关,但我不确定。此外,我认为我的代码不适合我想做的事情,但这就是我能想到的。因此,如果您认为有其他更好的方式来编写本节,将不胜感激。

.gallery {
    width: 100%;
    color: var(--primary-color);
}


.gallery-container {
    width: 100%;
    padding: 120px 15px 0 15px;
    display: flex;
    position: relative;
}


.gallery-container-text {
    flex: 0 0 33.33%;
    min-width: 33%;
}


.gallery-container-text h2 {
    font-size: 40px;
    padding: 30px 0;
    font-weight: 400;
}


.gallery-container-text h4 {
    font-size: 16px;
    line-height: 1.5;
    padding-right: 30px;
    font-weight: 400;
}


.gallery-container-image {
    flex: 0 0 66.66%;
    min-width: 66%;
    height: 400px;
    max-height: 60vh;
    overflow: hidden;
    position: relative;
    width: 100%;
}
.div-containers {
    position: absolute;
    top: -20px;
    bottom: 0;
    left: -20px;
    right: -20px;
}

.gallery-container-image img {
    box-shadow: 0 5px 23px 0 rgba(0,0,0,.15);
    max-width: 100%;
    height: auto;
}


.gallery-container-image div div:nth-child(1) {
    position: absolute;
    top: 20px;
    left: calc(28.25% + 20px);
    width: 42%;
    -webkit-animation: fadeup .5s ease-in-out .9s;
       -moz-animation: fadeup .5s ease-in-out .9s;
         -o-animation: fadeup .5s ease-in-out .9s;
            animation: fadeup .5s ease-in-out .9s;
    opacity: 0;
    animation-fill-mode: forwards;
}
.gallery-container-image div div:nth-child(2) {
    position: absolute;
    top: calc(27% + 20px);
    left: 20px;
    width: 39%;
    -webkit-animation: fadeup .5s ease-in-out .6s;
       -moz-animation: fadeup .5s ease-in-out .6s;
         -o-animation: fadeup .5s ease-in-out .6s;
            animation: fadeup .5s ease-in-out .6s;
    opacity: 0;
    animation-fill-mode: forwards;
}
.gallery-container-image div div:nth-child(3) {
    position: absolute;
    top: calc(52% + 20px);
    left: calc(22% + 20px);
    width: 54%;
    -webkit-animation: fadeup .5s ease-in-out .3s;
       -moz-animation: fadeup .5s ease-in-out .3s;
         -o-animation: fadeup .5s ease-in-out .3s;
            animation: fadeup .5s ease-in-out .3s;
    opacity: 0;
    animation-fill-mode: forwards;
}
.gallery-container-image div div:nth-child(4) {
    position: absolute;
    top: calc(36% + 20px);
    right: 20px;
    width: 40%;
    -webkit-animation: fadeup .5s ease-in-out;
       -moz-animation: fadeup .5s ease-in-out;
         -o-animation: fadeup .5s ease-in-out;
            animation: fadeup .5s ease-in-out;
    opacity: 0;
    animation-fill-mode: forwards;
}


@keyframes fadeup {
    0% {
        opacity: 0;
        -webkit-transform: translate3d(0, 100%,0);
           -moz-transform: translate3d(0, 100%,0);
             -o-transform: translate3d(0, 100%,0);
                transform: translate3d(0, 100%,0);
    }
    100% {
        opacity: 1;
        -webkit-transform: none;
           -moz-transform: none;
             -o-transform: none;
                transform: none;
    }
}
@media screen and (max-width:1200px) {
    .gallery-container {
        flex-direction: column;
        padding: 30px 15px 0 15px;
    }
    .gallery-container-text {
        flex: 0 0 100%;
        min-width: 100%;
    }
    .gallery-container-text h2 {
        text-align: center;
        padding: 30px 0;
    }
    .gallery-container-text h4 {
        padding-right: 0;
        text-align: center;
        margin-bottom: 30px;
    }
    .gallery-container-image {
        flex: 0 0 100%;
        min-width: 100%;
    }
}
@media screen and (max-width: 600px) {
    .gallery-container-image {
        max-height: 30vh;
    }
}
@media screen and (max-width: 400px) {
    .gallery-container-image {
        max-height: 25vh;
    }
    .gallery-container-text h2 {
        font-size: 30px;
    }
    .gallery-container-text h4 {
        font-size: 14px;
    }
}
<section class="gallery">
    <div class="gallery-container">
        <div class="gallery-container-text">
            <h2>Popular Recipes</h2>
            <h4>Some of our popular recipes with our great selection of Tasties Recipes</h4>
        </div>
        <div class="gallery-container-image">
            <div class="div-containers">
                    <div>
                            <img width="446" height="295" src="https://i.imgur.com/6m3Yrou.jpg" alt="image">
                        </div>
                        <div>
                            <img width="412" height="456" src="https://i.imgur.com/mWYieLP.jpg" alt="image">
                        </div>
                        <div>
                            <img width="572" height="416" src="https://i.imgur.com/sfQ5PyR.jpg" alt="image">
                        </div>
                        <div>
                            <img width="434" height="444" src="https://i.imgur.com/Ug7kH7b.jpg" alt="image">
                        </div>
            </div>
            
        </div>
    </div>
</section>

1 个答案:

答案 0 :(得分:1)

您在“ flex: 0 0 100%;”中使用“ .gallery-container-image”时遇到的问题应在“ flex: 0 0 auto;”下的“ @media screen and (max-width:1200px) {}”中。

.gallery {
    width: 100%;
    color: var(--primary-color);
}


.gallery-container {
    width: 100%;
    padding: 120px 15px 0 15px;
    display: flex;
    position: relative;
}


.gallery-container-text {
    flex: 0 0 33.33%;
    min-width: 33%;
}


.gallery-container-text h2 {
    font-size: 40px;
    padding: 30px 0;
    font-weight: 400;
}


.gallery-container-text h4 {
    font-size: 16px;
    line-height: 1.5;
    padding-right: 30px;
    font-weight: 400;
}


.gallery-container-image {
    flex: 0 0 66.66%;
    min-width: 66%;
    height: 400px;
    max-height: 60vh;
    overflow: hidden;
    position: relative;
    width: 100%;
}
.div-containers {
    position: absolute;
    top: -20px;
    bottom: 0;
    left: -20px;
    right: -20px;
}

.gallery-container-image img {
    box-shadow: 0 5px 23px 0 rgba(0,0,0,.15);
    max-width: 100%;
    height: auto;
}


.gallery-container-image div div:nth-child(1) {
    position: absolute;
    top: 20px;
    left: calc(28.25% + 20px);
    width: 42%;
    -webkit-animation: fadeup .5s ease-in-out .9s;
       -moz-animation: fadeup .5s ease-in-out .9s;
         -o-animation: fadeup .5s ease-in-out .9s;
            animation: fadeup .5s ease-in-out .9s;
    opacity: 0;
    animation-fill-mode: forwards;
}
.gallery-container-image div div:nth-child(2) {
    position: absolute;
    top: calc(27% + 20px);
    left: 20px;
    width: 39%;
    -webkit-animation: fadeup .5s ease-in-out .6s;
       -moz-animation: fadeup .5s ease-in-out .6s;
         -o-animation: fadeup .5s ease-in-out .6s;
            animation: fadeup .5s ease-in-out .6s;
    opacity: 0;
    animation-fill-mode: forwards;
}
.gallery-container-image div div:nth-child(3) {
    position: absolute;
    top: calc(52% + 20px);
    left: calc(22% + 20px);
    width: 54%;
    -webkit-animation: fadeup .5s ease-in-out .3s;
       -moz-animation: fadeup .5s ease-in-out .3s;
         -o-animation: fadeup .5s ease-in-out .3s;
            animation: fadeup .5s ease-in-out .3s;
    opacity: 0;
    animation-fill-mode: forwards;
}
.gallery-container-image div div:nth-child(4) {
    position: absolute;
    top: calc(36% + 20px);
    right: 20px;
    width: 40%;
    -webkit-animation: fadeup .5s ease-in-out;
       -moz-animation: fadeup .5s ease-in-out;
         -o-animation: fadeup .5s ease-in-out;
            animation: fadeup .5s ease-in-out;
    opacity: 0;
    animation-fill-mode: forwards;
}


@keyframes fadeup {
    0% {
        opacity: 0;
        -webkit-transform: translate3d(0, 100%,0);
           -moz-transform: translate3d(0, 100%,0);
             -o-transform: translate3d(0, 100%,0);
                transform: translate3d(0, 100%,0);
    }
    100% {
        opacity: 1;
        -webkit-transform: none;
           -moz-transform: none;
             -o-transform: none;
                transform: none;
    }
}
@media screen and (max-width:1200px) {
    .gallery-container {
        flex-direction: column;
        padding: 30px 15px 0 15px;
    }
    .gallery-container-text {
        flex: 0 0 100%;
        min-width: 100%;
    }
    .gallery-container-text h2 {
        text-align: center;
        padding: 30px 0;
    }
    .gallery-container-text h4 {
        padding-right: 0;
        text-align: center;
        margin-bottom: 30px;
    }
    .gallery-container-image {
        flex: 0 0 auto; /* Key line */
        min-width: 100%;
    }
}
@media screen and (max-width: 600px) {
    .gallery-container-image {
        max-height: 30vh;
    }
}
@media screen and (max-width: 400px) {
    .gallery-container-image {
        max-height: 25vh;
    }
    .gallery-container-text h2 {
        font-size: 30px;
    }
    .gallery-container-text h4 {
        font-size: 14px;
    }
}
<section class="gallery">
    <div class="gallery-container">
        <div class="gallery-container-text">
            <h2>Popular Recipes</h2>
            <h4>Some of our popular recipes with our great selection of Tasties Recipes</h4>
        </div>
        <div class="gallery-container-image">
            <div class="div-containers">
                    <div>
                            <img width="446" height="295" src="https://i.imgur.com/6m3Yrou.jpg" alt="image">
                        </div>
                        <div>
                            <img width="412" height="456" src="https://i.imgur.com/mWYieLP.jpg" alt="image">
                        </div>
                        <div>
                            <img width="572" height="416" src="https://i.imgur.com/sfQ5PyR.jpg" alt="image">
                        </div>
                        <div>
                            <img width="434" height="444" src="https://i.imgur.com/Ug7kH7b.jpg" alt="image">
                        </div>
            </div>
            
        </div>
    </div>
</section>