Is the Material-UI 1.3 font size failing to adapt to varying screen widths?

Looking to create an app with responsive font sizes using material-ui (v1.3)? Also, want the font size to shrink when the screen size is smaller and adjust automatically. However, the current code doesn't update the font size dynamically as the screen size changes. Need help to figure out why it's not working?

class App extends Component {
constructor(props) {
    super(props);
    this.state = {
        open: false,
    };
}


getDrawerFontSize() {
    if (window.innerWidth <= 575) {
        return '10px';
    } else if (window.innerWidth <= 767) {
        return '11px';
    } else if (window.innerWidth <= 991) {
        return '12px';
    } else if (window.innerWidth <= 1199) {
        return '13px';
    }
    return '14px';
}

render() {
    const drawerFontSize = this.getDrawerFontSize();
    const { open } = this.state;

    const theme = createMuiTheme({
        overrides: {...}
    });

    const styles = {...};

return (

    <MuiThemeProvider theme={theme}>
    ...
    ...
    ... // The rest of the code goes here

} }

export default withRouter(connect( mapStateToProps, mapDispatchToProps)(App));

Answer №1

Creating responsive fonts can be achieved in various ways:
1) Utilizing JavaScript :
- One option is to utilize a JavaScript library (e.g. )
2) Using CSS :
- Instead of using pixels, consider using vw or vh units:
- 1vw equals 1% of viewport width
- 1vh equals 1% of viewport height
- 1vmin equals the smaller of 1vw or 1vh
- 1vmax equals the larger of 1vw or 1vh

OR
You can also employ Media Queries in CSS
https://www.w3schools.com/css/css_rwd_mediaqueries.asp

Thank you! I hope this information proves helpful.

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

What is the best way to overlay text onto a background image using Material UI's Card and CardMedia components?

Using the card component, I have successfully added a background image. However, I am facing difficulty in figuring out how to overlay text on top of this image. If anyone has suggestions or alternative methods, please feel free to share! <Card> ...

The JSON data is riddled with numerous key/value pairs that are absent

When using Axios to load a static JSON file from the React application server, I noticed that many key/value pairs are missing after reading the files. The specific JSON file in question is asset-manifest.json, which contains all the assets (media, css, j ...

the label remains grounded even as the browser autocompletes passwords with the password manager

https://i.stack.imgur.com/vJMyg.png I noticed that the password label on my login form does not float when the browser's password manager auto-completes. Can someone help me fix this issue? Attached is an image for reference. /* login form ...

The embedded Google iframe is causing unnecessary padding at the bottom of the page

Below is a snippet of HTML code: <div class="google-maps"> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d109782.8671228349!2d76.62734023564995!3d30.69830520749905!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x390fee90 ...

What is the best way to delete stored angularjs files permanently?

My web application, built on AngularJS, has certain functionalities that I have hidden from users. While the controls have been successfully hidden in the updated version of the file, there are still some users with the old file who can access these undesi ...

Unveiling the intricacies of CSS specificity

Struggling with the specificity of this particular CSS rule. Despite researching extensively, I still can't seem to grasp it. Can someone help me determine the specificity of the following: #sidebar h1, p em, p a:hover{ ... } ...

What is the best way to keep my layout component fixed in the Next13 app directory?

I am struggling to develop a custom layout component that can retrieve its own data. Despite adding 'cache: 'force-cache'' to the fetch function, the updated content from my CMS is still being loaded every time I refresh the page. Below ...

What is the best way to arrange the elements vertically within a flex container?

In my current code snippet, I have the following setup: <section class="body1"> <h1 class="text1">Tours around the world</h1> <h3 class="text1">Great experiences</h3> <form action="/respuestaUsuario/"> ...

Error message "Potential Undefined Object" detected on a variable that is not an object in React with TypeScript

After finding and addressing the other 5-6 questions, I managed to partially fix it by using the "!" operator. Please do not remove this question for duplication purposes. However, what baffles me is that the variable is not recognized as an object. Here i ...

Next.js has shifted away from pre-generating page HTML

I have been working on a Jamstack application using Next.js, and I recently realized that the pages stopped pre-generating the HTML content without me noticing it at first. The pages still load fine, but there is no pre-generated HTML. Even the simplest c ...

Steps for Customizing the Font Style of a Certain List Item Tag <li>

I'm struggling to find the right CSS selector to specifically change the font of just one list item. Here's the current structure: <ul id="menu-applemain class="x-nav> <li>One</li> <li>Two</li> <li>Three</l ...

Struggling with running my React App as I'm encountering some errors

Check out the code on Github: https://github.com/bhatvikrant/IndecisionApp I have already run npm i and then executed yarn run dev-server, utilizing webpack. My operating system is MacOs. I have also created the .babelrc file. The issue I encountered aft ...

Unable to display a value using Creatable react-select

, I've integrated react-select with material-ui to create an autocomplete element that emulates the material design style and functionality. After following the initial setup from the Material UI demo page at here, I had to customize it to align with ...

Styling triangles within a CSS triangle

I'm attempting to design a webpage with a fixed triangle navigation element. The issue I am encountering is that I am unable to position smaller triangles inside the larger one, as shown in the image below. https://i.stack.imgur.com/1bTj8.png As th ...

Tips for adjusting the font size within the MUI TextField Label

I'm looking to adjust the label fontSize in the material ui TextField component. I've discovered the InputLabelProps property which has been helpful, but as shown in the image below, the label appears too cramped when focused. Below is my implem ...

Achieving Equal Spacing Between Containers without Using Grid or Flexbox

I'm struggling to evenly space four child containers within a single parent container without using Flex/Grid, as I haven't covered those topics yet. I tried setting each child container to 25% width of the parent and centering them with text-ali ...

The class names in Material-UI seem to constantly shuffle whenever I refresh the page

Right now I am experimenting with Text Fields in Material-UI and my goal is to make them smaller in size. For reference, here is an example of the class name: .eKdARe.header .input-container input After making changes in my file and refreshing the page, ...

What are some methods for customizing the calendar icon displayed in an input field with type date?

Is there a way to customize the calendar logo without relying on jquery? The desired appearance should resemble the image shown below: https://i.sstatic.net/G06iZ.png input { width: 50%; padding: 8px; border-radius: 10px; ...

What is the best way to customize the appearance of a form element within an angular-schema-form schema without affecting the overall

Currently, I am in the process of constructing a form using the incredible angular-schema-form. Creating the form schema object has been a success so far. My goal is to configure all the form components within the schema using the x-schema-form property in ...

Having trouble with the sx selector not functioning properly with the Material UI DateTimePicker component

I'm currently working with a DateTimePicker component and I want to customize the color of all the days in the calendar to match the theme color: <DateTimePicker sx={{ "input": { color: "primary.main&quo ...