Position the mat-icon button in the top right corner for the close button

I'm struggling with positioning my close icon button at the top right corner of my dialog box.

Here is my app-iconbutton component:

<button
  mat-icon-button
  class="iconbutton"
  [ngStyle]="{
    'background-color': backcolor
  }"
  (click)="onClick()"
>
  <mat-icon [ngStyle]="{ 'color': iconcolor }">{{ icontype }}</mat-icon>
</button>

And here is my dialog box component structure:

<div>
  <app-iconbutton
    backcolor="white"
    iconcolor="darkblue"
    icontype="close"
    class="closeicon"
  ></app-iconbutton>
</div>
<div class="dialogbox">
  <h1 mat-dialog-title class="title">{{ title }}</h1>
  <div mat-dialog-content>
    <p class="content">{{ content }}</p>
  </div>
  <div mat-dialog-actions>
    <button mat-button (click)="onNoClick()">Cancel</button>
    <button mat-button (click)="onYesClick()" cdkFocusInitial>
      {{ confirmtext }}
    </button>
  </div>
</div>

I've attempted to align the close icon using CSS, but it's not aligning as desired. When I use float: right, it aligns itself with the title instead of being in the top right corner. And when I use position: absolute, the icon button appears outside the dialog box rather than staying relative to the screen. Can anyone provide guidance on how to resolve this CSS issue? This is my first experience with Angular and I am still learning...

Answer №1

After some adjustments, I managed to make my app-iconbutton fit nicely inside the dialog box div. I also tweaked the positioning of my dialog box by setting it to relative and adjusting the closeicon css as follows:

.closeicon {
  float: right;
  position: absolute;
  top: -25px;
  right: -20px;
}

It's not exactly what I had in mind, but at least it gets the job done...

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

Troubleshooting the fluid container problem in Bootstrap 3

I am currently working on a website using Bootstrap 3 framework. I have a specific section where I need to have two fluid containers placed side by side, each with different background colors. One of these containers should also include a background image ...

Having trouble with installing angular-cli

angular-cli unexpectedly quits while trying installing: (myapp)vagrant@myapp-local:/vagrant$ sudo npm install -g angular-cli npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caadb8aba9afacbfa6e7acb98afbe4f8e4 ...

How come my footer is appearing at the top of my webpage?

I have encountered a problem where the footer is displaying on top of my page, despite not using any floats, wrappers, or grids in my code. The code snippet can be found below this text. Could someone assist me in identifying why this issue is occurring ...

What is the best way to ensure that an input group expands to fill the entire horizontal space

I am currently utilizing bootstrap 4 and have a responsive navbar for smaller screens. On this navbar, I am trying to implement a search input group that spans the full width from left to right up until the menu bar icon on the right side. You can view my ...

Showing or hiding child content based on the selected state of a radio button

This is a follow-up question from a previous one on changing check boxes to radio buttons. Now, I need to display child radio buttons and change the background color when the parent radio button is active. The child radio buttons should be hidden and the b ...

SystemJS is loading classes that are extending others

In my Angular2 application, I have two classes where one extends the other. The first class is defined in the file course.ts (loaded as js) export class Course { id:string; } The second class is in schoolCourse.ts (also loaded as js) import {Cours ...

Can a unique custom command be designed for the Kendo UI Grid in Angular2?

The built-in commands supported by the KendoUI Grid for Angular2 include: kendoGridAddCommand kendoGridCancelCommand kendoGridEditCommand kendoGridRemoveCommand kendoGridSaveCommand However, I am working on a project that requires a custom command to be ...

I am working on an Angular application that includes a dynamic form for an attendance system for employees. I am currently trying to figure out how to generate the JSON data

I have a dynamic form in my reactive attendance system for employees. When I click on submit, I need to generate JSON data like the following: { "user_id": "1", "branch_id": "4", "auth_token": "59a2a9337afb07255257199b03ed6076", "date": "2019- ...

Border at the Top and Text Alignment Problem

I am working on a basic navigation bar that includes a hover effect. .navip { float: left; text-decoration: none; font-weight: lighter; } .navip > a { display: block; color: black; text-decoration: none; font-size: 20px; ...

Arrange the buttons within the container

I'm struggling with the front-end development side of things (HTML, CSS, etc.) and need help aligning buttons within a container. The container will include a heading and multiple buttons. Any assistance would be greatly appreciated! Thank you in adv ...

Encountering issues in Angular 2 when attempting to pass data into root component through ng-content and binding. Objective: Creating a reusable form component

I currently have a .NET MVC application and I'm looking to integrate Angular 2 into it. The structure of my page is as follows: <html> <head>css imports and jquery imports</head> <body> <div> a bunch of table ...

CSS: The enigma of :nth-child - what eludes my understanding?

I have 2 divs which are similar to 2 td's in a table. My goal is to have 2 red divs, followed by 2 blue divs and so on. However, my current code doesn't seem to be working. Can someone point out what I am missing: <style> .irow :nth-child( ...

Align the content evenly on several cards using Material-UI

Trying to work on some frontend coding, but struggling with getting the content justified properly in fixed-height MUI cards. Each card consists of a title, description, divider, and author, but I can't seem to get everything aligned correctly within ...

Having trouble launching the freshly developed Angular app

I'm encountering an issue with my newly created app - I can't seem to launch it. Error: The loader “C:/C#/Angular/my-app/src/app/app.component.css” is not providing a string as expected. https://i.sstatic.net/6Xjwd.png https://i.sstatic.ne ...

"Users have reported that the file upload preview feature in Angular 6 only works after the

I am currently utilizing Angular 6. In my application, I have a simple input type="file" field that passes data to an image source which displays the image I intend to upload. The issue I am facing is that when I select an image for the first time, nothi ...

Increasing the height of nested Bootstrap columns by stretching them out

I am trying to ensure that the first two columns in both the green and violet rows always have the same height. I initially thought of using d-flex align-items-stretch, but it seems like it is not working because those elements are not within the same row ...

Developing an Angular application and deploying it onto the server

I've been working on an angular6 application and I need to create a build to test it on my server. Currently, when I use ng server, the application runs without any errors in my browser. c:\Users\emiry\Desktop\Angular\Proje ...

Set a default selection for radio buttons in Angular template-driven forms

I'm having an issue with setting a default selection for a radio button in my template-driven form. Here's the relevant part of my code: <div class="donut-form-promos"> <span>Promo:</span> <div class=&quo ...

What is the process for adjusting the color of the underline in Material UI input fields

I am facing an issue with a Material UI Select component that is on a dark background. I want to change the text and line colors to white just for this particular component, while keeping the rest of the Select instances unchanged. Although I have managed ...

How can you automate the process of skipping a protractor test?

Is there a way to skip protractor test cases based on certain conditions being true or false? I tried using pending('skipped'); expect(true).toBe(true); But it is marked as failed. Update I found a way to add test cases to "Pen ...