Bootstrap 代码在 Fiddle 中有效但在本地主机中无效?

Bootstrap code works in Fiddle but not in the localhost?

我遇到了一个问题,我的 bootstrap 代码可以在 JSFiddle 上运行,但不能在我的本地主机浏览器上运行。下面是代码。问题出现在 Navigation Tabs HREF!

我正在参加 coursera 课程,讲师很容易运行相同的代码,但我遇到了相同代码的问题,我已经尝试了 1000 多种方法,但都不起作用我也尝试过检查脚本和链接但没有进展。

<!DOCTYPE html>
<html lang="en">

<head>

    <title>Ristorante Con Fusion: About Us</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" type="text/css" href="node_modules\bootstrap\dist\css\bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="style.css">

</head>

<body>
    <nav class="navbar navbar-dark navbar-expand-sm fixed-top">
        <div class="container">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#Navbar">
                <span class="navbar-toggler-icon"></span>
                
            </button>
            <a class="navbar-brand mr-auto" href="#"><img src="img/logo.png" height="30" width="41"></a>
            <div class="collapse navbar-collapse" id="Navbar">
            <ul class="navbar-nav mr-auto">
                <li class="nav-items"><a class="nav-link" href="./index.html">Home</a></li>
                <li class="nav-items"><a class="nav-link active" href="#">About</a></li>
                <li class="nav-items"><a class="nav-link" href="#">Menu</a></li>
                <li class="nav-items"><a class="nav-link" href="#">Contact</a></li>
                
            </ul>
            </div>      
        </div>  
    </nav>

    <header class="jumbotron">
        <div class="container">
            <div class="row row-header">
                <div class="col-12 col-sm-6">
                    <h1>Ristorante con Fusion</h1>
                    <p>We take inspiration from the World's best cuisines, and create a unique fusion experience. Our lipsmacking creations will tickle your culinary senses!</p>
                </div>
                <div class="col-12 col-sm">
                    <div class="col-12 col-sm align-self-center">
                    <img src="img/logo.png" class="img-fluid">
                </div>
                </div>
            </div>
        </div>
    </header>

    <div class="container">
        <div class="row">
            <ol class="col-12 breadcrumb">
                <li class="breadcrumb-item"><a href="./index.html">Home</a></li>
                <li class="breadcrumb-item active">About Us</li>
                
            </ol>
            <div class="col-auto">
               <h3>About Us</h3>
               <hr>
            </div>
        </div>

        <div class="row">
            <div class="col-12 col-sm-6">
                <h2>Our History</h2>
                <p>Started in 2010, Ristorante con Fusion quickly established itself as a culinary icon par excellence in Hong Kong. With its unique brand of world fusion cuisine that can be found nowhere else, it enjoys patronage from the A-list clientele in Hong Kong.  Featuring four of the best three-star Michelin chefs in the world, you never know what will arrive on your plate the next time you visit us.</p>
                <p>The restaurant traces its humble beginnings to <em>The Frying Pan</em>, a successful chain started by our CEO, Mr. Peter Pan, that featured for the first time the world's best cuisines in a pan.</p>
            </div>
            <div class="col-sm">
                <div class="card">
                    <h3 class="card-header bg-primary text-white">Facts At a Glance</h3>
                    <div class="card-body">
                        <dl class="row">
                            <dt class="col-6">Started</dt>
                            <dd>3 Feb. 2013</dd>
                            <dt class="col-6">Major Stake Holder</dt>
                            <dd>HK Fine Foods Inc.</dd>
                            <dt class="col-6">Last Year's Turnover</dt>
                            <dd>,250,375</dd>
                            <dt class="col-6">Employees</dt>
                            <dd>40</dd>
                        </dl>
                    </div>
                </div>

            </div>
            <div class="col-12">
                <div class="card card-body bg-light">
                    <blockquote class="blockquote">
                        <p class="mb-0">You better cut the pizza in four pieces because I'm not hungry enough to eat six. </p>
                        <footer class="blockquote-footer">Yogi Berra,
                            <cite title="Source Title">The Wit and Wisdom of Yogi Berra, P. Pepe, Diversion Books, 2014</cite></footer>
                    </blockquote>
                    
                </div>
                
            </div>
        </div>


        <div>
            <div class="col-12">
                <h2>Corporate Leadership</h2>
                <nav>
                <div class="nav nav-tabs" role ="tablist">
                        <a href="#peter" class="nav-item nav-link active" role="tab" data-toggle="tab">Peter Pan, CEO</a>
                        <a href="#danny" class="nav-item nav-link" role="tab" data-toggle="tab">Dammy Witherspoon, CFO</a>
                        <a href="#agumbe" class="nav-item nav-link" role="tab" data-toggle="tab">Agumbe Tang, CTO</a>
                        <a href="#alberto" class="nav-item nav-link" role="tab" data-toggle="tab">Alberto Somayya, Exec. Chef</a>
                </div>
                </nav>
                <div class="tab-content">
                    <div role="tabpanel" class="tab-pane fade show active" id="peter">         
                        <h3>Peter Pan <small>Chief Epicurious Officer</small></h3>
                        <p class="d-none d-sm-block">Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which <em>The Frying Pan</em> became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural culinary connections.</p>
                    </div>
                    <div role="tabpanel" class="tab-pane fade" id="danny"> 
                        <h3>Dhanasekaran Witherspoon <small>Chief Food Officer</small></h3>
                        <p class="d-none d-sm-block">Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties of food sources. As he puts it in his own words, <em>Everything that runs, wins, and everything that stays, pays!</em></p>
                    </div>
                    <div role="tabpanel" class="tab-pane fade" id="agumbe"> 
                        <h3>Agumbe Tang <small>Chief Taste Officer</small></h3>
                        <p class="d-none d-sm-block">Blessed with the most discerning gustatory sense, Agumbe, our CTO, personally ensures that every dish that we serve meets his exacting tastes. Our chefs dread the tongue lashing that ensues if their dish does not meet his exacting standards. He lives by his motto, <em>You click only if you survive my lick.</em></p>
                    </div>
                    <div role="tabpanel" class="tab-pane fade" id="alberto"> 
                        <h3>Alberto Somayya <small>Executive Chef</small></h3>
                        <p class="d-none d-sm-block">Award winning three-star Michelin chef with wide International experience having worked closely with whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences. He says, <em>Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!</em></p>
                    </div>    
            </div>
       </div>
       <div class="row row-content">
        <div class="col-12 col-sm-9">
            <h2>Facts &amp; Figures</h2>
            <div class="table-responsive">
            <table class="table table-striped">
                <thead class="thead-dark">
                    <tr>
                        <th>&nbsp;</th>
                        <th>2013</th>
                        <th>2014</th>
                        <th>2015</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <th>Employees</th>
                        <th>15</th>
                        <th>30</th>
                        <th>40</th>
                    </tr>
                    <tr>
                        <th>Guests Served</th>
                        <th>15,000</th>
                        <th>45,000</th>
                        <th>1,00,000</th>
                    </tr>
                    <tr>
                        <th>Special Events</th>
                        <th>3</th>
                        <th>20</th>
                        <th>45</th>
                    </tr>
                    <tr>
                        <th>Annual Turnover</th>
                        <th>,51,325</th>
                        <th>,250,375</th>
                        <th>,00,000</th>
                    </tr>
                </tbody>
            </table>
            </div>
        </div>
        <div class="col-12 col-sm-3"></div>
           
       </div>

    </div>

    <footer class="footer">
        <div class="container">
            <div class="row">             
                <div class="col-4 offset-1 col-sm-2">
                    <h5>Links</h5>
                    <ul class="list-unstyled">
                        <li><a href="./index.html">Home</a></li>
                        <li><a href="#">About</a></li>
                        <li><a href="#">Menu</a></li>
                        <li><a href="#">Contact</a></li>
                    </ul>
                </div>
                <div class="col-7 col-sm-5">
                    <h5>Our Address</h5>
                    <address>
                      121, Clear Water Bay Road<br>
                      Clear Water Bay, Kowloon<br>
                      HONG KONG<br>
                      Tel.: +852 1234 5678<br>
                      Fax: +852 8765 4321<br>
                      Email: <a href="mailto:confusion@food.net">confusion@food.net</a>
                   </address>
                </div>
                <div class="col-12 col-sm-4 align-self-center">
                    <div class="text-center">
                        <a href="http://google.com/+">Google+</a>
                        <a href="http://www.facebook.com/profile.php?id=">Facebook</a>
                        <a href="http://www.linkedin.com/in/">LinkedIn</a>
                        <a href="http://twitter.com/">Twitter</a>
                        <a href="http://youtube.com/">YouTube</a>
                        <a href="mailto:">Mail</a>
                    </div>
                </div>
           </div>
           <div class="row justify-content-center">             
                <div class="col-auto">
                    <p>© Copyright 2018 Ristorante Con Fusion</p>
                </div>
           </div>
        </div>
    </footer>
    <script type="text/javascript" src="node_modules\bootstrap\dist\css\bootstrap.js"></script>
    <script src="node_modules\jquery\dist\jquery.slim.min.js"></script>
    <script src="node_modules\jquery\dist\popper.min.js"></script>
</body>

</html>

尝试使用 cdn。

替换:

<link rel="stylesheet" type="text/css" href="node_modules\bootstrap\dist\css\bootstrap.min.css">

与:

<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

如果这不起作用,请删除上面的内容并添加:

<!-- CSS only --><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

有时 bootstrap 只需包含 css 文件即可工作。但某些功能可能需要 jQuery 及其脚本文件。