Using Angular Material to create a sleek scrollbar within a tab containing card content

I require assistance in styling angular material tabs.

Please refer to this link for the issue: https://stackblitz.com/edit/angular-6-material-tab-problem?file=app/tab.component.html [Edit: The stackblitz example is working correctly after implementing the changes mentioned]

The layout of the first tab is almost perfect:

  1. There is an overflow-y scrollbar available when the content within mat-card-content exceeds the visible space inside the tab.
  2. No scrollbars on the mat-card or mat-tab elements - they should resize appropriately.
  3. Upon window resize, the height of the mat-tab-group might increase - the mat-card-content should also grow taller and become scrollable if necessary.

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

However, there is an issue when the length of the contents in the mat-card-content does not exceed the height of the tab.

For instance, with the same styling, the second tab is not displaying correctly. The red rectangle of the mat-card should fill the entire height of the mat-tab. Additionally, there is an unnecessary scrollbar on the far right.

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

Below is the template:

<mat-tab-group>
  <mat-tab label="Properties">
    <mat-card class="scrollable-content">
      <mat-card-header>
          <mat-card-title>Card Data</mat-card-title>
      </mat-card-header>
      <mat-card-content>
          My Content for this card...<br>
          ... Lots and lots of content
      </mat-card-content>
    </mat-card>
  </mat-tab>
  <mat-tab label="2nd Tab">
    <mat-card  class="scrollable-content">
      <mat-card-header>
          <mat-card-title>Other Stuff</mat-card-title>
      </mat-card-header>
      <mat-card-content>
        2nd Tab
      </mat-card-content>
    </mat-card>
  </mat-tab>
</mat-tab-group>

The CSS code is as follows:

.mat-card.scrollable-content{
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mat-card.scrollable-content mat-card-content {
    overflow-y: auto;
}
.mat-card.scrollable-content mat-card-title {
    display: block;
}

.mat-tab-group {
  height: 400px;
  border: 2px solid #00F;
}

.mat-card-content {
  border: 2px solid #0F0
}
.mat-card-title {
  font-weight: bold;
  font-size: 1.25em !important;
}
.mat-card {
  border: 2px solid #F00;
  height: 85%;
}

.mat-tab-label{
  font-weight: bold;
  font-size: 1.25em;
}

Answer №1

After some investigation, I discovered the issue stemmed from the transformation of material design elements in the template into different css classes.

To resolve this, I included the following lines in the css code:

.mat-tab-body-content {
  overflow: hidden !important;
}

.mat-tab-body-wrapper {
  height: 100% !important;
}

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

JavaScript query-string encoding

Can someone clarify why encodeURI and encodeURIComponent encode spaces as hex values, while other encodings use the plus sign? I must be overlooking something. Appreciate any insights! ...

Submitting a form using jquery in HTML

Below is the code I have created. It consists of a text-input field and a 'Search' button within a form. Upon clicking the search button (submitting the form), it should trigger the .submit function to carry out the necessary processing. HTML CO ...

Trouble encountered in adjusting the alignment of labels

I'm struggling with aligning my links properly. https://i.sstatic.net/W5G4Z.png I want Yesterday This week This month to line up perfectly with the DateTime From and Last 2 days Last 7 days Last 30 days labels for DateTime To. This is how it appear ...

Icon click does not pass the button's value attribute

In my website, I have implemented an HTML button using Bootstrap to serve as an icon that can toggle the state of an item. Here is the code for the button: <button class='btn' value='${noteid}' onclick='toggleAck(event)'> ...

Issue with horizontal scrolling in ng-scrollbars occurs when scrolling from right to left

We are currently developing a single page application that supports two languages, one being right to left and the other left to right. For scrolling functionality, we have implemented ng-scrollbars, an Angularjs wrapper for the malihu-custom-scrollbar-pl ...

What do I do when I encounter the error message "Provider not found for RadioControlRegistry" in Angular 2? Which provider should

Which provider should be included in the provider component? <div class="radio"> <input let match id="male" type="radio" name="gender" value="true" [(ngModel)]="isMatching" (click)="isMatching(match.value)" > Take a look at my console output ...

How can I make Nav-tabs align vertically on small screens?

I'm struggling to figure out why my .nav .nav-tabs are not stacking vertically even when I am using flex-sm-column. It's frustrating me a lot. Any ideas on what might be causing this issue? <html> <head> <link rel="stylesheet" h ...

How to dynamically add table rows and cells with JavaScript using a single selection input

I am working on a project that involves a selection input with around 5 options. Additionally, there is an empty table that follows this format: <table> <tr> <td>X (for deletion)</td> <td>Option name</td> ...

What is the best way to layer div elements using Bootstrap 4?

I'm looking to achieve a similar effect with overlapping elements as shown in the attached file. What would be the best code approach to achieve this? I am currently using bootstrap 4.6.2, can it be of assistance? Thank you for your guidance. Althou ...

Why do identical elements show different scrollHeights when overflowed and how can this discrepancy be resolved?

I am using a plugin that generates a <p> element and continuously fills it with the content from a <textarea>. This plugin positions the <p> directly below the <textarea>, and styles them so that they appear identical in terms of th ...

How to use Python Selenium to locate the parent element

Here is a snippet of my HTML code: <li> <div class="level1"> <div id="li_hw2" class="toggle open" </div> <ul style="" mw="220"> <li> <div class ="l ...

What could be causing my website's screen resolution to not fit properly on mobile devices?

Initially, the resolution perfectly matched the width of mobile devices. However, after changing the background image, for some reason, the width no longer fits the device length precisely. I've tried resetting to a point where the resolution was fine ...

What is the best way to assign a secondary name to a form field in Django python forms?

My website features a form that is dynamically generated using a python loop to call each field by its variable name. The following is the snippet of HTML code used: {% csrf_token %} {% for form_field in task_form %} <div class ="wrap-input2 vali ...

Ways to adjust the brightness of any color when hovered over

Is it possible to create a universal effect where an element becomes darker or lighter when hovered over, regardless of the initial color? Here is an example: .change-color{ Background:green; width:100px; height:100px } .change-color:hover{ Background ...

Encountering an issue with Bootstrap and Sass when trying to convert SCSS files to CSS due to an error involving an undefined variable @each $color, $value in $theme-colors

I have a goal to reduce the size of the bootstrap file bootstrap.min.css. After some research, I discovered that utilizing SASS and then SCSS is an effective method to achieve this by importing only the specific components needed. Despite my previous exper ...

Two separate pieces of text converge within a single span

I am facing a challenge with alignment in a bootstrap <span> element. Specifically, I want to align the word "amount" to the left, and the "$" to the right, within the same label. I attempted to nest a <span> inside another <span> and app ...

What is the best way to implement this header style with code?

I came across this design from a potential client recently, even though we didn't end up working together. I thought it would be a good exercise to try coding the design for practice purposes. Just to clarify, this is not my original design and I have ...

Is there a way to effortlessly scroll an element when the CSS overflow property is designated as auto?

I need help with creating a testimonial section where two divs automatically scroll inside a fixed-height container. Currently, only one div is scrolling while the other remains static in my code. I have implemented JavaScript for automatic scrolling wit ...

Where is the best place to import Bootstrap in my SCSS file when customizing it with Sass?

When attempting to customize bootstrap using Sass, I discovered that overriding default bootstrap variables can be quite confusing. I am curious if someone could provide an explanation for the inconsistent behavior. Some variables only seem to be overridd ...

How can I programmatically retrieve a webpage using C language? (using https)

Looking for a solution similar to the one mentioned here: What's the easiest way to grab a web page in C? However, my current situation requires connecting via https, which adds a bit of complexity. Does anyone have any code snippets to help with thi ...