skip to Main Content

I’m still very new to angular. I’ve created a component named header via the cli. I have added the html for the navbar i want to use. I also have some css i want to add. I put it in the scss file but it doesnt seem to be working.
here’s my css:

html,
body,
header,
.view {
    height: 100%;
}
/* Navigation*/

.navbar {
    background-color: transparent;
}

.top-nav-collapse {
    background-color: #4285F4;
}
@media only screen and (max-width: 768px) {
    .navbar {
        background-color: #4285F4;
    }
}
/*Intro*/
.view {
    background: url("https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(54).jpg")no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

here’s my html:

<navbar SideClass="navbar navbar-toggleable-md navbar-dark introZindex fixed-top">
    <logo>
        <a class="logo navbar-brand">Navbar</a>
    </logo>
    <links>
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link">Features</a>
            </li>
            <li class="nav-item">
                <a class="nav-link">Pricing</a>
            </li>
        </ul>
        <ul class="navbar-nav nav-flex-icons">
            <li class="nav-item">
                <a class="nav-link"><i class="fa fa-facebook"></i></a>
            </li>
            <li class="nav-item">
                <a class="nav-link"><i class="fa fa-twitter"></i></a>
            </li>
            <li class="nav-item">
                <a class="nav-link"><i class="fa fa-instagram"></i></a>
            </li>
        </ul>
    </links>
</navbar>
<!-- Main -->
<div class="view hm-black-strong">
    <div class="full-bg-img flex-center">
        <div class="container">
            <div class="white-text text-center wow fadeInUp">
                <h2>This Navbar is fixed and transparent</h2>
                <br>
                <h5>It will always stay visible on the top, even when you scroll down</h5>
                <br>
                <p>Full page intro with background image will be always displayed in full screen mode, regardless of device </p>
            </div>
        </div>
    </div>
</div>
<!-- /.Main -->
<main class="text-center py-5 mt-3">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <p align="justify">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
            </div>
        </div>
    </div>
</main>

here is the ts file:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

here is my app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';

import { MDBBootstrapModule } from './typescripts/angular-bootstrap-md/free';
import { MDBBootstrapModulePro } from './typescripts/angular-bootstrap-md/pro';
import { AgmCoreModule } from '@agm/core';
import { HeaderComponent } from './header/header.component';

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpModule,
    MDBBootstrapModule.forRoot(),
    MDBBootstrapModulePro.forRoot(),
    // https://developers.google.com/maps/documentation/javascript/get-api-key?hl=en#key
    // AgmCoreModule.forRoot({
    //   apiKey: 'google_maps_api_key'
    // })
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [NO_ERRORS_SCHEMA]
})
export class AppModule { }

Can anyone give me advice as to what I’m doing wrong here? the only thing in my app.component.html is which is the tag for the above mentioned component.

4

Answers


  1. Chosen as BEST ANSWER

    Alright, I got in touch with the MDBootstrap guys and found there was a missing helper class on the navbar in the html file. Once i added bg-primary it worked. So it looked like this: <navbar SideClass="navbar navbar-toggleable-md navbar-dark introZindex fixed-top bg-primary">


  2. In your app.component.ts file make sure @Component({}) contains StylesUrls[] or Styles[]. If you have created App.component using Cli then there would be StylesUrls['app.component.css'].

    So open your app.component.css file and write all the CSS code there to style your app.component.html.

    If you are using styles: [] define all the styling between [‘styling goes here’].

    Because you have a lot of styling so use stylingUrls[‘directory/filename.css’].

    Update:

    If you are following this procedure and still not working. Then restart your virtual server. More info about this here: "Port 4200 is already in use" when running the ng serve command

    Login or Signup to reply.
  3. Update

    Just see navbar tag on your html template. Did you declare (in module) and import it?


    I put it in the scss file

    I guess you didn’t config for styling extension.

    Please check angular-cli.json and add these lines

    "defaults": {
        "styleExt": "scss"
    }
    

    Or run the command

    ng set defaults.styleExt scss
    

    Then please ensure that you link correct location to your styling file.

    Login or Signup to reply.
  4. You didn’t add color to your navbar and that’s the only reason why u don’t see styles. It’s enough if you add bg-primary class (or any other with the color you prefer) to your SideClass.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search