Hide/Trim the upper right corner of the button

I am looking to customize the top right corner of a button in order to add a badge in that area. Here is an example of what I have in mind:

https://i.sstatic.net/j0xdz.png https://i.sstatic.net/uFzDw.png

The image on the right showcases my current setup.

I attempted to achieve this by following a solution from this answer: How to cut a circular part from an image?

However, it appears that the mask only works for images and not buttons.

Below is a snippet of code from my application:


          <b-button pill
                    class="notification"
                    :class="{ actived: isActive}"
                    @click="showNotif">
            <b-icon-bell></b-icon-bell>
            <span class="badge">3</span>
          </b-button>
 // Within my SCSS file
 .notification {
      width: 40px;
      height: 40px;
      background-color: $white;
      margin-right: 3%;
      border-color: transparent;
      & .b-icon {
        margin: 0 0 0 -4px;
        width: 24px;
        height: 24px;
        font-family: FuturaStd;
        font-size: 20px;
        font-weight: bold;
        font-stretch: normal;
        font-style: normal;
        line-height: normal;
        letter-spacing: normal;
        text-align: center;
        color: $bluey-grey;
      }

      .badge {
        position: absolute;
        top: 5px;
        padding: 3px 6px;
        border-radius: 50%;
        background: $golden-yellow;
        color: white;
      }
    }

Answer №1

To create a bit of space around the yellow circle, one option is to enclose it in a separate div element. You can wrap the badge in a new container div with 2px, 3px, or 4px of padding.

<div class="badge-wrapper">
  <span class="badge">3</span>
</div>
.badge-wrapper {
  background-color: grey; // matching the background
  padding: 3px;
  border-radius: 50px;
}

After that, transfer the positioning CSS rules from the badge to the wrapper.

Answer №2

Thank you for your response, but I actually discovered a solution similar to yours. I simply added the following code just before my badge span:

<span class="badge-hide"></span>

Then, I applied this CSS:

      .badge-hide {
        position: absolute;
        top: 10px;
        margin-left: 2px;
        padding: 9px 9px;
        border-radius: 50%;
        background: #f2f5f8;
        color: white;
      }

      .badge {
        position: absolute;
        top: 8px;
        margin-left: 3px;
        border-radius: 50%;
        background: #eec710;
        color: white;
      }

As a result, it looked like this: https://i.sstatic.net/yZLvj.png

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

The submission button in Bootstrap 3 becomes disabled upon clicking, preventing the data from being successfully transferred to the database

Currently, I am in the process of developing a signup page using bootstrap. To validate my form, I have integrated the plugin. Despite all validations being successful, an issue arises when I attempt to submit the form - the submit button is disabled and ...

Adjust divs for mobile display using Bootstrap and CSS

I have been struggling with rearranging two divs that are stacked vertically on mobile. I want the second div to appear above the first when the screen size is reduced. Despite trying various methods such as flexbox order and direction, I have not been suc ...

Most efficient method for dynamically changing HTML content with JavaScript

Can anyone provide guidance on how to switch HTML content using JavaScript? For example: if($sid == 0) {insert one HTML code} else {insert another HTML code} Which method is preferable - LESS, jQuery, CSS3, etc? ...

Discover the concealed_elem annotations through the power of JavaScript

As I work on my new website, I am struggling with narrowing down the web code. I came across a solution that seems fitting for what I need, but unfortunately, I can't seem to make it work: I attempted the non-jQuery solution, however, I must be missi ...

Setting the default TAB in a specific Menu Tab within the Menu Bar

I'm encountering some issues with this code. Specifically, the menu bar JavaScript is automatically clicking on the Second TAB instead of the First TAB when run. JS CODE. var dolphintabs = { subcontainers: [], last_accessed_tab: null, ...

Creating an animated scrolling image effect: A step-by-step guide

My current project involves implementing a scrolling textbox. I have put together the following snippet to achieve this: <html> <head> <style type="text/css"> #scroll { position: absolute; white-space: nowrap; ...

The combination of Asp.net and Bootstrap offers a powerful

I am facing an issue with using Bootstrap in my ASP.NET project. The page displays correctly on a desktop, but when I resize the page to mobile phone size, the navigation panel does not stay in dropdown position. Here is my code: <%@ Page Language="C ...

Element remains stationary and covers full viewport on mobile devices when the page overflows

I am looking to create a fixed element that covers the entire viewport on mobile devices (specifically Chrome and WebView). The CSS code I have is very straightforward: .full { position: fixed; left: 0; top: 0; width: 100vw; height: 10 ...

Issues with the Stylesheet Unresponsiveness in Bootstrap

I'm having an issue with applying my external CSS file to the HTML code. I've tried changing the order of loading the bootstrap style first, but it doesn't seem to work. HTML FILE: <!DOCTYPE html> <html> <head> <meta ...

Best way to trigger a DOM event when creating an HTML template using VueJS

I am looking to execute a FUNCTION when a template element is displayed on the screen, however I am unsure about the appropriate DOM event to utilize: <template v-on:something="function(parameter)"> </template> ...

Differences between Umbraco CSS and image file paths

As I embark on creating a new website using Umbraco(version 6.1.1 with razor), I find myself in unfamiliar territory as a newcomer to the world of Umbraco. My settings panel currently appears like this: Within my Master template, I have implemented my CSS ...

Personalizing the app's listview items by customizing the ui-icon arrow

Is there a way to customize the arrow image used for list items in a jQuery Mobile listview? How can I replace the default grey circle arrow with my own image? Do I need to override jQuery CSS classes for this task? My current setup uses jQuery Mobile 1.1. ...

The Vue application using Axios is sending data to an Express backend, but it is receiving

Introducing the main.js file of my Vue application, currently operating on localhost:8080 and attempting to send data to localhost:8081 (express.js) // The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in ...

Large size causing alignment issues with Bootstrap Tooltip位置混乱

I've encountered an issue with the bootstrap tooltip while using fullcalendar.js. The problem isn't with the fullcalendar library itself, as I included it just to provide context. You can view the problem on this JSfiddle link. The tooltip keeps ...

Creating manageable CSS styles for a wide variety of themes

I need to add themes to a web application that allows users to switch between them seamlessly. The designers want a variety of font colors and background colors, around 20 in total. Is there a way to achieve this without creating multiple .css files, which ...

How can a global function be declared in Vue.js so that it can be accessed from any part of the application

One of the challenges I encountered while using Vue.js was finding a way to declare a global function that could be accessed anywhere in the application without needing to import it each time. I attempted using a custom Vue plugin, but found that its func ...

Vue.js V-for not rendering any content

I am currently working on populating an array with objects retrieved from an API. The objects are being fetched successfully, but I am facing issues when trying to display them using v-for in the array. Below are my data variables: data() { return { ...

Tips for maintaining the aspect ratio of an image while ensuring it always occupies 100% width and automatically adjusts its height

I've searched everywhere but can't seem to find the right CSS solution for my problem. How can I ensure that an image always fills 100% of the height and width of the screen while maintaining its aspect ratio? .myimage { object-fit: cover; widt ...

Is there a way to successfully submit multiple locations, each separated by commas, through the multipart form?

Here is my HTML form: <form method="POST" enctype="multipart/form-data" v-on:submit.prevent="handelSubmit($event);"> <div class="clear"> <div class="col-md-3"></div> <div class="col-md-6"> <div class="form ...

Exploring the growth of CSS offsetting alongside with AngularJS

I am working on an Angular app where I need to increase the left offset of a div by 90px every time the slideThis() function is called. In jQuery, I would typically achieve this using left: '+=90', but I'm struggling to find a similar method ...