The mat-card's content is too large for the mat-card container

I am currently working on a project using Angular 7, Material, and Flex-layout. I am facing a challenge in making the mat-card with a mat-card-image responsive.

The mat-card-image is a square picture with a maximum width and height of 160px.

This is the layout I am trying to achieve:

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

  • In the left scenario, the parent container is large enough to display the mat-card with the maximum-size mat-card-image (160*160px). The size of the mat-card is determined by the equation: (width) * (height)(160px) * (mat-card-header + 160px + mat-card-content). Everything works perfectly in this case.

  • In the right scenario (responsive design), the parent container is not big enough: the mat-card-image needs to be resized. For example, the new size of the mat-card-image becomes 100*100px, so the mat-card size changes to (width) * (height)(100px) * (mat-card-header + 100px + mat-card-content). This is where I encounter an issue as the mat-card-image doesn't resize:

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

The mat-card is outlined in red but the content doesn't fit properly within the mat-card (the image should be resized).

I have tried various solutions, but below is my current code:

HTML:

       <div fxLayout="column" fxLayoutAlign="center center" fxFlexFill>


            <mat-card>
                <mat-card-header fxLayoutAlign="center">
                    <mat-card-title style="margin-bottom: 0px;" >
                        foo
                    </mat-card-title>
                </mat-card-header>

                <img mat-card-image [src]="foo" style="margin-bottom: 0px;" layout-fill>

                <mat-card-content fxLayoutAlign="center" style="margin-top: 0px;">
                    foo
                </mat-card-content>

            </mat-card>

            <span></span>

        </div>

CSS:

mat-card {
    max-width: 160px;
    max-height: 100%;
    padding-top: 0px;
    padding-bottom: 0px;
    box-sizing: border-box;
}

Any suggestions on how to achieve this responsive design?

Answer №1

Have you considered utilizing background-size: cover; to adjust the image size based on the container dimensions?

We would appreciate it if you could provide more of your CSS code. It is a bit challenging to make edits without sufficient information at this point...

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

Issues with CSS background colors

I am in the process of streamlining my CSS code by consolidating repetitive elements and removing unnecessary lines (I am currently enrolled in a mobile apps course that emphasizes creating web-based hybrid applications using HTML5, CSS, and JavaScript, he ...

The best approach to incorporating interactive animation in next.js

My vision is to develop a character creation application using next js. The app should empower users to customize the character using sliders and gender selection buttons. The ultimate goal is to have a 2D animated version of the character that dynamicall ...

Adjusting video size in carousel (Bootstrap 4.0)

My school project requires me to create a website with a video slider, and I decided to use Bootstrap 4.0 for this task. I have successfully implemented a template from Bootstrap, but I am facing an issue with the video not fitting properly within the slid ...

After uploading the WordPress theme, the wp_enqueue_style() function fails to work properly

I recently developed a new WordPress theme and encountered an issue while trying to load specific stylesheets for my child sites using the is_page(array('')) function in my function.php file. Surprisingly, only the files that were added to all of ...

Update the CSS variables in Angular Material version 15 to reflect new changes

Angular Material 15 introduces some significant changes to colors and spacing. As a result, I find myself needing to override the default CSS variable values in my styles.scss file. :root { --mdc-typography-button-letter-spacing: 'normal'; ...

Restricting choices once user selects an option (HTML)

Currently, I am faced with a dilemma regarding two sets of options for an HTML form. One set consists of various units (such as cm, in, ft.), while the other set includes different locations. The selection of a unit would restrict certain location option ...

Fluid layout causing elements in body to be hidden by fixed header

I'm currently tackling a fluid layout challenge, utilizing percentages instead of pixels to achieve it. I've managed to create a fixed heading (#heading) at the top of the page, but now I'm struggling with ensuring that all other elements on ...

Navigate to a new tab using this.router.navigate

Is there a way to redirect the user to a specific page with ${id} opening in a new tab, after clicking a button in an angular material dialog box? I want to leave the dialog box open while querying the new page. Currently, the redirect happens but not in a ...

Enhancing the Appearance of NextJS React Data Tables

Task: I need to display a large DataTable in the UI with both horizontal and vertical scrolling capabilities Issue: Unable to enable scrolling on the X axis UI cuts off the first half of the table unless zoomed out UI becomes unusable Tried: Reviewed ...

Encountering the issue of receiving an undefined value when attempting to define a {string} parameter within the "when" section of the step

As a novice in the world of protractor with cucumber, I am faced with the challenge of automating a process where inputting a first name, last name, and postcode creates a new user. In order to achieve this, I have attempted to define the data entry within ...

Insert straight lines between elements in an inline list

I am working on building a step progress bar using the HTML code below: .fa-check-circle { color: #5EB4FF; } .fa-circle { color: #CFD7E6; font-size: 14px; } .container { width: 100%; position: absolute; z-index: 1; margin-top: 20px; } . ...

React forms are experiencing issues with characters overlapping

Having trouble with overlapping label and input letters in my React form. Looking for: The appearance shown in the top image Experiencing: What is displayed in the bottom image Any solutions on how to resolve this issue? https://i.sstatic.net/Y3W2m.png ...

Is there a way to align the image next to the form and ensure they are both the same size?

I've been struggling to resize the image to match the form size, but I can't seem to get it right. Can anyone provide me with some guidance on this issue? I have obtained this contact form from a website that I plan to modify slightly, but I need ...

Three.js - spinning texture applied to spherical shape

Would it be possible to rotate a loaded texture on a sphere geometry in Three.js without rotating the object itself? I am seeking a way to rotate just the texture applied to the material. Imagine starting with a sphere like this: https://i.sstatic.net/Ol3y ...

Designing an HTML banner with 100% width and 660 pixels in height for optimal responsiveness

I am in need of a responsive banner that will be displayed at 100% width and 600px height on fullscreen. Below is the code I have: <style> /* default height */ #ad { height: 660px; width: 100%; } @media o ...

What is the best way to maintain a font size of 150% even after refreshing the page or reopening it?

After successfully implementing two buttons that allow users to adjust the font size on my webpage, I noticed that upon refreshing or reopening the page, the font size resets to its default setting. How can I ensure that the font size remains at 150% even ...

Efficiently Organizing Data Using Coldfusion Loops in Columns and Rows

My issue lies in pulling data from a database to display on my website. I have three keys/attributes (columns) - PostedDate, DataImage, and Source that need to be shown together in one div with the posted date at the top, image in the middle, and source at ...

The SCRIPT1002 error message popped up, signaling a syntax issue between IE11 and Angular

Encountering an error when trying to open my Angular project in IE11. The error message is as follows: SCRIPT1002: Syntax error vendor.js (224520,1) The line causing the error (224520) looks like this: class PreventableEvent { constructor() { ...

What is the best way to manage the connections in my D3 tree chart?

I've been working on customizing a tool from an open source library called angular-d3-tree, but I'm struggling with getting the links to connect properly in my D3 tree structure. This is what my current tree layout looks like: https://i.stack.im ...

Access the system by authenticating with the Firestore database collection

My goal is to develop a function that retrieves information from my collection in order to log into my application. With the help of this service, I am able to fetch all the necessary data: getUsersLocal(): Observable<AdminUser[]> { const bo ...