Styles in Angular Floating action button component

20 Dec 20225 minutes to read

This section explains the different styles of Floating Action Button.

FAB styles

The Angular Floating Action Button supports the following predefined styles that can be defined using the cssClass property. You can customize by replacing the cssClass property with the below defined class.

cssClass Description
e-primary Used to represent a primary action.
e-outline Used to represent an appearance of button with outline.
e-info Used to represent an informative action.
e-success Used to represent a positive action.
e-warning Used to represent an action with caution.
e-danger Used to represent a negative action.
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<div id="targetElement" style="position:relative;min-height:350px;border:1px solid;">
                </div>
                <!-- To Render Floating Action Button with applied warning style -->
                <button ejs-fab id='fab' iconCss= 'e-icons e-edit' cssClass= 'e-warning' target='#targetElement'></button>`
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { FabModule } from '@syncfusion/ej2-angular-buttons'

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        FabModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Predefined Floating Action Button styles provide only the visual indication. So, Floating Action Button content property should define the Floating Action Button style for the users of assistive technologies such as screen readers.

Styles customization

To modify the Floating Action Button appearance, you need to override the default CSS of Floating Action Button component. Please find the list of CSS classes and its corresponding section in Floating Action Button component. Also, you have an option to create your own custom theme for the components using our Theme Studio.

CSS Class Purpose of Class
.e-fab.e-btn To customize the FAB.
.e-fab.e-btn:hover To customize the FAB on hover.
.e-fab.e-btn:focus To customize the FAB on focus.
.e-fab.e-btn:active To customize the FAB on active.
.e-fab.e-btn-icon To customize the style of FAB icon.

Show text on hover

By using cssClass, you can customize the Floating Action Button to show text on hover with applied transition effect. For detailed information, refer index.css file below.

The content will behave the same , when the enableHtmlSantiizer is enabled. Since we are adding only the valid tags in content, sanitizing the content will not affect it.

import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<div id="targetElement" style="position:relative;min-height:350px;border:1px solid;">
                </div>
                <!-- To Render Floating Action Button -->
                <button ejs-fab id='fab' iconCss= 'e-icons e-edit' content='<span class="text-container"><span class="textEle">Edit</span></span>' cssClass= 'fab-hover' target='#targetElement'></button>`
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { FabModule } from '@syncfusion/ej2-angular-buttons'

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        FabModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);