How do I make my Bootstrap Carousel the full width

2020-05-08 17:44发布

问题:

I am trying to make my bootstrap carousel the full width of the page, thinking that that will look the best. I've looked it up and nothing I tried worked, though. Also, if you think that making it a different size would be better, I would love to hear! I'm not great with layout and I'm trying to work on it. Also, my pictures are in SD even though they were HD. Should I link them in the same folder as my html and css files instead of getting them straight from the internet?

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>Website Template</title>
        <!-- links to the css page and bootstrap -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
        <link rel="stylesheet" type="text/css" href="main.css">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    </head>
    <body>
<!-- BEGIN NAVBAR -->
<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header pull-left">
            <a class="navbar-brand" href="#">Project Name</a>
        </div>
        <div class="navbar-header pull-right">
            <ul class="nav navbar-nav pull-left">
                <li><a class="" href="#">Text</a></li>
            </ul>
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
        </button>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="#">Text</a></li>
                <li><a href="#">Text</a></li>
                <li><a href="#">Text</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>   <ul class="dropdown-menu">
                        <li><a href="#">Text</a></li>
                        <li class="divider"></li>
                        <li class="dropdown-header">Text</li>
                        <li><a href="#">Text</a></li>
                        <li><a href="#">Text</a></li>
                    </ul>
                </li>
            </ul>
            <div class="navbar-right">
                <ul class="nav navbar-nav">
                    <li><a href="#">Text</a></li>
                    <li><a href="#">Text</a></li>
                </ul>
            </div>
        </div>
    </div>
</div>
<!-- END NAVBAR -->


            <div class="container">
                <!-- CAROUSEL START -->
                <div id="myCarousel" class="carousel slide" data-interval="3000" data-ride="carousel">
                    <!--Carousel indicators -->
                    <ol class="carousel-indicators">
                        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                        <li data-target="#myCarousel" data-slide-to="1"></li>
                        <li data-target="#myCarousel" data-slide-to="2"></li>
                    </ol>
                    <!-- Carousel items -->
                    <div class="carousel-inner">
                        <div class="item active">
                            <img src="http://36646d87786feafc0611-0338bbbce19fc98919c6293def4c5554.r0.cf1.rackcdn.com/images/FiGZ9r3D3E82.878x0.Z-Z96KYq.jpg" alt="First Slide">
                            <div class="carousel-caption">
                                <h3>First slide label</h3>
                                <p>BLAH</p>
                            </div>
                        </div>
                        <div class="item">
                            <img src="https://media.licdn.com/mpr/mpr/p/2/005/096/045/19d71d5.jpg" alt="Second Slide">
                            <div class="carousel-caption">
                                <h3>Second slide label</h3>
                                    <p>BLAH BLAH</p>
                                </div>
                            </div>
                            <div class="item">
                                <img src="http://d3psvddqt9zx7g.cloudfront.net/blog/wp-content/uploads/2015/05/lol1-2.jpg" alt="Third Slide">
                                <div class="carousel-caption">
                                    <h3>Third slide label</h3>
                                    <p>BLAH BLAH BLAH</p>
                                </div>
                            </div>
                        </div>
                        <!--Carousel nav -->
                        <a class="carousel-control left" href="#myCarousel" data-slide="prev">
                            <span class="glyphicon glyphicon-chevron-left"></span>
                        </a>
                        <a class="carousel-control right" href="#myCarousel" data-slide="next">
                            <span class="glyphicon glyphicon-chevron-right"></span>
                        </a>
                    </div>

                <!--CAROUSEL END -->
            </div>

    </body>
</html>

CSS

body {
    padding-top: 50px;
    padding-bottom: 20px;
}

.carousel img {
    top: 0;
    left: 0;
    min-width: 100%;
    height: 550px;
    max-height: 550px;
    width: auto;
}

回答1:

Just remove the container like in this fiddle https://jsfiddle.net/zdxq5c85/

<!-- CAROUSEL START -->
                <div id="myCarousel" class="carousel slide" data-interval="3000" data-ride="carousel">
                    <!--Carousel indicators -->
                    <ol class="carousel-indicators">
                        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                        <li data-target="#myCarousel" data-slide-to="1"></li>
                        <li data-target="#myCarousel" data-slide-to="2"></li>
                    </ol>
                    <!-- Carousel items -->
                    <div class="carousel-inner">
                        <div class="item active">
                            <img src="http://36646d87786feafc0611-0338bbbce19fc98919c6293def4c5554.r0.cf1.rackcdn.com/images/FiGZ9r3D3E82.878x0.Z-Z96KYq.jpg" alt="First Slide">
                            <div class="carousel-caption">
                                <h3>First slide label</h3>
                                <p>BLAH</p>
                            </div>
                        </div>
                        <div class="item">
                            <img src="https://media.licdn.com/mpr/mpr/p/2/005/096/045/19d71d5.jpg" alt="Second Slide">
                            <div class="carousel-caption">
                                <h3>Second slide label</h3>
                                    <p>BLAH BLAH</p>
                                </div>
                            </div>
                            <div class="item">
                                <img src="http://d3psvddqt9zx7g.cloudfront.net/blog/wp-content/uploads/2015/05/lol1-2.jpg" alt="Third Slide">
                                <div class="carousel-caption">
                                    <h3>Third slide label</h3>
                                    <p>BLAH BLAH BLAH</p>
                                </div>
                            </div>
                        </div>
                        <!--Carousel nav -->
                        <a class="carousel-control left" href="#myCarousel" data-slide="prev">
                            <span class="glyphicon glyphicon-chevron-left"></span>
                        </a>
                        <a class="carousel-control right" href="#myCarousel" data-slide="next">
                            <span class="glyphicon glyphicon-chevron-right"></span>
                        </a>
                    </div>

                <!--CAROUSEL END -->