Код начальной загрузки работает в Fiddle, но не на локальном хостинге?

#html #localhost #bootstrap-modal #href #nav

#HTML #localhost #bootstrap-модальный #href #навигация

Вопрос:

У меня проблема, когда мой код начальной загрузки работает в JSFiddle, но не в моем браузере localhost. Ниже приведен код. Проблема возникает на вкладках навигации 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_modulesbootstrapdistcssbootstrap.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>$1,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;amp; Figures</h2>
            <div class="table-responsive">
            <table class="table table-striped">
                <thead class="thead-dark">
                    <tr>
                        <th>amp;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>$2,51,325</th>
                        <th>$1,250,375</th>
                        <th>$3,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_modulesbootstrapdistcssbootstrap.js"></script>
    <script src="node_modulesjquerydistjquery.slim.min.js"></script>
    <script src="node_modulesjquerydistpopper.min.js"></script>
</body>

</html>  

Ответ №1:

Попробуйте использовать cdn.

Заменить :

 <link rel="stylesheet" type="text/css" href="node_modulesbootstrapdistcssbootstrap.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 и их файлы сценариев могут потребоваться для некоторых функций.

Комментарии:

1. Я думаю, что проблема с моим кодом заключалась в использовании ссылок на скрипт! Я установил его с помощью npm и соответствующим образом использовал ссылку! <тип сценария=»текст / javascript» src=»node_modulesbootstrapdistcssbootstrap.js «></script> Использование приведенной выше ссылки исправило это. Большое вам спасибо 🙂