如何更改wordpress中只有一页的css? [英] How do I change the css of only one page in wordpress?

查看:20
本文介绍了如何更改wordpress中只有一页的css?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要更改主页的 css,我用谷歌搜索过,很多建议是将页面 ID 添加为 css 选择器的一部分.但是当我尝试它时,它似乎不起作用?我想更改类.contentclass"并且页面 ID 为599",所以这是我尝试过的:

I need to change the css of the home page only, I have googled and a lot of the suggestions were to add the page id as part of the css selector. But when I try it, it doesn't seem to work? I want to change the class ".contentclass" and the pages id is "599" so here's what I've tried:

.post-id-599 .contentclass {}
.page-id-599 .contentclass {}
.body-id-599 .contentclass {}

他们似乎都没有工作......

none of them seems to be working...

链接到我正在处理的网页:链接

Link to the webpage I'm working on: Link

推荐答案

如果您的主题使用 body_class() 在 body 标签中,您将有一个用于首页的特定 css 类 (.home),您可以在样式表中使用它;

If your theme uses body_class() in the body tag, you will have a specific css class for the front page (.home), which you could use in the stylesheet;

示例(可能因您的主题而异):

Example (might be different for your theme):

.home #content .entry { color: #123edf;}

要覆盖通用样式表 style.css,您可以在 header.php 中使用条件语句来链接首页的特定样式表:

to overwerite the genral stylesheet style.css, you could use a conditional statement in header.php to link a specific stylesheet for the front page:

示例:

<?php if( is_home() ) { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_stylesheet_directory_uri(); ?>/front-style.css" />
<?php } ?>

代码需要在通用样式表的链接之后.

the code needs to be after the link to the general stylesheet.

(您可能需要使用 is_front_page() 而不是 is_home() )

(instead of is_home() you might need to use is_front_page() )

检查:Conditional_Tagsget_stylesheet_directory_uri

--或者,要加载不同的样式表而不是通用样式表,请使用带有 else 的条件语句:(此代码将替换通用样式表的链接)

-- alternative, to load a different stylesheet instead of the general stylesheet, use the conditional statement with an else: (this code would replace the link of the general stylesheet)

示例:

<?php if( is_home() ) { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_stylesheet_directory_uri(); ?>/front-style.css" />
<?php } else { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<?php } ?>

这篇关于如何更改wordpress中只有一页的css?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆