Ways to eliminate the excess margin of ng-container from the webpage

When controlling two mat tabs with a statement, I encountered an interesting issue. Both mat-tab elements contain a card-list and are controlled with a statement in ng-container. Strangely, on the first tab, the card has a slight margin from the top when I hover over it, showing 'ng-star-inserted'. The opposite logic applies to the second mat-tab card element, as it has a margin from the bottom. If I remove '' line, the unnecessary margin disappears, but the logic stops working. How can I eliminate this unnecessary margin without compromising the logic that determines if appointments have passed or not?

Margin on top (Active appointments tab)

https://i.sstatic.net/DHszE.jpg

<ng-container *ngIf="!appointment.passed">

Margin on bottom (Past appointments tab)

https://i.sstatic.net/17CK9.jpg

<ng-container *ngIf="appointment.passed">

Appointments array below (each object has a passed value indicating if it has passed or not)

0: {id: 36, appointmentDate: "2019-12-27T10:28:15", doctorName: "Conner Reyes", departmentName: "Urology", hospitalName: "Genopkins Hospital", …}
1: {id: 57, appointmentDate: "2020-01-03T08:29:25", doctorName: "Ayesha Brewer", departmentName: "Eye Center", hospitalName: "Genopkins Hospital", …}
2: {id: 40, appointmentDate: "2020-01-11T17:23:39", doctorName: "Shelbie Jenkins", departmentName: "Gynecologic Oncology", hospitalName: "Genopkins Hospital", …}
3: {id: 58, appointmentDate: "2020-01-15T15:45:19", doctorName: "Kirsty Armstrong", departmentName: "Eye Center", hospitalName: "Genopkins Hospital", …}
4: {id: 93, appointmentDate: "2020-01-16T17:26:27", doctorName: "Claire Burton", departmentName: "Eye Center", hospitalName: "Mediclinic Hospital", …}

Answer №1

Hey there, please take note of the gap you are experiencing, it may be due to padding rather than margin.

Additionally, when using

<ng-container></ng-container>
in Angular, it creates a comment rather than an element.

<ng-container *ngIf="true">
  <div>
    Hello
  </div>
</ng-container>

Upon rendering in the DOM, it will appear as:

<!--bindings={
  "ng-reflect-ng-if": "true"
}--><!---->
<div _ngcontent-jim-c0=""> Hello </div>

If mat-card is an external component, consider using ::ng-deep in your CSS component code.

For example:

::ng-deep {
    .mat-card.ng-star-inserted { padding: 0; }
}

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

Steps for modifying an element in an array using Javascript

Currently, I am a beginner in the realm of JavaScript and I am trying to build a todo-style application. So far, I have successfully managed to create, display, and delete items from an array. However, I am facing challenges when it comes to editing these ...

CSS an act of misbehavior

I have noticed some unusual behavior on my website page. My website design can be viewed at Also, here is the same design in CMS format Please pay attention to the section under <div class="godelpage"> <a href="http://ryugaku.babonmultimedia ...

Utilizing Node.js with Graphics Magick to generate high-quality cropped thumbnails without sacrificing image resolution

Is there a solution to maintain image quality when cropping and centering an image using Graphics Magick? The code I currently have reduces the fidelity of the resulting image. gm(imagePath) .thumbnail(25, 25 + '^') .gravity('Cent ...

Encountering a sanity issue while attempting to execute vercel build: sanity/..page.jsx lacks a root layout. To resolve this issue, ensure that each page includes a root layout

While my project runs smoothly locally, I encounter issues when trying to deploy it on Vercel. The error message reads: ⨯ sanity/[[...index]]/page.jsx doesn't have a root layout. To resolve this issue, ensure that every page has a root layout. Comp ...

What is the procedure for importing material UI components into the main class?

Hey there! I'm currently working on integrating a "SimpleAppBar" element into my React app design. Below is the code snippet for this element sourced directly from the Material UI official website: import React from 'react'; import PropType ...

Modifying linked dropdown selections with jQuery

I'm trying to create a recurrent functionality where I have 3 select elements. When the first select is changed, it should update the second and third selects accordingly. If the second select is changed, then it should also affect the third select. ...

Encountering an unexpected token 'Indent' while working with Jade in Eclipse

Currently, I am delving into the world of node, angular, javascript, express, and jade. Transitioning from a purely .net based coding environment has presented me with quite the learning curve. While following a tutorial, I encountered a roadblock at step ...

AngularJS - Multi-controller Data Calculation

I am currently in the process of developing an Angularjs application. The project is quite extensive and requires segmentation into multiple Controllers to manage effectively. One challenge I am facing is performing calculations across these controllers. ...

Getting Started with NextJs and Firestore Setup

Recently, I have been incorporating Firebase into my NextJs project. I've set up a file called initFirebase.tsx for the server-side implementation. import * as Sentry from '@sentry/nextjs'; import * as admin from 'firebase-admin'; ...

Copy values of multiple input fields to clipboard on click

I have a collection of buttons in my Library, each with different text that I want to copy when clicked function copyTextToClipboard(id) { var textElement = document.getElementById(id); textElement.select(); navigator.clipboard.writeText(textElement. ...

What is the best way to keep track of the most recent 100 items?

In Angular, I want to store the last 100 items to display. Currently, I am using an array and inserting items with 'array.push'. If this method is not effective for this scenario, what alternative approach can I take? Here is a snippet of the co ...

When Safari injects elements that were previously hidden with display:none, they remain visible

Using the JS library MagnificPopup, I implement popups on my website triggered by a "read more" button. This library moves the html to display it in a different location and then injects it back when the popup is closed. While this functionality works seam ...

Sending Angular 4 POST request to Java Spring Controller via HTTP

Hey there, I'm looking to pass a string from my Angular 4 post request to my Java Spring MVC controller and get its value returned. In the Angular 4 function: let body = 'example' http .post('favourite', body) .subscribe( ...

React DOM's offsetHeight prior to rendering

I am struggling to figure out how to position a React DOM element based on its offsetHeight. The issue is that I cannot determine the offsetHeight of an element that hasn't been created yet (so the height cannot be passed as a parameter to the render ...

The scope chain in Chrome v71 connects the anchor tag to the inner img tag

Ever since updating to Chrome v71, I've noticed a strange issue with the scope of an anchor tag that contains an img tag inside. Take a look at this snippet: <a href="#none" onclick="debugger;complete();"> <img src="https://clickmeuk.net/w ...

Hover over the image to trigger animation effects

Looking for a way to enhance my current jQuery script that creates an orange transparent hover effect over images. How can I add animations, specifically a fade in and out effect? $(document).ready(function() { $('#gallery a').bind('mo ...

Populating a form within an Angular.js application using PhantomJS

Looking to test an AngularJS application using PhantomJS? The first step is to fill in the login form with the username field, assuming there are no other fields involved. Typically, in a real browser, this field is managed by Angular (with the ng-model ...

What is the formula to determine the precise hue-rotate needed for producing a particular shade?

I'm looking to change the color of a white background image in a div to match the main theme color. I know I can use filters like sepia(), saturate(10000%), and hue-rotate() to achieve this, but is there a way to calculate these values beforehand? Sin ...

Retrieve the value of an input text within a table data cell using JavaScript

I have set up a table using CGridView, which includes input text fields for user input. The problem I'm facing is that I can retrieve the text from table cells without input fields, but not from those containing input fields. PHP: <?php $this-> ...