如何找出为什么我的CSS无法显示?

时间:2019-04-03 14:27:55

标签: php html css wordpress

我正在建立一个网站,以前从未使用HTML的任何用户都可以进行更改,因此我选择了Wordpress。我想出了为二十二个主题制作子主题的方法,并尝试对其进行了自定义,但是由于某些原因,CSS无法显示。

我尝试多次更改style.css和functions.php文件,例如添加教程中包含的CSS。没用然后,我添加了自己的CSS,但同样没有用。我也将其留空,并使用wp上的“自定义其他CSS”工具添加了其他CSS,或者转到主题编辑器并在其中添加CSS。我还多次更改了functions.php中的内容,并删除了文件,但是它不起作用。我抬起头,为什么会发生这种情况,并尝试了一些方法,但没有帮助。

这是style.css文件:

/*  
Theme Name: Twenty Twelve Child
Description: Twenty Twelve Child Theme
Template: twentytwelve
*/
@import url("../twentytwelve/style.css");

[ my custom css ]

和functions.php:

<?php
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
?>

我尝试了这些以及其他许多方法,但是它们都没有起作用。任何帮助或技巧都将不胜感激。

更新:我还有一些其他文件,例如footer.php或header.php,当我从文件夹中删除它们时,CSS就会显示出来。这些文件可能有问题吗?

1 个答案:

答案 0 :(得分:0)

尝试将其用于functions.php

 <?php
function twentytwelve_child_theme_child_theme_enqueue_styles() {
$parent_style = 'twentytwelve_child_theme_parent_style';
$parent_base_dir = 'twentytwelve';

wp_enqueue_style( $parent_style,
    get_template_directory_uri() . '/style.css',
    array(),
    wp_get_theme( $parent_base_dir ) ? wp_get_theme( $parent_base_dir )->get('Version') : ''
);

wp_enqueue_style( $parent_style . '_child_style',
    get_stylesheet_directory_uri() . '/style.css',
    array( $parent_style ),
    wp_get_theme()->get('Version')
);
}

add_action( 'wp_enqueue_scripts', 'twentytwelve_child_theme_child_theme_enqueue_styles' );

对于style.css,仅使用此(不使用@import):

/*
Theme Name: Twenty Twelve Child
Description: Twenty Twelve Child Theme
Template: twentytwelve
Version: 1.0.0
*/

尚未测试,但应该可以工作:)