The combination of MUI CardContent and flexBox seems to have issues when used in conjunction with typography and chips

Take a look at this React code using MUI. It's designed to create a Card that showcases Character Information.

const CharacterPreview = ({ characterKey }: CharacterPreviewProps) => {
  return (
    <Card sx={{ maxWidth: 256, borderRadius: 4 }}>
      <Box
        component="a"
        href={`/#/${characterKey}`}
        display="flex"
        position="relative"
        sx={{
          "&::before": {
            content: '""',
            display: "block",
            position: "absolute",
            left: 0,
            top: 0,
            width: "100%",
            height: "100%",
            opacity: 0.7,
            backgroundImage: `url(${bannerImgUrl})`,
            backgroundPosition: "center",
            backgroundSize: "cover",
          },
        }}
        width="100%"
      >
        <Box
          flexShrink={1}
          sx={{ maxWidth: { xs: "40%", lg: "40%" } }}
          alignSelf="flex-end"
          display="flex"
          flexDirection="column"
          zIndex={1}
        >
          <Box
            component="img"
            src={iconImgUrl}
            width="100%"
            height="auto"
            maxWidth={256}
            sx={{ mt: "auto" }}
          />
        </Box>
      </Box>
      <CardContent>
        <Typography variant="h5" component="div">
          {characterName}
        </Typography>
        
        <Chip
          label={characterChipInfo}
          size="small"
        />
      </CardContent>
    </Card>
  );
};

This is the visual output:

https://i.stack.imgur.com/MmRco.jpg

I'm trying to place the chip component (displaying as CRYO in the image and represented by characterChipInfo in the code above) on the same line as the characterName, with some space between them like a space-between flexbox layout. However, my attempts to use the Box component with flex-box and

justifyContent="space-between"
around the name Typography and Chip elements have not been successful. I've also experimented with changing the Typography's display property to inline-flex and inline-block, which puts them on the same line but still doesn't work with the Box's justifyContent=space-between.

Answer №1

To implement a stylish user interface, consider utilizing the Stack component from Material UI in the following manner: Check out the code on CodeSandBox

    <Stack
      direction="row"
      spacing={2}
      justifyContent="space-between"
      alignItems="center"
    >
        <Typography variant="h5" component="div">
          {characterName}
        </Typography>
        {/* <Typography variant="body2" color="text.secondary"> */}
        {/*   {characterInfo.title as string} */}
        {/* </Typography> */}
        <Chip
          label={characterChipInfo}
          size="small"
        />
    </Stack>

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 Regular Expression for separating a collection of email addresses into individual parts

I am very close to getting this to work, but not quite there yet. In my JavaScript code, I have a string with a list of email addresses, each formatted differently: var emailList = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data- ...

I am unable to make any changes to the CSS in the WordPress code that is already integrated

I have created a static web page to serve as my primary homepage. The page is built using HTML and CSS, with some PHP code pulled from My WordPress integrated into it. One of the functionalities I've added is to display the three most recent posts on ...

CSS: A guide to correctly setting an image URL for a checked checkbox

In my current situation, I have a list of checkboxes with corresponding images. When a checkbox is checked, I would like to add a black circle behind the image. Here is an example of the current output: This is what I expect the output to look like: Her ...

Steps to redirect a page from a React.js frontend to a Node.js backend with a proxy

I have developed a basic react application with two pages ("/", "/show-stocks") using Routes for navigation. Additionally, I have created a node/express js backend with an endpoint named "/show-stocks/btc". To link the frontend to the backend, I configured ...

Is there a way to maintain image proportions when resizing the window?

I'm in the process of developing a classroom-themed website with interactive overlaying images. The goal is to have various pictures that users can click on to access different resources from different websites. My main challenge right now is getting ...

Efficiently incorporating multiple properties into one in Angular

Within my Angular service, I have defined variables in the following manner: export class MyService { someVariableA = 1; someParams = { someVariableB, otherVariable: this.someVariableA }; } In a component, I update 'someVariableA&a ...

Error with Bootstrap Layout caused by the StringBuilder

After diving into Bootstrap, I encountered an issue with the layout generated by a VB.NET page using StringBuilder. The result was a disorganized mess: Upon further inspection, it became evident that the problem extended to other sections of the page as w ...

Creating a large and spacious modal in Angular using ngx-bootstrap

I need help with resizing the ngx-modal to cover a large area of the screen. Currently, I am trying to make it so that when something is clicked, the modal should overlay an 80% width grid on a full desktop screen. Despite my attempts at using .modal-xl an ...

Tips for maintaining consistent formatting of a div element across various sizes

Looking to create a Bootstrap Jumbotron that features a background image, text (h1 and p), and a call-to-action button that scales appropriately for different viewports without sacrificing formatting. Essentially, the goal is for the div to behave like an ...

The Material UI Drawer stays closed despite the state being set to true

Currently, I am in the process of developing a WebApp utilizing React and Material UI. Despite following numerous tutorials on implementing the Drawer component and poring over the documentation, I am still struggling to grasp its functionality. Even thou ...

A collapsible select list with checkboxes for children items

I am currently developing a website using Vue.js, HTML, and SCSS. I am looking to implement a drop-down functionality similar to the animated example provided in the gif below: https://i.stack.imgur.com/Mia2D.gif The gif demonstrates how the drop-down me ...

Is createMuiTheme designed to include default values for any missing properties?

I'm in the process of developing a new theme utilizing createMuiTheme(): import { createMuiTheme, responsiveFontSizes } from '@material-ui/core/styles'; const theme = responsiveFontSizes( createMuiTheme({ palette: { type: &apos ...

Is there a way to tally up the overall count of digits in a number using TypeScript?

Creating a number variable named temp in TypeScript: temp: number = 0.123; Is there a way to determine the total count of digits in a number (in this case, it's 3)? ...

Error: The function is not defined in React-Redux when attempting to use React Final Form

I am currently in the process of developing a store that manages login information. However, when I dispatch with the action, I encounter an error message in the console. Error TypeError: Object(...) is not a function at onSubmit (Login.js:66) at O ...

Breaking apart faces of a sphere using Three.js

I am currently working on creating a sphere geometry. geometry = new THREE.SphereGeometry( 200, 20, 10 ); material = new THREE.MeshLambertMaterial({ shading: THREE.FlatShading, color: 0xff0000 }); sphere = new THREE.Mesh(geometry, material); scene.add( sp ...

Having difficulty retrieving data from JSON file using Backbone framework

When I click on the div, I am attempting to retrieve JSON data but am unable to view the output. I am utilizing Backbone Collection to fetch JSON data. I have tried displaying the JSON data in the console as well as within another div. The contents of the ...

What is the best way to serve a .ttf file in node.js with the http and fs libraries?

I am running a basic node server and I have a CSS file that is trying to load a font from the server: @font-face{ font-family: 'NiagaraSolid-Reg'; src: url('http://localhost:1111/NIAGSOL.TTF'); } This is my attempt at servin ...

MUI: broadening the scope of color challenges

These are the colors I am using: import { PaletteOptions } from "@mui/material/styles"; export const palette: PaletteOptions = { primary: { 50: "#FFF5FA", 100: "#FFEBF5", 200: "#FED7EB", ...

Fetch data in JSON format from a specified URL

I have been attempting to fetch a JSON from a specific URL. Here is my current code snippet: <script> var co2; $(document).ready(function(){ alert("0"); $.getJSON(url,function(result){ var jsonObject = result; alert(result); ...

How can I customize the color of the text and calendar icon in Material UI DatePicker?

Is there a way to customize the color of the date text and calendar icon in MUI X DatePicker (using Material UI)? I've tried passing styles to InputProps, but it only removed the border. Other than that, nothing seems to change. I also attempted apply ...