Making a floating action button in Ionic

I am currently working on creating an action floating button using the Ionic framework. While I have successfully created a basic button, I am now looking to add some stylish effects and make additional buttons appear upon interaction. I understand that this can easily be achieved using ionic-material, but I prefer to accomplish this task using AngularJS, Ionic, and CSS only.

HTML

<div class="float-button">
    <span class="height-fix">
        <a class="content" ui-sref="home">
            <i class="ion-ios-home"> </i>
        </a>
    </span>
</div>

CSS

.float-button {
    background-color: $heading-color;
    opacity: 0.9;
    color: white;
    border-radius: 50%;
    /*border-radius:15% 0 0 0;*/
    width: 30px;
    padding: 25px;
    font-size: 30px;
    position: fixed;
    bottom: 10%; /* Adjust height */
    right: 5%; /* Adjust position */
    z-index: 1000;
}
.float-button .height_fix {
    margin-top: 100%;
    border: 1px solid red;
}
.float-button .content {
    position: absolute;
    left: 0;
    top: 50%;
    height: 100%;
    width: 100%;
    text-align: center;
    margin-top: -20px;
    color: $app-background-color;
}

Answer №1

Give this a try

  <ion-view view-title="List of Available Jobs">
   <ion-content class="padding has-header has-subheader">
     <ion-item ng-repeat="job in jobsList">
       <h2>{{job.title}}</h2>
       <p>{{job.description}}</p>
     </ion-item>
   </ion-content>

   <div class="float-button">
     <span class="height-fix">
       <button id="fab-profile" ui-sref="app.jobAdd" class="button button-fab button-fab-bottom-right fab-fixed button-assertive pane" nav-view="active" style="opacity: 1; transform: translate3d(0%, 0px, 0px);">
         <i class="icon ion-plus"></i>
       </button>
     </span>
   </div>
 </ion-view>

CSS Style

.float-button {
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
  width: 30px;
  padding: 30px;
  font-size: 40px;
  background: $warning;
  position: fixed;
  bottom: 20px; /* Adjust positioning as needed */
  right: 20px; /* Adjust positioning as needed */
  z-index: 9999;
 }

 .float-button .height_fix {
   margin-top: 100%;
 }

 .float-button .content {
   position: absolute;
   left: 0;
   top: 50%;
   height: 100%;
   width: 100%;
   text-align: center;
   margin-top: -20px; /* Must be half the font size */
   color: $light;
   }

Give it a shot and see if it helps

Answer №2

To add a floating button to your HTML page, create a file named "your_page_name.scss" and include the following styles:

.float-button {
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
  width: 30px;
  padding: 30px;
  font-size: 16px;
  background: #32db64;
  background-color: #32db64 !important;
  color: #ffffff !important;
  position: fixed;
  bottom: 20px; /* Adjust as needed */
  right: 20px; /* Adjust as needed */
  z-index: 9999;
}
.float-button .height_fix {
  margin-top: 100%;
}
.float-button.content {
  position: absolute;
  left: 0;
  top: 50%;
  height: 100%;
  width: 100%;
  text-align: center;
  margin-top: -20px; /* Must be half the font size */
  color: light;
} 
 Add the following code at the end of your HTML page after the ion-content tag:
<!-- Start of float-button -->
 <div class="float-button">
  <span class="height-fix">
    <a ui-sref="add-trip" class="content">
      <i class="ion-plus-round" (click)="newContact()">Add</i>
    </a>
  </span>
 </div>
 <!-- End of float-button -->

I hope this explanation helps you implement the floating button correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

angular-chart custom tooltip positioning issue

Hello everyone! I'm having trouble fixing the tooltip position when hovering over a point. I've searched through various posts on StackOverflow and have tried all the examples provided in my implementation: https://github.com/chartjs/Chart.js/tr ...

Traversing through nested arrays within nested objects using AngularJS

In my project, I am utilizing angularjs 1 and dealing with a complex json object that has multiple levels of nesting. My goal is to use ng-repeat in order to access a nested array within the json structure. [{ "information": { "name": "simdi jinki ...

Is there a way to dynamically expand and collapse all table rows, with the latest row always remaining visible, using pure JavaScript?

I have a form input field where I enter data. The entered data is then displayed in a table as a new row, with the most recent entry at the top. What I want to achieve is to show only the newest row in the table and hide all other rows. When I hover over ...

Error-free ngClick doesn't trigger AngularJS controller method

I am struggling to trigger the removePlayer(playerId) method upon clicking a button. However, it seems that the method is not being called, as I have placed a console.log() statement at the top and the console remains empty. This situation has left me puz ...

What is preventing me from setting a background image in Angular 13?

Trying a different approach based on advice from Stack Overflow, I attempted the following: <div [style.background-image]="'url(https://picsum.photos/200)'"></div> Unfortunately, this resulted in no effect and the image was ...

Unable to display socket data in Angular js Table using ng-repeat

div(ng-controller="dashController") nav.navbar.navbar-expand-sm.navbar-dark.fixed-top .container img(src='../images/Dashboard.png', alt='logo', width='180px') ul.navbar-nav li.nav-item ...

Tips for adjusting image size using media queries

How can I ensure that the image resizes correctly on smaller screens? Currently, the image spills over the container and there are gaps between the top/left of the container and the image. Should I adjust the image size in the media query or expand the con ...

Steps for transferring data from a POST response to the client in NodeJS/ExpressJS

I am currently in the process of setting up an EasyPost API and I need to save some data that is included in a response from a POST route. My goal is to send this data directly to the client for storage, but I am struggling to determine where or how to do ...

AngularJS is adjusting the form to be dirty, not pristine

I have created an HTML form and implemented validation for each input using AngularJS. However, I want the validation errors to be hidden initially when the page loads, and only show up once the user interacts with the form. This is how my validation is ...

Unable to include the variable "$localStorage"

While working on my method in app.js, I encountered the following error: Uncaught Error: [$injector:strictdi] function($rootScope, $q, $localStorage, $location) is not using explicit annotation and cannot be invoked in strict mode http://errors.angula ...

Is it possible to customize the formatting of the information displayed within a details tag when it is nested under a summary

Is there a way to format the details information so that it aligns underneath the summary tag? Currently, both lines of text are aligned to the left. <details> <summary> Summary 1 </summary> Details 1 </details> ...

Utilize the :not() selector in combination with the :first-child() selector

Currently, I am seeking a method to merge two css selectors together in order to target specific elements. The selectors I am attempting to combine are ':not' and ':first-of-type'. Here is the code snippet that represents my current sit ...

Utilizing Node and Electron to dynamically adjust CSS style properties

Having a dilemma here: I need to access the CSS properties from styles.css within Electron. Trying to use document.getElementsByClassName() won't work because Node doesn't have document. The goal is to change the color of a specific div when the ...

What is the best way to center this image horizontally within its variable-sized parent container?

I am currently working on a webpage that has a responsive design. The page features a list of products, with the product listing adjusting in size as the page width changes. My goal is to center the product image within its container, ensuring that the i ...

An AngularJS-powered dynamic navbar

Apologies if my explanation is unclear, but I am struggling to find a simple way to convey the following information. I have set up a navigation bar that displays different categories of articles. These navigation items are pulled from a database and can ...

Adjusting the sidebarPanel height to match the mainPanel content in a shiny app

I'm currently developing an app that features a scrollable sidebarPanel alongside a mainPanel that can have varying heights, such as: library(shiny) ui <- fluidPage( headerPanel('Iris k-means clustering'), sidebarPanel(style = " ...

Implementing Content-Security-Policy with React and Material-UI v4 for secure styling requirements

Utilizing a React UI with material-ui version 4, the web server is embedded within a JVM application during Production. Following npm build for the UI, the bundle is deployed alongside the server side code. An essential requirement involves implementing C ...

Understanding fluid design concept

Check out this example. I've noticed that when resizing the viewport, the font size within the .main class increases while there is no change in the .aside class. Can someone help shed light on this for me? Thank you in advance! ...

A guide to implementing lazy loading using BXSlider

I have implemented an image gallery using Bxslider, but I am facing an issue with the loading time as there are more than 15 images in each slide. To address this problem, I want to load images one by one when a particular slide appears. I came across an e ...

I'm having trouble getting jquery css to function properly in my situation

I am trying to implement a fallback for the use of calc() in my CSS using jQuery CSS: width: calc(100% - 90px); However, when I tried running the code below, it seems like the second css() function is not executing. I suspect that there might be an issu ...