Angular Material Basic Card Section
Last Updated :
04 Jan, 2022
Angular Material is a UI component library which is developed by Google so that Angular developers can develop modern applications in a structured and responsive way. By making use of this library, we can greatly increase the user experience of an end-user thereby gaining popularity for our application. This library contains modern ready-to-use elements which can be directly used with minimum or no extra code.
The <mat-card> is a container for the content that can be used to insert the media, text & action in context to the single subject. The basic requirement for design the card is only an <mat-card> element that has some content in it, that will be used to build simple cards.
Syntax:
<mat-card> Content </mat-card>
This element has opening tag followed with the content or some code & ended with the closing tag. Angular Material facilitates the number of preset sections that can be used with the <mat-card> element, which is given below:
Element Name | Description of the Element |
---|
<mat-card-title>
| Title of the respective card
|
<mat-card-subtitle>
| The subtitle of the respective card
|
<mat-card-content>
| All the data and information which is the body of the card needs to be written in this section.
|
<mat-card-actions>
| This tag is used to mention all the events like submit, cancel and etc to be written in the card.
|
<mat-card-header>
| It is used to mention all the details on the header of the card like title, subtitle etc.
|
<mat-card-footer> | This section is anchored to the bottom of the card., that contains the copyright symbol with year, company name, etc.
|
The above elements are primarily used for pre-styled content containers, instead of using any additional APIs. However, the align property with <mat-card-actions>, is mainly used to position the actions at the 'start' or 'end' of the container.
Installation Syntax:
In order to use the Basic Card Section in the Angular Material, we must have Angular CLI installed in the local machine, that will help to add and configure the Angular material library. After satisfying the required condition, type the following command on the Angular CLI:
ng add @angular/material
Please refer to the Adding Angular Material Component to Angular Application article for the detailed installation procedure.
Project Structure:
After successful installation, the project structure will look like the following:
Example: The below example illustrates the implementation of the Angular Material Card.
app.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { AppComponent } from "./app.component";
import { MatCardModule } from "@angular/material/card";
import { MatButtonModule } from "@angular/material/button";
@NgModule({
imports:
[BrowserModule,
FormsModule,
MatCardModule,
MatButtonModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
app.component.css
@import "~material-icons/iconfont/material-icons.css";
p {
font-family: "Lato", sans-serif;
text-align: justify;
}
.example-card {
max-width: 450px;
margin: 10px;
}
mat-card-subtitle {
font-size: 18px;
}
mat-card-title {
color: green;
font-size: 55px;
justify-content: center;
display: flex;
}
app.component.html
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>GeeksforGeeks</mat-card-title>
<mat-card-subtitle>
One stop solution for all CS Subjects
</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<p>
With the idea of imparting programming
knowledge, Mr. Sandeep Jain, an IIT Roorkee
alumnus started a dream, GeeksforGeeks.
Whether programming excites you or you feel
stifled, wondering how to prepare for
interview questions or how to ace data
structures and algorithms, GeeksforGeeks
is a one-stop solution. With every tick of
time, we are adding arrows in our quiver.
From articles on various computer science
subjects to programming problems for practice,
from basic to premium courses, from technologies
to entrance examinations, we have been building
ample content with superior quality. In a short
span, we have built a community of 1 Million+
Geeks around the world, 20,000+ Contributors and
500+ Campus Ambassador in various colleges across
the nation. Our success stories include a lot of
students who benefitted in their placements and
landed jobs at tech giants. Our vision is to
build a gigantic network of geeks and we are
only a fraction of it yet.
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button style=
"background-color:blue;
color:white">
LIKE
</button>
<button mat-button style=
"background-color:green;
color:white">
SHARE
</button>
</mat-card-actions>
</mat-card>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
}
Output:
Reference: https://material.angular.io/components/card/overview#basic-card-sections
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read