Bootstrap theme not as wide as parent container

Viewed 57

I need help with bootstrap container and row width.

I have created a container and a row inside it. I have everything inside the row, but for some reason content sizes are different as displayed on jsfiddle and image preview.

<!DOCTYPE html>
<html lang="cs">
    <head>
        <title>xGhost.cz | Československý Gamehosting.</title>
        <!-- meta data -->
        <meta name="author" content="Jan Dvořák">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- styles -->
        <link rel="stylesheet" href="css/style.css">
        <!-- BOOTSTRAP START -->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
        <!-- BOOTSTRAP END -->      
    </head>
    <body>
        <div class="container-lg">
            <div class="row">
                <div class="row">
                    <div class="col-lg-1">
                        <img src="img/xGhost.svg" alt="" style="width: 300px; height: auto;"/>
                    </div>
                </div>
                <nav class="navbar navbar-expand-md navbar-dark bg-dark mt-2">
                    <a class="navbar-brand" href="#" style="font-style: italic;">xGhost.cz</a>
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>

                    <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
                        <ul class="navbar-nav ms-auto">
                            <li class="nav-item"><a class="nav-link active" aria-current="page" href="#">Úvod</a></li>
                            <li class="nav-item"><a class="nav-link" href="#">Ceník</a></li>
                            <li class="nav-item"><a class="nav-link" href="#">Objednávka</a></li>
                            <li class="nav-item"><a class="nav-link" href="#">Příručka</a></li>
                            <li class="nav-item"><a class="nav-link" href="#">Servery</a></li>
                            <li class="nav-item"><a class="nav-link" href="#">Technika</a></li>
                            <li class="nav-item"><a class="nav-link" href="#">Kontakt</a></li>
                        </ul>
                    </div>
                </nav>
                <div class="row gx-2 mt-3">
                    <div class="col-md-8">
                        <div class="box">
                            <div class="box-heading">Novinky & Blog</div>
                        </div>
                    </div>
                    
                    <div class="col-md-4">
                        <div class="box">
                            <div class="box-heading">Přihlášení</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

CSS:

body {
    background: url(../img/bg.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

.navbar {
    text-align: center;
}

.nav-link:hover {
    color: rgba(39, 174, 96, 1.0) !important;
}

.box {
    width: 100%;
    height: auto;
}
.box-heading {
    background: #212529 !important;
    color: #fff;
    text-align: center;
    padding: 7px;
    width: 100%;
}

JSFiddle: https://jsfiddle.net/1c9w3taq/

Image preview

On the image you can clearly see, where the spaces are. It all should be aligned from side to side inside the container. Logo column width is missing a few pixels on the right and the two boxes in the bottom are not touching the sides of parrent container.

1 Answers

The problem is from this div.

<div class="col-md-8">

as well as <div class="col-md-4">

Yes they both equal 12 but they contain a margin.

To fix this you can add a class like this.

.nomargin{
margin: 0px !important;
}

And use the class like this

This will remove the default bootstrap margin.

Related