Home  >  Q&A  >  body text

How to add Tailwind CSS class for <html> and <body> tags in Nuxt 3?

<p>I'm trying to make a custom 404 error page using tailwind for my Nuxt 3 application. </p> <p>I want the page to fill the screen on all devices and the 404 error page to be centered vertically and horizontally, but I can't get it to be centered vertically. Even when using h-screen or h-full in a wrapped <div>, it is always at the top of the page. </p> <p>In one example in the Tailwind UI component, it says: "This example requires updating your template": </p> <pre class="brush:php;toolbar:false;"><html class="h-full"> <body class="h-full"></pre> <p>How to easily add tailwind class to html and body tags in specific page.vue in Nuxt 3? </p> <p>I tried adding the following to page.vue: </p> <pre class="brush:php;toolbar:false;"><script setup> useHead({ htmlAttrs: { style: 'html: h-full' }, bodyAttrs: { style: 'body: h-full' } }) </script> <style> html, body { margin: 0; padding: 0; } </style></pre></p>
P粉476883986P粉476883986385 days ago567

reply all(1)I'll reply

  • P粉754473468

    P粉7544734682023-09-05 10:44:01

    Try this.

    In the useHead composable document, there is a bodyAttrs parameter. This should help you add any custom classes in the tag. If you want to add a class to HTML, you can use the htmlAttrs parameter. https://nuxt.com/docs/api/composables/use-head#usehead

    useHead({
      bodyAttrs: {
        class: 'your-body-class',
      },
    });

    reply
    0
  • Cancelreply