我用于导航栏的 style.scss
.navbar {
background-color: transparent;
}
.top-nav-collapse {
background-color: #3f51b5;
}
@media only screen and (max-width: 768px) {
.navbar {
background-color: #3f51b5;
}
}
我的 home.component.html 以及我的背景图片所在的 home.component.html
header.masthead {
position: relative;
background: url("https://res.cloudinary.com/dn1b66xo5/image/upload/c_scale,q_auto:best,w_750/v1509987250/photo-1503767849114-976b67568b02_li9wxo.jpg") no-repeat fixed center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
padding-top: 8rem;
padding-bottom: 8rem; }
header.masthead h1 {
font-size: 2rem; }
@media (min-width: 768px) {
header.masthead {
padding-top: 12rem;
padding-bottom: 12rem; }
header.masthead h1 {
font-size: 3rem; } }
<header class="masthead h-75 text-white text-center">
<div class="overlay"></div>
<div class="container">
<div class="home-info">
<h1 class="cover-heading">Welcome to Noodles Hub</h1>
<p class="lead">Order your delicious meals from your <strong><b>HALLS AND OFFICES</b></strong>.</p>
<p class="lead">
<a routerLink="/products" class="btn btn-lg btn-success">Select Restaurant</a>
</p>
</div>
</div>
</header>
我的导航栏组件.html
<nav>
<mdb-navbar SideClass="navbar navbar-expand-lg navbar-dark fixed-top scrolling-navbar top-nav-collapse" [containerInside]="false">
<logo><a class="navbar-brand" routerLink="/">Noodles Hub</a></logo>
<links>
<ul class="navbar-nav mr-auto">
<li class="nav-item active" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
<a routerLink="/" class="nav-link waves-light" mdbRippleRadius>Home<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item" routerLinkActive="active">
<a class="nav-link waves-light" mdbRippleRadius routerLink="/shopping-cart">
<i class="fa fa-shopping-cart fa-lg" aria-hidden="true"></i>
<span class="badge badge-warning badge-pill" *ngIf="cart$ | async as cart">
{{ cart.totalItemsCount }}
</span>
</a>
</li>
</ul>
<ul class="navbar-nav ml-auto nav-flex-icons">
<li class="nav-item"routerLinkActive="active">
<a routerLink="/restaurants" class="nav-link waves-light">Restaurants</a>
</li>
<ng-template #anonymousUser>
<li class="nav-item" routerLinkActive="active">
<a class="nav-link waves-light" routerLink="/login">Login <i class="fa fa-user-plus" aria-hidden="true"></i></a>
</li>
</ng-template>
<li *ngIf="appUser; else anonymousUser" class="nav-item dropdown" dropdown routerLinkActive="active">
<a *ngIf="appUser.name" class="nav-link dropdown-toggle waves-light" dropdownToggle mdbRippleRadius>{{ appUser.name }}</a>
<a *ngIf="!appUser.name" class="nav-link dropdown-toggle waves-light" dropdownToggle mdbRippleRadius>Welcome</a>
<div *dropdownMenu class="dropdown-menu dropdown dropdown-primary" role="menu">
<a class="dropdown-item waves-light" mdbRippleRadius routerLink="/my/orders">My Orders</a>
<ng-container *ngIf="appUser.isAdmin">
<a class="dropdown-item waves-light" mdbRippleRadius routerLink="/admin/orders">Manage Orders</a>
<a class="dropdown-item waves-light" mdbRippleRadius routerLink="/admin/restaurants">Manage Products</a>
</ng-container>
<div class="divider dropdown-divider"></div>
<a mdbRippleRadius (click)="logout()" class="dropdown-item waves-light">Log Out</a>
</div>
</li>
</ul>
</links>
</mdb-navbar>
</nav>
Mdb的标记实际上正在工作,但我遇到的问题是我的导航栏是一个不同的组件,因此背景图像不会与导航栏重叠