Bootstrap Dropdown未显示

时间:2018-02-27 03:24:08

标签: html css asp.net twitter-bootstrap razor

我正在为作业建立一个网站,教师向我们展示了如何根据https://docs.microsoft.com/en-us/aspnet/web-pages/overview/ui-layouts-and-themes/3-creating-a-consistent-look使用_header,_footer和_layout

在我向_header.cshtml中的导航栏添加下拉列表之前,一切都运行良好。当我的网站使用普通的HTML和CSS时,它起作用了。但是,一旦我添加了新的布局,下拉列表就不会起作用。

_Layout.cshtml:

    <!DOCTYPE html>
<html>
    <head>
        <title>@Page.Title</title>
        @RenderSection("head", required: false)
    </head>
<body>
@RenderPage("~/shared/_header.cshtml")
@RenderBody()
@RenderPage("~/shared/_footer.cshtml")
</body>
</html>

_Header.cshtml:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="~/css/bootstrap.css" rel="stylesheet" />
    <link href="~/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/css/Site.css" rel="stylesheet" />
    <link href="~/css/viewImg.css" rel="stylesheet" />

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
    <body>
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle " data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">VPC</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a href="~/index.cshtml">Home</a></li>
                    <li><a href="~/About.cshtml">About</a></li>
                    <li><a href="~/Contact.cshtml">Contact</a></li>
                    <li class="dropdown">         
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">More <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="~/Cameras.cshtml">Cameras</a></li>
                            <li><a href="~/Photography.cshtml">Photography</a></li>
                            <li><a href="~/Videography.cshtml">Videography</a></li>
                        </ul>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li class="active">
                        <a href="~/Login.cshtml">
                            <img class="signin-img" src="~/img/signin.png" width="26" height="26"/>
                        </a>
                    </li>
                </ul>
            </div><!--/.nav-collapse -->
        </div><!--/.container-fluid -->
    </nav>
    </body>
</html>

index.cshtml :(这是主页)

@{
    Page.Title = "Title goes here";
    Layout = "~/shared/_Layout.cshtml";
    //Layout = "Your Layout Page goes here";
}

<div class="container">
    <div class="jumbotron" style="background-image: url(img/vpc_main.jpg); background-size: 100%; opacity: 0.6;">
        <h1 style="color: #ffffff; text-align: center; opacity: 2;">Video Photography Camera</h1>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-sm-4">
            <section>
                <img class="img-responsive" src="img/cameras.jpg" />
                <h1 class="wtext">Cameras</h1>
                <p class="wtext">
                    Search our catalog which includes the best cameras on the market. From DSLR to Mirrorless.
                </p>
                <a class="btn btn-default form-control" href="cameras.cshtml">Go To ></a>
            </section>
        </div>
        <div class="col-sm-4">
            <section>
                <img class="img-responsive" src="img/photography.jpg" />
                <h1 class="wtext">Photography</h1>
                <p class="wtext">
                    Search our catalog of pictures that ranges from nature to portrait photography.
                </p>
                <a class="btn btn-default form-control" href="photography.cshtml">Go to ></a>
            </section>
        </div>
        <div class="col-sm-4">
            <section>
                <img class="img-responsive" src="img/videography.jpg" />
                <h1 class="wtext">Videography</h1>
                <p class="wtext">
                    Search our catalog of videos that vary from montage to action videography.
                </p>
                <a class="btn btn-default form-control" href="videography.cshtml">Go to ></a>
            </section>
        </div>
    </div>
    <div class="container-fluid">

    </div>
    <br /><br />

</div>

Cameras.cshtml :(这是我要通过下拉列表重定向的页面)

@{
    Page.Title = "Title goes here";
    Layout = "~/shared/_Layout.cshtml";
}

<div class="container">
    <br />
    <h1>Cameras</h1>
    <div class="row">
        <div class="col-lg-3" style="border-right: 1px solid #000000; height: 600px;">
            <h3 style="text-align: center"><a href="https://www.sony.com/electronics/interchangeable-lens-camera-products/t/interchangeable-lens-cameras?bestfor=advanced-amateur">Sony ></a></h3>
            <h3 style="text-align: center"><a href="https://www.usa.canon.com/internet/portal/us/home/products/list/cameras/dslr/">Canon ></a></h3>
            <h3 style="text-align: center"><a href="http://imaging.nikon.com/lineup/dslr/index.htm">Nikon ></a></h3>
        </div>
        <div class="col-lg-3">
            <h2 style="text-align: center">Sony</h2>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/sony_a7RIII.jpg" width="240" alt="A7R Mark III" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.sony.com/electronics/interchangeable-lens-cameras/ilce-7rm3'">
                    <div class="imgtext">A7R Mark III</div>
                </div>
            </div>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/sony_a6500.jpg" width="240" alt="a6500" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.sony.com/electronics/interchangeable-lens-cameras/ilce-6500-body-kit'">
                    <div class="imgtext">a6500</div>
                </div>
            </div>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/sony_rx100mkV.jpg" width="240" alt="rx100mk Mark V" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.sony.com/electronics/cyber-shot-compact-cameras/dsc-rx100m5'">
                    <div class="imgtext">rx100mk Mark V</div>
                </div>
            </div>
            <br />
        </div>
        <div class="col-lg-3">
            <h2 style="text-align: center">Canon</h2>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/canon_1dX.jpg" width="240" alt="1D X" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.usa.canon.com/internet/portal/us/home/products/details/cameras/dslr/eos-1d-x'">
                    <div class="imgtext">1D X</div>
                </div>
            </div>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/canon_6dII.jpg" width="240" alt="6D Mark II" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.usa.canon.com/internet/portal/us/home/products/details/cameras/dslr/eos-6d-mark-ii'">
                    <div class="imgtext">6D Mark II</div>
                </div>
            </div>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/canon_rebelt6i.jpg" width="240" alt="Rebel t6i" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.usa.canon.com/internet/portal/us/home/products/details/cameras/dslr/eos-rebel-t6i-ef-s-18-55mm-is-stm'">
                    <div class="imgtext">Rebel t6i</div>
                </div>
            </div>
            <br />
        </div>
        <div class="col-lg-3">
            <h2 style="text-align: center">Nikon</h2>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/nikon_d5.jpg" width="240" alt="D5" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.nikonusa.com/en/nikon-products/product/dslr-cameras/d5.html'">
                    <div class="imgtext">D5</div>
                </div>
            </div>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/nikon_d800.jpg" width="240" alt="D810" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.nikonusa.com/en/nikon-products/product/dslr-cameras/d810.html'">
                    <div class="imgtext">D810</div>
                </div>
            </div>
            <br />
            <div class="imgcontainer">
                <img src="img/Cameras/nikon_d810.jpg" width="240" alt="D3400" class="image" />
                <div class="imgoverlay" onclick="location.href = 'https://www.nikonusa.com/en/nikon-products/product/dslr-cameras/d3400.html'">
                    <div class="imgtext">D3400</div>
                </div>
            </div>
            <br />
        </div>
    </div>
    <div>

    </div>
</div>

site.css(自定义样式表)

body {
    padding-top: 50px;
    padding-bottom: 20px;
    /*background-image: url('../img/computer-programming-background-1461985468sGF.jpg');*/  
    background-image: url(../img/background02.jpg);
}

.navbar {
    padding: 0;
    border: 0;
}

/* Wrapping element */
/* Set some basic padding to keep content from hitting the edges */
.body-content {
    padding-left: 15px;
    padding-right: 15px;
}

/* Set widths on the form inputs since otherwise they're 100% wide */
input,
select,
textarea {
    max-width: 280px;
}


/* Responsive: Portrait tablets and up */
@media screen and (min-width: 768px) {
    .jumbotron {
        margin-top: 10px;
    }

    .body-content {
        padding: 0;
    }
}

@keyframes pics {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.img-effect {
    animation: pics 10s infinite;
    animation-play-state: paused;
}
.img-effect:hover {
    animation: pics 10s infinite;
    animation-play-state: running;
}

/* login and signup */

.login-container {
    position: center;
}

/* overide button color: */

.btn-default {
    color: #cccccc;
    /*background-color: #333333;
    border-color: #cccccc;*/
    opacity: 0.8;
    background-image: url(../img/btn02_img.jpg);
    background-size: 100%;
    text-align: center;
}

.btn-default:hover,
.btn-default:focus,
.btn-default:active,
.btn-default.active,
.open .dropdown-toggle.btn-default {
    color: #adadad;
    /*background-color: #cccccc;
    border-color: #adadad;
    background-image: url(../img/btn01_img.jpg);*/
    opacity: 1;
    background-size: 100%;
    text-align: center;
}

/* Custom Glyphicons for sign in and sign out*/

.signin-img {
    filter: invert(100%);
}

/* style the container */

.container {
    background: rgba( 192, 192, 192, 0.3 );
}

.wtext {
    color: #ffffff;
}

viewImg.css :( Cameras.cshtml的样式表)

.imgcontainer {
    position: relative;
    width: 91.5%;
}

.image {
    display: block;
    width: 240px;
    height: auto;
}

.imgoverlay {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100%;
    width: 100%;
    opacity: 0;
    transition: .5s ease;
    background-color: #000000;
}

.imgcontainer:hover .imgoverlay {
    opacity: 0.8;
    cursor: pointer;
}

.imgtext {
    color: white;
    font-size: 20px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    text-align: center;
}

This is the Picture of the Home Webpage

基本上,我的问题是:为什么下拉列表不起作用,有没有办法解决它? (在图片中,下拉列表位于导航栏的左侧)。

1 个答案:

答案 0 :(得分:0)

你为什么要包括Bootstrap 3次?开始单独评论这些内容,看看它是否有所作为,并在每次测试时进行完整的浏览器刷新。

此外,将它们移动到布局文件中,以便它们影响所有视图。