You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
4 Hrs
35 Min
27 Seg
Curso de Tailwind CSS 1

Curso de Tailwind CSS 1

Víctor Yoalli Domínguez

Víctor Yoalli Domínguez

Dimensiones y Espacios

8/29
Resources

What is the spacing system in Tailwind?

The powerful Tailwind CSS framework provides a widely configurable spacing system. Through it, you can manage the dimensions and spacing of your web elements precisely. This system is highly flexible and can be modified according to your design and development needs. Tailwind starts from a default definition of units, ranging from zero to larger values, each with its own special function.

How do spacing units work?

Units in Tailwind start from zero, with no spacing, and words like SPX are used to represent a pixel. In this way, multiple units, from zero to six, can be implemented within Tailwind, handling different predefined scales. Here's the fascinating thing: four units equal one rem, which in turn equals six pixels. Thus, Tailwind jumps incrementally in its spacing: six, eight, ten, twelve, sixteen, twenty, and twenty-four.

The spacing system is not only useful, but will be your eyes and hands throughout any project using this framework.

/* Example of Tailwind CSS classes for spacing */.h-16 { height: 4rem; }.w-32 { width: 8rem; }.mx-auto { margin-left: auto; margin-right: auto; }

Where is spacing applied?

Spacing in Tailwind is applicable in different CSS properties, allowing you to manageheight,width,margin andpadding, adapting these attributes in an efficient and flexible way according to the desired design.

How to adjust height and width?

To adjust the dimensions of the elements, we use specific classes. For example, an h-8 class modifies the height of an element to eight units, or sixteen units if we use h-16. Similarly, for thewidth, we can use w-16 and w-32, finally getting square elements if the same unit is used in both directions.

In addition, Tailwind allows you to modify the width by percentages, using fractions. This method is extremely useful when you want elements to adapt to different size contexts.

/* Example of handling width with fractions */.w-1/2 { width: 50%; }.w-1/3 { width: 33.33333333%; }.w-1/4 { width: 25%; }

What are Margin and Padding and how are they used?

Margins(margin) andpadding (padding) manage the space both inside and outside an element, respectively. With Tailwind, you can modify them uniformly or in specific directions. For example:

  • m-t4 increases the top margin by four units.
  • p-l4 increases the padding on the left by four units.

It's a powerful way to optimize your designs while maintaining fine-grained control over space distribution.

/* Example CSS classes for margins and padding */.mt-8 { margin-top: 2rem; }.ml-8 { margin-left: 2rem; }.p-4 { padding: 1rem; }.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; } .px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }

How to use spacing on horizontal and vertical axis?

Tailwind provides advanced functionality to apply spacing on specific axes. Using the classes m-x-auto on the horizontal axis or p-y-2 on the vertical axis, you can adjust the spacing depending on your needs. This feature is particularly useful when you want to center elements or provide equal spacing along the x or y axis.

/* Example of spacing control on the axes */.mx-auto { margin-left: auto; margin-right: auto; }.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }

This knowledge about dimensions and spacing will be a pillar for your efficiency in designing using Tailwind. Take advantage of these tools and take a bold step towards mastering a consistently clean and structured design. Be encouraged to keep learning and experimenting with Tailwind CSS to develop amazing projects!

Contributions 25

Questions 7

Sort by:

Want to see more contributions, questions and answers from the community?

Me tomé la molestia de hacer la conversión para los que no dominan el tema muy bien como yo

      '0': '0',		= 0px
      '1': '0.25rem',	= 4px
      '2': '0.5rem',	= 0.8px
      '3': '0.75rem',	= 12px
      '4': '1rem',	= 	16px
      '5': '1.25rem',	= 20px
      '6': '1.5rem',	= 24px
      '8': '2rem',	= 	32px
      '10': '2.5rem',	= 40px
      '12': '3rem',	= 48px
      '16': '4rem',	= 64px
      '20': '5rem',	= 80px
      '24': '6rem',	= 96px
      '32': '8rem',	= 336px
      '40': '10rem',	= 640px
      '48': '12rem',	= 768px
      '56': '14rem',	= 896px
      '64': '16rem',	= 1024px

Mi problema con la estandarización de espacios se acabó

También permite el uso de márgenes negativas, aquí el ejemplo:

Fuente: https://tailwindcss.com/docs/margin

1rem = 16px

<h1>3.2 Dimensiones y espacios</h1>

Tailwind utiliza un sistema de espacios que se puede configurar. Se maneja internamente utilizando rem. Se puede visualizar desde el archivo tailwind.config.full.js.

Se puede utilizar en:

  • Height.
  • Width.
  • Margin.
  • Padding.

En las clases de los elementos se añaden cosas como:
h-32 w-1/2 pt-2 mx-auto

Para manajear el height:
https://tailwindcss.com/docs/height/#app

Para manejar width en porcentajes se puede ver esta documentación:
https://tailwindcss.com/docs/width/#app

tailwind es más interesante de lo que parce. por lo menos me va gustando más que boostrap

Está muy interesante esto! .
Nunca pares de aprender

hasta el momento se ve genial tailwind

Cada clase ha sido un 🤯 continuo.

Tailwindcss es una maravilla

Parece que la información de los estilos va en el mismo html, lo cuál no sé hasta que punto es algo bueno.

Boom me encanta!

El sistema de espaciado de Tailwind afecta a las propiedades:

  • Height
  • Width
  • Margin
  • Padding

Puedes configurar sus medidas en el archivo tailwind.config.js,

Aquí hay buena información al respecto

Nunca había utilizado Tailwind CSS y es increíble ❤️

Me recuerda a las utilidades de bootstrap, solo que aquí hay muchas más.

Conociendo ya las propiedades del sistema de espacios vamos a ir a nuestro index.html empezaremos con la altura y el ancho

  • h-8 - modifica altura
  • w-16 - modifica el ancho

Otra forma de cambiar el ancho de nuestros elementos por porcentajes, si vamos los a la documentación veremos que el porcentaje lo maneja en fracciones entonces tenemos

  • w-1/2 - 50% - toma el 50% del ancho
  • w-1/3 - 33.33333%

Tengo un problema cuando quiero aplicar en un tema un estilo de boxShadow diferente llamado soft… mi configuracion es la siguiente:

module.exports = {
  theme: {
    boxShadow: {
      xs: '0 0 0 1px rgba(0, 0, 0, 0.05)',
      sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
      default: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
      md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
      lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
      xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
      soft: '0 9px 9px 16px rgba(163, 177, 198, 1), 0 -9 -9 16 rgba(163, 177, 198, 1)',
      '2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
      inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
      outline: '0 0 0 3px rgba(66, 153, 225, 0.5)',
      none: 'none',
    },
  },
  variants: {},
  plugins: [],
}```

Al colocarle la clase shadow-soft el elemento no cambia...

Me parece increíble que se puedan poner “barras” como parte del nombre de la clase.
No recordaba que CSS sea tan permisivo en el naming de las clases.

Si que es un buen elemento que me servirá de mucho para un proyecto que estoy haciendo.

Vengo de 4 años usando Bootstrap y Tailwind es hermoso, ahora que lo conosco, seguro que lo usare mas

Hasta ahora se ve sencillo de implementar, con clases similares a Bootstrap

  • 1rem = 16px
  • Los porcentajes (%) se manejan con sistema de fracciones

Me está gustando estoooo

sf