Tips for aligning text in a stylish way on an Angular Material Button

My angular material button has been customized with increased size and the text is currently offset. Here is the code:

<a mat-raised-button class="buttons-class" color="accent">Hello!</a>

To increase the size, the following CSS was added:

.buttons-class {
  height: 60px !important;
  width: 210px !important;
  align-items: center;
}

However, I am now facing an issue with centering the text within the button. The text is not centered as desired:

https://i.sstatic.net/mDXbg.png

Attempts to center the text using standard techniques like putting it in a span or div have not been successful so far.

Answer №1

One helpful technique is using ng-deep along with the ::ng-deep shadow-piercing descendant combinator. This allows you to apply styles that will cascade down through the child component tree, affecting all child component views and classes.

::ng-deep.buttons-class {
  height: 60px !important;
  width: 210px !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

Answer №2

Please include the specified styles below.

.custom-btn {
  height: 70px !important;
  width: 200px !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

Using the angular routerLink with query parameters derived from an enumerated key

I have a component that looks like this: export enum QueryParamsEnum { node = 'nodeId' } export class Component { key = QueryParamsEnum.node; } Now, I want to use the key as part of the queryParams in my template like this: <a [rou ...

Bootstrap image with simplistic arrow indicators

I'm facing a minor issue that I need help solving. I want to have two simple arrows (one pointing left and one right) vertically aligned in the center of an image. Additionally, these arrows should resize proportionally when the screen size changes. ...

**Utilizing Bootstrap (v5) in Angular (v15) the Traditional Way**

I've successfully integrated Bootstrap with Angular by following the steps outlined in the ng-bootstrap.github.io documentation: ng new my-ng-bootstrap-app # Create angular app. Choose routing and SCSS options ng add @ng-bootstrap/ng-bootstrap # add b ...

Is there an issue with loading CSS and JavaScript in mobile view on a website built with CodeIgniter?

My experience with codeigniter has been great so far, but I encountered an issue when trying to view my work on different devices. Here is the problem: Web: Broswer View | Browser (Responsive Design View) Mobile: Screenshot 1 | Screenshot 2 _htaccess: ...

Optimize the layout with Grid CSS to allow the last two items to dynamically occupy

I've been working on a layout that looks like this: X X X X X X X X A B Currently, I have used grid-template-columns: repeat(4, 1fr); to define the columns. However, what I actually want is for the last two items to take up the full width of the rem ...

Is there a way to modify the size and color of a specific word in a CSS animation?

As a newcomer to CSS, I am exploring ways to change the font size and color of a specific word in my sentence after an animation. My initial attempt was to enclose the word within a span class like this: <h2>I'm <span style = "font-size: ...

What is the best way to extend a class in NestJS from another class?

I've encountered an issue while attempting to extend a class service from another class service in NestJS and utilize DI to load it in a third service. The error message I'm receiving from Nest is: Error: Nest can't resolve dependencies of ...

Guide to setting up a search function with class name filtering

I am currently managing a website with multiple items, each represented by individual div elements. While all items share one common class name, they also have several other class names serving as tags to differentiate them (some tags may overlap between d ...

Having trouble getting CSS3 Keyframes to function properly?

Check out the following code snippet: .startanimation { height: 100px; width: 100px; background: yellow; -webkit-animation: animate 1s infinite; } @-webkit-keyframes animate { 100% { width: 300px; height: 300px; } ...

How can I create a circular Datepicker in JavaFX?

Struggling with customizing my JavaFX application using CSS. Everything was going smoothly until I encountered the Datepicker. Despite trying various approaches, none seem to be working. Is there a way to round the Datepicker just like my TextFields? Here ...

Adjust the horizontal position of a span element from left to right based on its class

Welcome to my first question here, with many more to come in the future. I have an issue with positioning that I'm not sure is possible to solve. The problem arises with an unordered list (<ul>) containing floated <li> elements. For the m ...

Challenge encountered in handling AJAX response data for presentation

Currently, I am immersed in a project and decided to implement AJAX for smoother form submissions. My initial attempt was trying to display text from a .txt file below the "submit" button, but unfortunately, that approach didn't yield the desired resu ...

Issues arising from utilizing Twitter Bootstrap 3.1.x, the box-sizing property, and Revolution Slider

I'm currently working on a PyroCMS theme that is built with Twitter Bootstrap 3.1.x and includes Revolution Slider. However, I've encountered an issue where the property box-sizing: border-box; creates an unwanted grey border as shown in the imag ...

Printing the default value set in the constructor using HTML

I'm encountering an issue while trying to set a default value from the constructor parameters and display it in HTML. The error message I'm receiving is: No suitable injection token for parameter 'name' of class 'AppComponent' ...

Tips for displaying all 'ul li' lists in media queries to ensure responsiveness in design

When I view my navigation bar snippet on desktop mode, it displays all the list items. However, when I adjust the browser width to fit my media queries, only the Home list is shown in the nav bar. Here's an example of the issue: Before Clicking the ...

Is there a way to showcase Images or Stars in a Material Angular Form?

I have a form where the rating is displayed using star images, but it is stored as a number in string format on the backend. While experimenting, I am trying to figure out the best way to achieve this. Currently, this is what I have: https://i.sstatic.net ...

Exploring JSON data in Angular 2

Struggling to comprehend how to navigate through different parts of a JSON object in Angular2. I have a custom web API that provides details about the hard drive on my server, as shown in the JSON object below: https://i.sstatic.net/x1d6M.jpg The image d ...

Patience is key: Techniques for waiting on service responses in Angular 2

Here is the code snippet I have been working on: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { let isAuthenticated: boolean = false this.authServiceLocal.isAuthenticated().then(response => isAuthenticated = r ...

Can you explain the distinction among the various FormControl initialization techniques?

Can you discern the variance among the following methods: input: new FormControl({}, inputValidatorFn()) input: [{}, inputValidatorFn()] input: formBuilder.control({}, inputValidatorFn()) They appear to function identically. Is there truly no disparit ...

In Vue, applying CSS styles to D3's SVG elements may not work as expected when using the scoped attribute

Here is the code snippet of my component: <template> <div id="something" class="card"> </div> </template> const height = 200; const width = 200; let graph = d3 .select('#something') .append('svg') ...