Angular MDBootstrap媒体对象布局
MDBootstrap是一个基于Material Design和bootstrap的Angular UI库,通过其无缝和易于使用的组件来制作有吸引力的网页。在这篇文章中,我们将知道如何在Angular MDBootstap中使用媒体对象布局。
媒体对象布局用于建立复杂和高度重复的组件,便于将媒体添加到一个元素中,将媒体与内容定位在一起,而不包裹在其周围,等等。
语法:
<div class="media">
<img class="d-flex mr-3" src="link" alt="text">
<div class="media-body">
Content
</div>
</div>
步骤:
- 从官方网站下载Angular MDBootstrap。
- 将文件提取到当前工作目录。
- 使用以下命令在当前项目中安装npm。
npm install
- 在创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
- 使用以下命令启动服务器。
ng serve
项目结构:完成安装后,它将看起来像下面这样。
Project Structure
例子1:这是一个基本的例子,说明了如何在Angular MDBootstrap中使用媒体对象布局。
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>Angular MDBootstrap Media Objects Layout</h4>
<br />
<div class="media">
<img class="mr-3" src=
"https://media.geeksforgeeks.org/wp-content/uploads/20220221143609/1.png"
alt="GFG_logo">
<div class="media-body">
<h5 class="mt-0 font-weight-bold">
GeeksforGeeks
</h5>
MDBootstrap is a Material Design and
bootstrap-based Angular UI library
that is used<br>to make good looking
webpages with its seamless and
easy-to-use component.
</div>
</div>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent{}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MDBBootstrapModule.forRoot(),
FormsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule{}
输出:
示例2:这个例子说明了如何在Angular MDBootstrap中改变媒体对象布局的对齐方式。
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>Angular MDBootstrap Media Objects Layout</h4>
<br />
<div class="media">
<img class="d-flex mr-3 align-self-start"
style="width:20px"
src=
"https://media.geeksforgeeks.org/wp-content/uploads/20220221143609/1.png"
alt="GFG_Logo">
<div class="media-body">
<h5 class="mt-0 font-weight-bold">
GeeksforGeeks
</h5>
MDBootstrap is a Material Design
and bootstrap-based Angular UI library
that is used<br>to make good looking
webpages with its seamless and
easy-to-use component.
</div>
</div>
<div class="media">
<img class="d-flex mr-3 align-self-center"
style="width:20px" src=
"https://media.geeksforgeeks.org/wp-content/uploads/20220221143609/1.png"
alt="GFG_logo">
<div class="media-body">
<h5 class="mt-0 font-weight-bold">
GeeksforGeeks
</h5>
MDBootstrap is a Material Design
and bootstrap-based Angular UI library
that is used<br>to make good looking
webpages with its seamless
and easy-to-use component.
</div>
</div>
<div class="media">
<img class=" d-flex mr-3 align-self-end"
style="width:20px" src=
"https://media.geeksforgeeks.org/wp-content/uploads/20220221143609/1.png"
alt="GFG_logo">
<div class="media-body">
<h5 class="mt-0 font-weight-bold">
GeeksforGeeks
</h5>
MDBootstrap is a Material Design
and bootstrap-based Angular UI library
that is used<br>to make good looking
webpages with its seamless and
easy-to-use component.
</div>
</div>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent{}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MDBBootstrapModule.forRoot(),
FormsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule{}
输出: