After adding the Angular Material component "Toolbar" to my project, I noticed that it does not appear the same as it does in the example provided. Despite using the same styles, the outcome is different.
Here is what the example looks like on the project website:
https://i.sstatic.net/ESP42.png
To debug the issue, I created a blank Angular app and included Angular Material along with just the toolbar component. Surprisingly, it displayed the same way as in my actual project, shown here: here
https://i.sstatic.net/zCLNG.png
Below is the HTML and CSS code from the example that works correctly:
I have replicated it on StackBlitz here
index.html
<link href="https://fonts.googleapis.com/icon?family=Material+Icons&display=block" rel="stylesheet">
<div class="mat-app-background basic-container">
<toolbar-basic-example>loading</toolbar-basic-example>
</div>
<span class="version-info">Current build: 10.2.0</span>
component html
<mat-toolbar>
<button mat-icon-button class="example-icon" aria-label="Example icon-button with menu icon">
<mat-icon>menu</mat-icon>
</button>
<span>My App</span>
<span class="example-spacer"></span>
<button mat-icon-button class="example-icon favorite-icon" aria-label="Example icon-button with heart icon">
<mat-icon>favorite</mat-icon>
</button>
<button mat-icon-button class="example-icon" aria-label="Example icon-button with share icon">
<mat-icon>share</mat-icon>
</button>
</mat-toolbar>
style.scss
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
body {
font-family: Roboto, Arial, sans-serif;
margin: 0;
}
.basic-container {
padding: 30px;
}
component css
.example-spacer {
flex: 1 1 auto;
}
This is my debugging Angular app, which I want to resemble the example. You can view and edit it on StackBlitz here
index.html
<!doctype html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons&display=block" rel="stylesheet">
</head>
<body class="mat-typography">
<div class="mat-app-background basic-container">
<app-root></app-root>
</div>
</body>
</html>
component html
<mat-toolbar>
<button mat-icon-button class="example-icon" aria-label="Example icon-button with menu icon">
<mat-icon>menu</mat-icon>
</button>
<span>My App</span>
<span class="example-spacer"></span>
<button mat-icon-button class="example-icon favorite-icon" aria-label="Example icon-button with heart icon">
<mat-icon>favorite</mat-icon>
</button>
<button mat-icon-button class="example-icon" aria-label="Example icon-button with share icon">
<mat-icon>share</mat-icon>
</button>
</mat-toolbar>
styles.scss
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
body {
font-family: Roboto, Arial, sans-serif;
margin: 0;
}
.basic-container {
padding: 30px;
}
component scss
.example-spacer {
flex: 1 1 auto;
}
What are the reasons why my Angular app does not resemble the example from the Angular Material website, and how can I correct it to achieve the desired outcome?