justify-content-center not working on carousel

Viewed 462

I'm trying to center my carousel with it's images and it's not working. I tried putting the justify-content-center the carousel inner div, outside of that, trying to do it in CSS but it just won't work.

Html

<?php

?>


<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="./css/style.css">

    <title>Scary Configs | Media</title>
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-dark bg-primary noselect">
    <div class="container-fluid">
        <a class="navbar-brand" href="index.php">Home</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse justify-content-center" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="purchase.php">Purchase</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link nav-link active" href="media.php">Media</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Feedback</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Terms of Service</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Login/Register</a>
                </li>
            </ul>
        </div>
    </div>
</nav>


<div id="videos">
    <div class="container">
        <div class="row justify-content-center">
            <div class="mt-4" id="video">
                <h1 id="video-header">Media with my config</h1>
                <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/cLGBfQt-6sA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/tnvBqitVv3s" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
            </div>
        </div>
    </div>
</div>

<div id="pictures">
    <h1 id="video-header" class="mt-3">Screenshot Media</h1>
    <div class="carousel slide" data-ride="carousel">
        <div class="carousel-inner w-100">
            <div class="carousel-item active" data-interval="4000" data-keyboard=true data-ride="true">
                <img src="img/media/221.png" class="d-block w-100">
            </div>
            <div class="carousel-item" data-interval="4000" data-keyboard=true>
                <img src="img/media/224.jpg" class="d-block w-100">
            </div>
            <div class="carousel-item" data-interval="4000" data-keyboard=true>
                <img src="img/media/288.jpg" class="d-block w-100">
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>

css

body {
    background-color: #121212;
    height: 100%;
    padding-bottom: 50px;
    -ms-overflow-style: none;
    scrollbar-width: none;
    overflow: -moz-scrollbars-none;
}

.noselect {
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
    -khtml-user-select: none; /* Konqueror HTML */
    -moz-user-select: none; /* Old versions of Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome, Edge, Opera and Firefox */
}

.card {
    border: none;
}

#jumbo-text, #video-header {
    color: white;
    opacity: 40%;
    text-align: center;
}
#jumbo {
    @import url('https://fonts.googleapis.com/css2?family=Antonio:wght@700&display=swap');
    background: rgba(200, 200, 200, 0.05);
    font-family: 'Antonio', sans-serif;
}

#purchase-btn {
    color: white;
}

.navbar {
    font-size: 1.5em;
}

.w-100 {
    width: 800px !important;
    height: 40vh;
}

Also how would I add margin between the two video embeds? I tried adding mx-5 and it just places them horizontally? The same happens when I use padding instead of margin.

1 Answers

To use Bootstrap-4 classes, like justify-content-center to center your carousel, you need to be using Bootstrap’s grid system of rows and columns. Also, you shouldn’t redefine Bootstrap classes like w-100 (which is for width: 100%) to be a fixed width. The idea behind Bootstrap is elements are defined as percentages so when users use a different screen size, they get a viable experience.

Same for the video section – rather than having fixed sizes, you can use Bootstrap’s row, col, and embed classes.

You were using an older version of Bootstrap CSS (4.0.0) and JavaScript (4.3.1). I switched everything to the latest V4 version (4.6.0)

And you seemed to be restricting everything to the available screen (no overflow), but not everything would fit, so I commented out those styles.

<link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>

<style>
    @import url('https://fonts.googleapis.com/css2?family=Antonio:wght@700&display=swap');

    body {
        background-color: #121212;
        height: 100%;
        padding-bottom: 50px;
        /*overflow: hidden;
        -ms-overflow-style: none;
        scrollbar-width: none; 
        overflow: -moz-scrollbars-none;*/
    }

    .noselect {
        -webkit-touch-callout: none;
        /* iOS Safari */
        -webkit-user-select: none;
        /* Safari */
        -khtml-user-select: none;
        /* Konqueror HTML */
        -moz-user-select: none;
        /* Old versions of Firefox */
        -ms-user-select: none;
        /* Internet Explorer/Edge */
        user-select: none;
        /* Non-prefixed version, currently
                                supported by Chrome, Edge, Opera and Firefox */
    }

    .card {
        border: none;
    }

    #jumbo-text,
    #video-header {
        color: white;
        opacity: 40%;
        text-align: center;
    }

    

    #jumbo {
        
        background: rgba(200, 200, 200, 0.05);
        font-family: 'Antonio', sans-serif;
    }

    #purchase-btn {
        color: white;
    }

    .navbar {
        font-size: 1.5em;
    }

    
</style>

<nav class="navbar navbar-expand-lg navbar-dark bg-primary noselect">
    <div class="container-fluid">
        <a class="navbar-brand" href="index.php">Home</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse justify-content-center" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="purchase.php">Purchase</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link nav-link active" href="media.php">Media</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Feedback</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Terms of Service</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Login/Register</a>
                </li>
            </ul>
        </div>
    </div>
</nav>



<div id="videos" class="container-sm">
    <div class="row">
        <h1 id="video-header" class="w-100 text-center">Media with my config</h1>
    </div>
    <div id="video" class="row justify-content-center">
        <div class="col-12 col-md-8 col-lg-5 embed-responsive embed-responsive-16by9 mb-3 mb-lg-0">
            <iframe class="embed-responsive-item" src="https://www.youtube-nocookie.com/embed/cLGBfQt-6sA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        </div>
        <div class="col-1 d-none d-lg-block"></div>
        <div class="col-12 col-md-8 col-lg-5 embed-responsive embed-responsive-16by9">
            <iframe class="embed-responsive-item" src="https://www.youtube-nocookie.com/embed/tnvBqitVv3s" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        </div>
    </div>
</div>

<div class="container">
    <div class="row justify-content-center">
        <div class="col-12 col-md-8 col-lg-6 px-0">
            <div id="pictures">
                <h1 id="video-header" class="mt-3">Screenshot Media</h1>
                <div class="carousel slide" data-ride="carousel">
                    <div class="carousel-inner w-100">
                        <div class="carousel-item active" data-interval="4000" data-keyboard=true data-ride="true">
                            <img src="https://via.placeholder.com/400x240/FF0000/000000.png" class="d-block w-100">
                        </div>
                        <div class="carousel-item" data-interval="4000" data-keyboard=true>
                            <img src="https://via.placeholder.com/400x240/0000FF/000000.png" class="d-block w-100">
                        </div>
                        <div class="carousel-item" data-interval="4000" data-keyboard=true>
                            <img src="https://via.placeholder.com/400x240/FFFF00/000000.png" class="d-block w-100">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Related