0

I have written :- .container-fluid{padding 3% 15%;} but its only changing padding of Vertical directions to 3% and no change in horizontal padding

#title {
    background-color: #ff4c68;
}

.container-fluid {
    padding: 3% 15%;
}

h1 {
    font-family: 'Montserrat', sans-serif;
    font-size: 3rem;
    line-height: 1.5;
}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>TinDog</title>

    <!-- fonts -->
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@900&display=swap" rel="stylesheet">

    <!-- CSS files -->
    <link rel="stylesheet" href="css/styles.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">

    <!-- js file -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>

</head>

<body>

    <section id="title">

        <div class="container-fluid">
            <!-- Nav Bar -->

            <nav class="navbar navbar-expand-lg navbar-dark">
                <a class="navbar-brand ms-2" href="#">tindog</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarTogglerDemo01">
                    <ul class="navbar-nav ms-auto">
                        <li class="nav-item">
                            <a class="nav-link" href="#">Home</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Pricing</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#">Contact</a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                Link
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarScrollingDropdown">
                                <li><a class="dropdown-item" href="#">Action</a></li>
                                <li><a class="dropdown-item" href="#">Another action</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="#">Something else here</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </nav>


            <!-- Title -->

            <div class="row">
                <div class="col-lg-6">
                    <h1>Meet new and interesting dogs nearby.</h1>
                    <button type="button">Download</button>
                    <button type="button">Download</button>
                </div>
                <div class="col-lg-6">
                    <blockquote class="imgur-embed-pub" lang="en" data-id="a/hlTZeUb" data-context="false" ><a href="//imgur.com/a/hlTZeUb"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>" 
                </div>
            </div>
        </div>
    </section>


</body>

</html>

I want to add horizontal padding to 15% to container-fluid class div element so that they come to center of screen.

EDIT :- It looks like bootstrap has also mentioned some padding for .container-fluid in their css so when i disable it using Dev Tools in my browser i get my required padding of 15% horizontally. But is there any way to really solve it?

  • Funny, this [exact question was just asked before](https://stackoverflow.com/questions/67441000/what-is-the-default-display-type-of-container-fluid-in-bootstrap-5) from the same "Tin dog" tutorial. The issue you describe is [not reproducible](https://codeply.com/p/8oCku5cDYy) – Carol Skelly May 08 '21 at 12:59

2 Answers2

1

This question is actually reproducible. It happened to me when I was following the Tindog tutorial. The other answer works well but there's a better way of doing this. See here. You can add an id or class to the <body> tag:

<body id="bootstrap-overrides">

and then use that with every element you want to style in the CSS file like this:

#bootstrap-overrides .container-fluid {
  padding: 3% 15%;
}

It works with all the elements.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sam_
  • 73
  • 2
  • 4
0

Try this:

.container-fluid {
    padding: 3% 15% !important;
}
Saghi Shiri
  • 537
  • 5
  • 19