首页  >  问答  >  正文

如何在Nuxt 3中为<html>和<body>标签添加Tailwind CSS类?

<p>我正在尝试为我的Nuxt 3应用程序使用tailwind制作一个自定义的404错误页面。</p> <p>我希望该页面在所有设备上都能填满屏幕,404错误页面在垂直和水平方向上居中,但是我无法使其垂直居中。即使在包装的<div>中使用h-screen或h-full,它始终位于页面顶部。</p> <p>在Tailwind UI组件中的一个示例中,它说:“此示例需要更新您的模板”:</p> <pre class="brush:php;toolbar:false;"><html class="h-full"> <body class="h-full"></pre> <p>如何在Nuxt 3的特定page.vue中轻松添加tailwind类到html和body标签中?</p> <p>我尝试在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 天前568

全部回复(1)我来回复

  • P粉754473468

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

    试试这个。

    useHead可组合文档中,有一个bodyAttrs参数。这应该可以帮助您在标签中添加任何自定义类。如果您想在HTML中添加一个类,可以使用htmlAttrs参数。 https://nuxt.com/docs/api/composables/use-head#usehead

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

    回复
    0
  • 取消回复