Angular MDBootstrap网格系统布局
MDBootstrap是一个基于Material Design和bootstrap的Angular UI库,通过其无缝和易于使用的组件来制作好看的网页。在这篇文章中,我们将知道如何在Angular MDBootstap中使用Tooltips组件。网格系统布局是创建为移动设备优化的布局的一个伟大工具。 Bootstrap的网格系统使用一系列的容器、行和列来布局和对齐内容。我们可以定义列的大小为’xs’、’sm’、’md’、’xl’和’xxl’。 基本上,网格系统布局是用flexbox构建的,这使得它完全响应。它是一个强大的工具,有很多功能。
语法:
<div class="container">
<div class="row">
<div>
GeeksforGeeks
</div>
</div>
</div>
步骤:
- 下载 Angular MDBootstrap from: https://mdbootstrap.com/docs/angular/getting-started/installation/
- 提取文件并切换到工作目录。
- 使用以下命令在当前项目中安装npm。
npm install
or
npm install -y
- 在创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
- 使用以下命令启动服务器。
ng serve
项目结构:完成安装后,它将看起来像下面这样。
例子1:这是一个基本的例子,说明了如何使用网格系统布局。
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>Angular MDBootstrap Grid System Component</h4>
<br />
<div class="container">
<div class="row">
<div class="col-sm bg-danger rounded m-3">
GeeksforGeeks
</div>
<div class="col-sm bg-warning rounded m-3">
GeeksforGeeks
</div>
<div class="col-sm bg-success rounded m-3">
GeeksforGeeks
</div>
</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 { }
输出:
例子2:在这个例子中,我们将知道如何添加不同宽度的行。
<div id='gfg'>
<h2>GeeksforGeeks</h2>
<h4>Angular MDBootstrap Grid System Component</h4>
<br />
<div class="container">
<div class="row">
<div class="col-sm bg-danger rounded m-3">
One of the 2
</div>
<div class="col-sm bg-warning rounded m-3">
One of the 2
</div>
</div>
<div class="row">
<div class="col-sm bg-success rounded m-3">
One of the 3
</div>
<div class="col-sm bg-secondary rounded m-3">
One of the 3
</div>
<div class="col-sm bg-info rounded m-3">
One of the 3
</div>
</div>
<div class="row">
<div class="col-sm bg-light rounded m-3">
One of the 4
</div>
<div class="col-sm bg-dark text-light rounded m-3">
One of the 4
</div>
<div class="col-sm bg-primary rounded m-3">
One of the 4
</div>
<div class="col-sm bg-warning rounded m-3">
One of the 4
</div>
</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 { }
输出: