Change the font size of the class .MuiTypography-body1 to a different size

  • I attempted to change the font size of the .MuiTypography-body1 class
  • After doing some research, I came across this helpful link https://material-ui.com/api/typography/
  • Unfortunately, I'm having trouble with the override not working as expected
  • Could someone provide guidance on how to resolve this issue?
  • Below is my code snippet and sandbox demo for reference.

https://codesandbox.io/s/material-demo-yr83v

const useStyles = makeStyles(theme => ({
  root: {
    fontSize: "2"
  },


  checkboxLabel: {
    border: "1px solid black",
    fontWeight: "100",
    fontSize: "20"
  },
  body1Text: {
    fontSize: "2"
  }
}));


 <div
      classes={{
        body1: classes.body1Text
      }}
      className={classes.root}
    >
      <FormControl
        classes={{
          body1: classes.body1Text
        }}
        component="fieldset"
        className={classes.formControl}
      >
        <FormLabel
          classes={{
            body1: classes.body1Text
          }}
          component="legend"
        >
          Gender
        </FormLabel>
        <RadioGroup
          classes={{
            body1: classes.body1Text
          }}
          aria-label="gender"
          name="gender1"
          className={classes.group}
          value={value}
          onChange={handleChange}
        >
          {console.log("props", props)}
          {props.radioValues.map(val => {
            return (
              <FormControlLabel
                classes={{
                  body1: classes.body1Text,
                  label: classes.checkboxLabel
                }}
                style={{
                  fontWeight: "300",
                  fontSize: "2",
                  border: "1px solid red"
                }}
                value={val}
                control={
                  <Radio
                    classes={{
                      body1: classes.body1Text
                    }}
                    style={{
                      fontWeight: "100",
                      fontSize: "1",
                      border: "1px solid red"
                    }}
                    
                  />
                }
                label={val}
              />
            );
          })}
        </RadioGroup>
      </FormControl>
    </div>

Answer №1

Applying the style={{fontSize:'sizeValue'}} directly is a valid approach that can yield the desired results.

Answer №2

Just a tiny bit more effort and you would have nailed it. All that was missing was specifying a unit for the font size:

  checkboxLabel: {
     border: "1px solid black",
     fontWeight: "100",
     fontSize: "20px"
  },

To clarify: Your intention was to override the Typography styles in your code snippet. For guidance, consult the FormControlLabel api: https://material-ui.com/api/form-control-label/#formcontrollabel-api

The css section explicitly states that you must use the 'label' rule name to override Typography styles. As seen in the FormControlLabel classes you implemented:

 classes={{
              body1: classes.body1Text,
              label: classes.checkboxLabel // this line here
            }}

If you'd like to see a live example of me overriding all Typography-body1 styles, check out this demo: https://codesandbox.io/s/material-demo-h685r?fontsize=14

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

Unable to bring in the specified export 'Directive' from a non-EcmaScript module - only the default export is accessible

I am currently working on an ionic angular project and utilizing the ng-lazyload-image plugin. However, I am encountering errors during compilation that look like this: Error: ./node_modules/ng-lazyload-image/fesm2015/ng-lazyload-image.mjs 401:10-19 Can ...

Ways to showcase HTML content in angular when receiving entities

Is there a way to properly display HTML characters using HTML entities? Take this scenario for example: Let's say we have the following string: $scope.myString = "&lt;analysis mode=&quot;baseball&quot; ftype=&quot;&quot; version ...

How can I use XPATH and Python Selenium to select the text node that is outside of an <a> element?

Check out the following link: Within this section of code: //*[@id="main-contents"]/div[1]/table[1]/tbody/tr/td, there is a piece of text Mottled Boar slain (10) //*[@id="main-contents"]/div[1]/table[1]/tbody/tr/td/a This part contains only: Mo ...

AngularJS: Creating a dual-column layout with alternating styles

Struggling to create a two-column layout that repeats in AngularJS using a JSON object of image data. I'm aiming for a display of images in a side-by-side format, but my odd/even logic seems to be off no matter what adjustments I make. Can anyone poin ...

What is the best way to use a jQuery variable within a .css() function

I'm working on a typewriter effect with some advanced CSS code. I need the program to calculate the length of a PHP variable and adjust the cursor animation steps accordingly. Basically, I want the cursor movement in the animation to be determined by ...

Route parameters do not function correctly with computed properties

I'm facing an issue with my getter function that stores all products. When I try to retrieve a single product dynamically based on this.$route.params.id, it doesn't return any value. The code works fine when I navigate to a specific product, but ...

Guide on using a while-loop in selenium with python to continuously run until a specific element is no longer present on the page

I'm currently facing a challenge with creating a while-loop that will run until a specific element is no longer present on a website. My existing solution gets the job done, but I know there's room for improvement. I would love to hear suggestion ...

I am looking to retrieve a specific input value from a JSON array using JavaScript

I have created an array called 'PROPERTIES' which accepts values like username, password, sid, etc. I am looking to retrieve these entered values using JavaScript. 'PROPERTIES': {'gatewayurl': {'Name': ...

Tips on incorporating form groups within a grid using semantic-ui-react

I am currently developing a project using semantic-ui-react that involves numerous input fields. To better organize the page, I have decided to split it into 3 columns. Below is the approach I have taken: render() { return ( <Form> < ...

Generate star icons dynamically within a div using C# and MSSQL data to determine the number of stars

Upon retrieving a rating (which can be more than 5) from the database, I aim to dynamically generate glyphicon stars based on the received value when the page loads. The code snippet below demonstrates how the value is retrieved: int rating_count = DBinte ...

What is the best way to eliminate excess space on the right side of a div element

I recently utilized a column structure with bootstrap 4, resulting in a layout with 1 row containing 2 columns: <div class="left"> <hr class="container hline"> <div id="main" class="container border"> <di ...

Encountered an unexpected symbol < in JSON while implementing fetch() operation

I'm currently working on linking my React signup page to my Django API in order to automatically create a user profile in Django when a user signs up. Whenever I attempt to create a new user, I encounter this error in my console: Signup.js:33 ...

Is it possible to achieve the full image when utilizing double buffering for drawing on canvas?

I have a code where I am using two canvas elements to draw an image in order to prevent flickering. However, I am facing an issue where I cannot get the full image to display when using this method. When I use just one canvas, the image displays fine. It ...

Utilizing React-Redux along with Redux-Thunk in a functional component to dynamically modify the UI upon receiving data from an external API

Within my functional component, I am utilizing a custom hook to fetch data from an API using Redux. const useFetching = (someFetchActionCreator) => { const dispatch = useDispatch(); useEffect(() => { dispatch(someFetchActionCreator() ...

Having trouble implementing min and max date validation in Angular UI-Bootstrap datepicker with UI-Bootstrap version 1.3.3

My goal is to implement validation in my datepicker, preventing the user from selecting a date within 30 days before or after the current date. Here's the code snippet I'm currently using for the datepicker: <div class="form-group" ng-class=" ...

Is it possible to utilize JStestDriver for testing JavaScript code embedded within JSP files?

Just a quick question: Is it feasible to conduct unit testing, specifically with JStestDriver, on Javascript code that is embedded within JSP files? Or do I need to extract it into separate external javascript files? ...

Test your knowledge of Javascript with this innerHtml quiz and see

How can I display the output of a score from a three button radio button quiz without using an alert popup? I want the output to be displayed within a modal for a cleaner look. I tried using InnerHTML but now there is no output when the button is clicked. ...

material-icons appear differently when letter-spacing is applied in iOS browsers

To display levels using star icons from angular material, I wanted the stars to be shown next to each other. I attempted to achieve this by applying letter-spacing: -0.25rem;, but unfortunately it did not render correctly on iOS platforms (resulting in s ...

Ways to transfer HTML page data into a Python variable using a URL

I stumbled upon a helpful guide at: https://docs.python.org/2/library/htmlparser.html However, the HTMLParser.feed(data) function requires data to be actual HTML content. Is there a way to achieve a similar feed but using only a web address? Maybe someth ...

Is it possible to create a clip plane in Three.js for objects that intersect?

Currently, my setup involves using a PlaneGeometry as the representation of water. I have also added a ship (gltf model) onto the water. The issue I'm encountering is that when the boat slightly overlaps with the water surface, the water is visible in ...