Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
Adaptive Font Size function using material UI elements

as a exercise for school, I want to scale-down the font Size of an H4 element inside a Grid and Typography Tag, here is the code:

const CompanyDetails: React.FC<Props> = (props) => {
  const { orgId, organisation, individuals, refetchOrg } = props;

  return (
    <>
      <Grid container rowSpacing={2.3}>
        <Grid item xs={12}>
          <Card sx={{ p: 2 }}>
            <CardContent>
              <Grid
                container
                item
                xs
                justifyContent="space-between"
                alignItems="center"
              >
                <Grid container item md={6}>
                  <Typography
                    variant="h4"
                    align="center"
                    textAlign="start"
                    paddingRight={6}
                  >
                    {organisation?.name}
                  </Typography>
                </Grid>

The question is, if the text takes more than 3 lines, I wanted the font size to scale down to stay in the maximum of 2 lines, I'll attach some screenshots here as well. Something I tried but it didn't work, was this:

const adaptiveFontSize = (text: string) => {
  if (text.length < 65) {
    return "1em";
  } else {
    return "0.9em";
  }
};

This is what it looks like with 2 lines This is the default This is what it looks like with 3 lines enter image description here This is what I am trying to achieve if it's big enough enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda