0.4.2 • Published 1 year ago

@tailwindcss/aspect-ratio v0.4.2

Weekly downloads
27,166
License
MIT
Repository
github
Last release
1 year ago

@tailwindcss/aspect-ratio

A plugin that provides a composable API for giving elements a fixed aspect ratio.

Installation

Install the plugin from npm:

# Using npm
npm install @tailwindcss/aspect-ratio

# Using Yarn
yarn add @tailwindcss/aspect-ratio

Then add the plugin to your tailwind.config.js file:

// tailwind.config.js
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/aspect-ratio'),
    // ...
  ],
}

Usage

Combine the aspect-w-{n} and aspect-h-{n} classes to specify the aspect ratio for an element:

<div class="aspect-w-16 aspect-h-9">
  <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

Use aspect-none to remove any aspect ratio behavior:

<div class="aspect-w-16 aspect-h-9 lg:aspect-none">
  <!-- ... -->
</div>

When removing aspect ratio behavior, if nested elements have w-{n} or h-{n} classes, ensure they are re-declared with a matching breakpoint prefix:

<div class="aspect-w-16 aspect-h-9 lg:aspect-none">
  <img src="..." alt="..." class="w-full h-full object-center object-cover lg:w-full lg:h-full" />
</div>

Note that due to the way this currently needs to be implemented (the old padding-bottom trick) you need to assign the aspect ratio to a parent element, and make the actual element you are trying to size the only child of that parent.

Once the aspect-ratio property is supported in modern browsers, we'll add official support to Tailwind CSS itself and deprecate this plugin.

Aspect ratio classes up to 16 are generated by default:

WidthHeight
aspect-w-1aspect-h-1
aspect-w-2aspect-h-2
aspect-w-3aspect-h-3
aspect-w-4aspect-h-4
aspect-w-5aspect-h-5
aspect-w-6aspect-h-6
aspect-w-7aspect-h-7
aspect-w-8aspect-h-8
aspect-w-9aspect-h-9
aspect-w-10aspect-h-10
aspect-w-11aspect-h-11
aspect-w-12aspect-h-12
aspect-w-13aspect-h-13
aspect-w-14aspect-h-14
aspect-w-15aspect-h-15
aspect-w-16aspect-h-16

Configuration

You can configure which values and variants are generated by this plugin under the aspectRatio key in your tailwind.config.js file:

// tailwind.config.js
module.exports = {
  theme: {
    aspectRatio: {
      1: '1',
      2: '2',
      3: '3',
      4: '4',
    }
  },
  variants: {
    aspectRatio: ['responsive', 'hover']
  }
}
@pagemaker.io/pagemakerauctic-uipmi-iqos-dce2@mayking0811/ui-componentson-rewind-uiholo-design-system-vuepegadaian-components@monto/tailwindcssindebted-stylesmfx-component-libraryhahnbee-testhahnbee-test-client@vernaillen/nuxt3-base@jarisinc/design-system@sdaragon/desy-html-starterav-theme@farnabaz/docuscategory-filtersblueblocksui-navigationblueblocksui-product-listsblueblocksui-tailheaderblueblocksui-category-filtertailwind-config-forcirvue3-resume-builderatomicform-components@everything-registry/sub-chunk-892fastnuxtkeystroke-react-ui@toantranmei/mei-nuxt3-uitailwindcss3-jit-cdntc-webtailwind-to-styledsymaxtailwindcss-jit-cdntailadmin-ui-kittailwindcss-browser-plugintailwindcss-calendartailwind-presettailwind-semantic-setuptaas-imo-uitaas-uiwindmill-react-ui-kitwindmill-react-ui-kit-2wali-lib-ax-flow-components-tailwindxbesh-uitechtessyvue-graphsvendere-storybook-test@dominic-erp/nuxt-ui@domedb/panel@donswayo/windmill-react-ui-kit@docus/docs-theme-edge@docus/blog-theme-edge@cocpit/components@creation-ui/react@crypto-dex-sdk/ui@cssninja/nuxt-ui@cssninja/stylo@bond-london/gatsby-theme@benbender/tailwind-preset@pergel/module-box@pergel/module-ui@roketid/windmill-react-ui@troychaplin79/ui-testing@troychaplin79/idc-tailwind@twistail/corejibreskaliara-merge-testkaze-uikudu-ui-systemxbeshuimtxcms-front@ouest-labs/uiui-framework-v2vitra-auth-npm-packmockline-edgesoulswap-uistreampay-checkout-payments-sdkstellar-uitw-css-extractortransak-partner-sdktwinklecss@ailayerlabs/six079-tailwind-preset@asagiri-design/tw-mui@angsanley/nuxt-ui@aklesky/tailwind-config@baleada/prepare@bbki.ng/stylebase@afif_hh/ui_components@aetheria/plugin-tailwind-classes-builder@binhtranhuu/nuxt-ui@boaterbase/bb-react-components@buildy-design-system/tailwind-preset@carletonuniversity/rds@chaibuilder/sdk@chaibuilder/forge@4alldigital/foundation-ui--gamma@brandboostinggmbh/painless-melter-plugins@deskree/ui
0.4.1

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.3.0

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago