1 year ago

#386842

test-img

irfan

Tailwind css predefined fontsize depending on screen

I need to change fonsize accourding to screensize with tailwind css. Is there a way to define fontsizes according to screen in tailwind.config and apply them to all text? Normally i can create custom fontsize and apply in text element.

Define custom fontsize in tailwind.config:

module.exports = {
 content: ["./src/**/*.{js,jsx,ts,tsx}"],
 theme: {
    fontSize: {
      xs: "10px",
      s: "15px",
      sm: "17px",
      "2sm": "20px",
      m: "22px",
      md: "25px",
      l: "30px",
      xl: "35px",
      "2xl": "40px",
      "3xl": "45px",
      "4xl": "50px",
      "5xl": "55px",
      "6xl": "60px",
      "7xl": "65px",
      "8xl": "70px",
    },
 }
}

using it in text element:

<div className="text-s md:text-m  xl:text-xl">Text</div>

in order to avoid applying resposive text size for every text element i need it change fontsize value automatically. Maybe it will look like so in tailwind.config:

module.exports = {
  content: ["./src/**/*.{js,jsx,ts,tsx}"],
  theme: {
    fontSize: {
      screen: {
        lg: {
          xs: "10px",
          s: "15px",
          sm: "17px",
          "2sm": "20px",
          m: "50px",
          md: "25px",
        },
        md: {
          xs: "5px",
          s: "7px",
          sm: "10px",
          "2sm": "15px",
          m: "17px",
          md: "20px",
        },
      },
    },
  }
};

or do i have to apply responsize fontsize for every text?

tailwind-css

tailwind-ui

0 Answers

Your Answer

Accepted video resources