'list has 8 items but the the last 4 items moves out from the blue background in testimonials-section

As i am running the html and css code the list of testimonials are 8 but , when i increased the size of the screen to 950px the list of 8 items start coming out of the background, so please can anyone give me the hint that where the code is wrong

const mobileBtn = document.getElementById('mobile-cta');
nav = document.querySelector('nav');
mobileBtnExit = document.getElementById('mobile-sta');

mobileBtn.addEventListener('click' , () => {
 nav.classList.add('mobile-menu');
})
mobileBtnExit.addEventListener('click' , () => {
nav.classList.remove('mobile-menu'); 
})
    :root {
        --primary-color: #007af3;
    }

    body{
        background: #F2F2F2;
        margin: 0 ;
        font-family: 'Poppins'; 
    }

    .navbar {
        background: white;
        padding: 1em;
        
        .logo{
             text-decoration: none;
             font-weight: bold;
             color: black ;
             font-size: 1.2em;

            span {
                 color: var(--primary-color);
            }
        }

        nav{
            display: none;
        }
        .container{
            display: flex;
            place-content: space-between;
        }

        .mobile-menu{
            cursor: pointer;
        }
    }

    a{
        color: #444444;
    }

    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
    }

    section{
        padding: 5em 2em;
    }

    .hero{
        text-align: center;
    }

    .left-col{

        .subhead{
            text-transform: uppercase;
            font-weight: bold;
            color: gray;
            letter-spacing: .3em;
        }

        h1{
            font-size: 2.5em;
            line-height: 1.3em;
            margin-top: .2em;
        }

        .primary-cta{
            background: var(--primary-color);
            color: white;
            text-decoration: none;
            padding: .6em 1.3em;
            font-size: 1.4em;
            border-radius: 5em;
            font-weight: bold;
            display: inline-block;
        }

        .watch-video-cta{
            display: block;
            margin-top: 1em;
            
            img {
                margin-right: .5em;
            }
        }
    }

    .hero-img{
        width: 70% ;
        margin-top: 3em;
    }

    section.features-section{
        background: #20272e;
        color: white;
    }

    ul.feature-list{
        margin:  0;
        padding-left: .1em;
        display: grid;
        grid-template-columns: repeat(auto-fit , minmax(19rem, 1fr));

        li{
            font-size: 1.1em;
            margin-bottom: 1em;
            margin-left: 2em;
            position: relative;

            &:before{
                content: '';
                left: -2em;
                position: absolute;
                width: 20px;
                height: 20px;
                background-image: url('../2021frontend/images/bullet.svg');
                background-size: contain;
                margin-right: .5em;

            }
        }
        
    }

    .features-section img{
        display: none;
    }


    .testimonials-section{
        background: var(--primary-color);
        color: white;

        li{
            width: #006bd6;
            text-align: center;
            padding: 2em 1em;
            width: 75%;
            margin: 0 auto 5em auto;
            border-radius: 1em;
            
            img{
                width: 5em;
                height: 5em;
                border: 5px solid #006bd6;
                border-radius: 50%;
                margin-top: -4.5em;
            }
        }
    }

    h2{
        font-size: 2em;
    }

    label{
        display: block;
        font-size: 1.2em;
        margin-bottom: .5em;
    }

    input, textarea{
        width: 100%;
        padding: .8em;
        margin-bottom: 1em;
        border-radius: .3em;
        border: 1px solid gray;
        box-sizing: border-box;
    }

    input[type="submit"]{
        background-color: var(--primary-color);
        color: white;
        font-weight: bold;
        font-size: 1.3em;
        border: none;
        margin-bottom: 5em;
        border-radius: 5em;
        display: inline-block;
        padding: .8em 6.7em;
        width: unset;
        cursor: pointer;
    }

    iframe{
        width: 100%;
        height: 300px;
    }

    nav.mobile-menu{
        display: block;
    }

    nav{
        position: fixed;
        z-index: 999;
        width: 66%;
        right: 0;
        top: 0;
        background: #20272e;
        height: 100vh;
        padding: 1em;

        ul.primary-nav{
            margin-top: 5em;
        }

        li{

            a{
                color:white;
                text-decoration: none;
                display: block;
                padding: .5em;
                font-size: 1.3em;
                text-align: right;

                &:hover{
                    font-weight: bold;
                }
            }
        }

    }

    .mobile-mobile-closed {
        float: right;
        margin: .5em;
        cursor: pointer;

    }

    //now here we desinging the pc version of the website

    @media only screen and (min-width: 768px){
        .mobile-menu, .mobile-menu-closed{
            display: none;
        }

        .navbar .container{
            display: grid;
            grid-template-columns: 180px auto;
            justify-content: unset;
            
        }

        .navbar nav{
            display: flex;
            justify-content: space-between;
            background: none;
            position: unset;
            height: auto;
            width: 100%;
            padding: 0;

            ul{
                display: flex;
            }

            a{
                color: black;
                font-size: 1em;
                padding: .1em 1em; 
            }

            ul.primary-nav{
                margin: 0;
            }

            li.current a{
                font-weight: bold;
            }

            li.go-premium-cta a{
                color: var(--primary-color);
                border: 3px solid var(--primary-color);
                font-weight: bold;
                border-radius: 5em;
                margin-top: -.2em;

                &:hover{
                    background: var(--primary-color);
                    color: white;
                }
            }
        }
    }

    @media only screen and (min-width: 950px) {
        .container{
            width: 950px;
            margin: 0 auto;
        }

        section{
            padding: 10em 4em;
        }
        
        .hero .container{
            display: flex;
            justify-content: space-between;
            text-align: left;

            .left-col{
                margin: 3em 3em 0 5em;

                h1 {
                    font-size: 3em;
                    width: 90%;
                }
            }
        
        }

        .hero-img{
            width: 30%;
            margin-right: 8em;
        }

        .hero-cta{
            display: flex;
        }

        .primary-cta{
            margin-right: 1em;
        }

        ul.features-list{
            display: block;
            margin-left: 5em;

            li{
                font-size: 1.4em;

                &:before{
                    width: 30px;
                    height: 30px;
                }
            }
        }

        .features-section{
            position: relative;
        }

        .features-section img{
            display:block;
            position: absolute;
            right: 0;
            width: 325px;
            bottom: -6em; 
            height: 250px; 
        }

        .testimonials-section ul{
            display: flex;

            li {
                margin: 0 1em;
                flex-basis: 33.333333%;
            }
        }

        .contact-section{
            position: relative;
            display: flex;
            
        }

        .contact-right{
            position: absolute;
            right: 0;
            top: 0;
            width: 45%;
            height: 100%;

            iframe{
                height: 100%;
            }
        }
    }

    //here we done the styling of 1220px and after
    @media only screen and (min-width: 1220px){
        .features-section{

            &:before{
                content: '';
                position: absolute;
                width: 10%;
                height: 20em;
                background: var(--primary-color);
                left: 0;
                top: -4em;
            }

            &:after{
                content: '';
                position: absolute;
                width: 200px;
                height: 18em;
                background: url('../2021frontend/images/dots.svg') no-repeat;
                top: -1em;
                left: auto;
            }
        }
    }
        <div class="navbar"> <!-- here class is the name given to the div block so that the css identify it for styling it-->
            <div class="container">
                <a class="logo" href="#">Let's<span>Code</span></a>
                
                <img id="mobile-cta" class="mobile-menu" src="2021frontend/images/menu.svg" alt="Open navigation">

                <nav>
                    <img id="mobile-sta" class="mobile-menu-closed" src="2021frontend/images/exit.svg" alt="Closed navigation">
                    <ul class="primary-nav">
                        <li class="home"><a href="#">Home</a></li>
                        <li><a href="#">Events</a></li>
                        <li><a href="#">Registration</a></li>
                    </ul>

                    <ul class="secondary-nav">
                        <li><a href="#">GrowYourMoney</a></li>
                        <li><a href="#">Projects</a></li>
                    </ul>
                </nav>
            </div>
        </div>

        <section  class="hero">
            
            <div class="container">
                <div class="left-col">
                    <p class="subhead">Share with the World &amp; Grow with the World</p>
                    <h1>We are here to make the Future</h1>

                    <div class="hero-cta">
                        <a href="#" class="primary-cta">Click Here</a>
                        <a href="#" class="watch-video-cta">
                            <img src="2021frontend/images/watch.svg" alt="Watch a video">Watch a Video
                        </a>
                    </div>        
                </div>

                <img src="2021frontend/images/illustration.svg" class="hero-img" alt="illustration-images">
            </div>
            
        </section>

        <section class="features-section">
            <div class="container">
                <ul class="feature-list">
                     <li>Full Stack Web Development</li>
                     <li>Full Stack Mobile App Development</li>
                     <li>Cloud tech</li>
                     <li>Devops</li>
                     <li>Web3 Development</li>
                     <li>Stock Market</li>

                </ul>

                <img src="2021frontend/images/holding-phone.jpg" alt="Man holding phone">
            </div>

        </section>

        <section class="testimonials-section">
            <div class="container">
                <ul>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"has a strong hold in full stack web Development, leader of team antidote in sih prefinal round"</blockquote>
                        <cite>- saksham bansal</cite>
                    </li>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"starting my journey as a full stack developer and interested in web3 domain"</blockquote>
                        <cite>- sayan halder</cite>
                    </li>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"currently doing frontend development with bootstrap and loves playing football and cricket"</blockquote>
                        <cite>- varun sharma</cite>
                    </li>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"currently learning web Development and see myself in future as a android developer "</blockquote>
                        <cite>- parth barara</cite>
                    </li>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"iam  the tomper of the class and likes chemistry very much"</blockquote>
                        <cite>- sakshi gupta</cite>
                    </li>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"i dont know what i am doing but my boyfriend loves me very much"</blockquote>
                        <cite>- nandini gulati</cite>
                    </li>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"same as nandini"</blockquote>
                        <cite>- kushi suri</cite>
                    </li>
                    <li>
                        <img src="2021frontend/images/person.jpg" alt="person">

                        <blockquote>"iam the don of kv, dont even try to fight with me in palam"</blockquote>
                        <cite>- sribash paul</cite>
                    </li>
                </ul>
            </div>

        </section>
        <br>

        <section class="contact-section">
            <div class="contact-left">
                <h2>Contact</h2>

                <form action="">
                    <label for="name">Name</label>
                    <input type="text" id="name" name="name" placeholder="Your Name"> <br>
                    <br>
                    <label for="email">Email</label>
                    <input type="email" id="email" name="email" placeholder="@email.com"> <br>
                    <br>
                    <label for="message">Message</label> <br>
                    <textarea name="message" id="message" cols="30" rows="10"></textarea> <br>
                    <br>
                    <input type="submit" class="send-message-cta" value="Send Message">
                </form>
            </div>
            
            <div>
                <div class="contact-right">
                    <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d28026.467037845872!2d77.08443149999997!3d28.59052415000001!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x390d1b3f9902dce7%3A0xdf51d27e693abbea!2sPalam%2C%20New%20Delhi%2C%20Delhi!5e0!3m2!1sen!2sin!4v1649777392215!5m2!1sen!2sin" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
                </div>
            </div>

            <img src="2021frontend/images/" alt="">
            
        </section>


Solution 1:[1]

By default display: flex; will try and put everything onto one row. Where you have .testimonials-section ul { in your 950px breakpoint add flex-wrap: wrap;

One thing to note, and I may be mistaken here, is that flex-basis doesn't take margins into consideration, so you will find that your testimonials will be 2 per row instead of 3 because of the horizontal margins you've set. You can fix this by change flex-basis: 33.3333% to flex-basis: calc(33.3333% - 2em);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jon Walter