Angular PrimeNG TabMenu Styling
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG TabMenu Styling.
The TabMenu component allows the creation of the menu in the form of a tier. It displays submenus in nested overlays. The TabMenu Styling classes allow changing the design of the component from the default design.
Angular PrimeNG TabMenu Styling:
- p-tabmenu: It is a container element.
- p-tabmenu-nav: It is a list element of headers.
- p-tabmenuitem: It is an element for the menu items.
- p-menuitem-link: It is a link inside a menu item.
- p-menuitem-text: It is a label of a menu item.
- p-menuitem-icon: It is an icon of a menu item.
Syntax:
:host ::ng-deep .p-tabmenu { // CSS Styling }
Creating Angular application & Module Installation:
Step 1: Create an Angular application using the following command.
ng new Beginner_angular
Step 2: After creating your project folder i.e. Beginner_angular, move to it using the following command.
cd Beginner_angular
Step 3: Install PrimeNG and CDK in your given directory.
npm install primeng --save npm install primeicons --save
Project Structure: The project structure will look like the following:
Steps to run the above file: Run the below command
ng serve --save
Example 1: Below is the example code that illustrates the use of Angular PrimeNG TabMenu Styling. In the following example, we have a TabMenu with a border around the list
- app.component.html:
HTML
< h1 style = "color: green; text-align: center;" > w3wiki </ h1 > < h3 >Angular PrimeNG TabMenu Styling</ h3 > < p-tabMenu [model]="items"></ p-tabMenu > |
- app.component.ts:
Javascript
import { Component } from "@angular/core" ; import { MenuItem } from "primeng/api" ; @Component({ selector: "app-root" , templateUrl: "./app.component.html" , styleUrls: [ "./app.component.css" ] }) export class AppComponent { items: MenuItem[]; ngOnInit() { this .items = [ { label: "SQL" , icon: "pi pi-database" }, { label: "Follow w3wiki on youtube" , icon: "pi pi-fw pi-youtube" }, { label: "Webite" , icon: "pi pi-fw pi-globe" }, { label: "Find all Documentation" , icon: "pi pi-fw pi-file" } ]; } } |
- app.component.css:
CSS
:host ::ng-deep .p-tabmenu { border : 10px green ; border-style : dashed ; padding : 2px ; } |
- app.module.ts:
Javascript
import { NgModule } from "@angular/core" ; import { BrowserModule } from "@angular/platform-browser" ; import { RouterModule } from "@angular/router" ; import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ; import { AppComponent } from "./app.component" ; import { MessageModule } from "primeng/message" ; import { TabMenuModule } from "primeng/tabmenu" ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, MessageModule, TabMenuModule, RouterModule.forRoot([{ path: "" , component: AppComponent }]) ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {} |
Output:
Example 2: Below is another example code that illustrates the use of Angular PrimeNG TabMenu Styling. In the following example, we have menu logos with larger sizes and shadows.
- app.component.html:
HTML
< h1 style = "color: green; text-align: center;" > w3wiki </ h1 > < h3 >Angular PrimeNG TabMenu Styling</ h3 > < p-tabMenu [model]="items"></ p-tabMenu > |
- app.component.css:
CSS
:host ::ng-deep .p-menuitem- icon { font-size : 32px ; box-shadow: 4px 4px 4px 4px green ; } |
- app.component.ts:
Javascript
import { Component } from "@angular/core" ; import { MenuItem } from "primeng/api" ; @Component({ selector: "app-root" , templateUrl: "./app.component.html" , styleUrls: [ "./app.component.css" ] }) export class AppComponent { items: MenuItem[]; ngOnInit() { this .items = [ { label: "SQL" , icon: "pi pi-database" }, { label: "Follow w3wiki on youtube" , icon: "pi pi-fw pi-youtube" }, { label: "Webite" , icon: "pi pi-fw pi-globe" }, { label: "Find all Documentation" , icon: "pi pi-fw pi-file" } ]; } } |
- app.module.ts:
Javascript
import { NgModule } from "@angular/core" ; import { BrowserModule } from "@angular/platform-browser" ; import { RouterModule } from "@angular/router" ; import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ; import { AppComponent } from "./app.component" ; import { MessageModule } from "primeng/message" ; import { TabMenuModule } from "primeng/tabmenu" ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, MessageModule, TabMenuModule, RouterModule.forRoot([{ path: "" , component: AppComponent }]) ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {} |
Output:
Reference: http://primefaces.org/primeng/tabmenu