bootstrap carousel full width

Issue

Use technology

  1. Bootstrap
  2. css
  3. js
  4. Django
  5. Python

My problem

I want to declare container-fluid and make the carousel slide fill the screen.

but there is a little space left at both ends

i want to fill in the blanks

and I want to adjust the carousel slide height.

I am new to css please help

My html of carousel slide parts

<div class="container-fluid">
    <div id="carouselExampleSlidesOnly" class="carousel slide" data-bs-ride="carousel">
        <div class="carousel-inner">
            <div class="carousel-item active">
                <img src="http://placeimg.com/640/480/any" class="w-100" alt="...">
            </div>
            <div class="carousel-item">
                <img src="http://placeimg.com/640/480/any" class="w-100" alt="...">
            </div>
            <div class="carousel-item">
                <img src="http://placeimg.com/640/480/any" class="w-100" alt="...">
            </div>
        </div>
    </div>

</div>

My all html

<!doctype html>
<html lang="en">
{% load static %}
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="{% static 'Blog/css/bootstrap.css' %}">
    <link rel="stylesheet" href="{% static 'Blog/css/bootstrap.min.css' %}">
    <title>Bootstrap demo</title>
    <!-- Navigation-->
</head>
<body id="page=top">
<nav class="navbar navbar-expand-lg navbar-light fixed-top py-3" id="mainNav">
    <div class="container-fluid">
        <div class="col-2">
            <a class="navbar-brand" href="#page-top">코딩하는 돌맹이 옷집</a>
        </div>
        <button class="navbar-toggler navbar-toggler-right" type="button" data-bs-toggle="collapse"
                data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false"
                aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
        <div class="collapse navbar-collapse row col-10" id="navbarResponsive">
            <div class="col-9">
                <ul class="navbar-nav">
                    <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
                            data-bs-target="#navbarNavDarkDropdown" aria-controls="navbarNavDarkDropdown"
                            aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLink" role="button"
                           data-bs-toggle="dropdown" aria-expanded="false">
                            IMMM
                        </a>
                        <ul class="dropdown-menu dropdown-menu-white" aria-labelledby="navbarDarkDropdownMenuLink">
                            <li><a class="dropdown-item" href="#">Action</a></li>
                            <li><a class="dropdown-item" href="#">Another action</a></li>
                            <li><a class="dropdown-item" href="#">Something else here</a></li>
                            <li><a class="dropdown-item" href="#">Something else here</a></li>
                            <li><a class="dropdown-item" href="#">Something else here</a></li>
                            <li><a class="dropdown-item" href="#">Something else here</a></li>
                            <li><a class="dropdown-item" href="#">Something else here</a></li>
                            <li><a class="dropdown-item" href="#">Something else here</a></li>
                        </ul>
                    </li>
                    <li class="nav-item"><a class="nav-link" href="#services">IMMM MADE</a></li>
                    <li class="nav-item"><a class="nav-link" href="#portfolio">COMMUNITY</a></li>
                </ul>
            </div>
            <div class="col-3">
                <ul class="navbar-nav">
                    <li class="nav-item"><a class="nav-link" href="#about">LOG IN</a></li>
                    <li class="nav-item"><a class="nav-link" href="#services">JOIN</a></li>
                    <li class="nav-item"><a class="nav-link" href="#portfolio">MYPAGE</a></li>
                    <li class="nav-item"><a class="nav-link" href="#contact">SEARCH</a></li>
                </ul>
            </div>
        </div>
    </div>
</nav>
<div class="container-fluid">
    <div id="carouselExampleSlidesOnly" class="carousel slide" data-bs-ride="carousel">
        <div class="carousel-inner">
            <div class="carousel-item active">
                <img src="http://placeimg.com/640/480/any" class="w-100" alt="...">
            </div>
            <div class="carousel-item">
                <img src="http://placeimg.com/640/480/any" class="w-100" alt="...">
            </div>
            <div class="carousel-item">
                <img src="http://placeimg.com/640/480/any" class="w-100" alt="...">
            </div>
        </div>
    </div>

</div>

</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.min.js"
        integrity="sha384-kjU+l4N0Yf4ZOJErLsIcvOU2qSb74wXpOhqTvwVx3OElZRweTnQ6d31fXEoRD1Jy"
        crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
        crossorigin="anonymous"></script>

Solution

You have combined a couple of questions and this should be enough to start you in the correct direction.

To remove the gaps on the sides of the container add the Bootstrap class px-0 to remove the padding:

<div class="container-fluid px-0">

You can add a style attribute to set the vertical height of the carousel. However, the images will be cropped when the height:width ratio of the image is different from the carousel ratio:

<div class="carousel-inner" style="height: 300px;">

You can fix your navbar by adding a solid background color like bg-light:

<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top py-3"

And since you use a fixed navbar you should also add a spacer div to push the carousel down. Without the spacer the content will be hidden by the navbar.

<div style="margin-top: 70px;"></div>

Yet, if you want the navbar to appear over the images then add the following style rather than the spacer:

  <nav style="background-color: rgba(255,255,255,0.6);" class="navbar navbar-expand-lg navbar-light fixed-top py-3" 

And since you are using bootstrap.bundle.min.js you can remove this script from your page (you do not need both):

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.min.js"

Run the snippet to understand how it works.

<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top py-3" id="mainNav">
  <div class="container-fluid">
    <div class="col-2">
      <a class="navbar-brand" href="#page-top">코딩하는 돌맹이 옷집</a>
    </div>
    <button class="navbar-toggler navbar-toggler-right" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
    <div class="collapse navbar-collapse row col-10" id="navbarResponsive">
      <div class="col-9">
        <ul class="navbar-nav">
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDarkDropdown" aria-controls="navbarNavDarkDropdown" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            IMMM
                        </a>
            <ul class="dropdown-menu dropdown-menu-white" aria-labelledby="navbarDarkDropdownMenuLink">
              <li><a class="dropdown-item" href="#">Action</a></li>
              <li><a class="dropdown-item" href="#">Another action</a></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
            </ul>
          </li>
          <li class="nav-item"><a class="nav-link" href="#services">IMMM MADE</a></li>
          <li class="nav-item"><a class="nav-link" href="#portfolio">COMMUNITY</a></li>
        </ul>
      </div>
      <div class="col-3">
        <ul class="navbar-nav">
          <li class="nav-item"><a class="nav-link" href="#about">LOG IN</a></li>
          <li class="nav-item"><a class="nav-link" href="#services">JOIN</a></li>
          <li class="nav-item"><a class="nav-link" href="#portfolio">MYPAGE</a></li>
          <li class="nav-item"><a class="nav-link" href="#contact">SEARCH</a></li>
        </ul>
      </div>
    </div>
  </div>
</nav>

<div style="margin-top: 70px;"></div>

<div class="container-fluid px-0">
  <div id="carouselExampleSlidesOnly" class="carousel slide" data-bs-ride="carousel">
    <div class="carousel-inner" style="height: 300px;">
      <div class="carousel-item active">
        <img src="https://loremflickr.com/640/480/red" class="w-100 h-auto" alt="...">
      </div>
      <div class="carousel-item">
        <img src="https://loremflickr.com/640/480/green" class="w-100" alt="...">
      </div>
      <div class="carousel-item">
        <img src="http://placeimg.com/640/480/blue" class="w-100" alt="...">
      </div>
    </div>
  </div>

</div>


<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"></script>

Answered By – Yogi

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.