You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用TailwindCSS的自定义WordPress主题样式不生效问题

自定义WordPress主题中TailwindCSS样式不生效问题

我尝试使用TailwindCSS制作自定义WordPress主题,但样式未生效。不过WordPress已识别到主题信息,说明style.css文件本身能被系统读取。

手动将CSS代码添加到WordPress时样式正常(页面样式完整渲染),而通过主题引入时样式丢失(页面仅显示无样式的原始HTML结构)。我已尝试调整文件路径,但问题仍未解决。

以下是我使用的文件:

functions.php

<?php

function enqueue_tailwind_styles() {
    // Enqueue the style.css file from the theme root
    wp_enqueue_style('tailwind', get_template_directory_uri() . '/style.css', array(), '1.0.0', 'all');
}
add_action('wp_enqueue_scripts', 'enqueue_tailwind_styles');

// Add other theme functions below...
remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );

styles.css

@import '../../theme-info.css';

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

theme-info.css

/*
Theme Name: Car_Dealer_Groovy
Theme URI: https:/placeholder.com
Author: Santiago Mejia Wilches
Author URI: https://placeholder.com
Description: Custom theme made for a car company, name pending as of writing.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: your-text-domain
*/

style.css(主题根目录文件)

/*
Theme Name: Car_Dealer_Groovy
Theme URI: https:/placeholder.com
Author: Santiago Mejia Wilches
Author URI: https://placeholder.com
Description: Custom theme made for a car company, name pending as of writing.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: your-text-domain
*/

/*
! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com
*/

/*
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
*/

*,
::before,
::after {
  box-sizing: border-box; /* 1 */
  border-width: 0; /* 2 */
  border-style: solid; /* 2 */
  border-color: #e5e7eb; /* 2 */
}

/* 省略剩余CSS代码 */

内容的提问来源于stack exchange,提问作者sappho7124

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 19:12:31