admin管理员组文章数量:1426091
I am relatively new to Wordpress, but I'm sure there's a way to do what I'd like to do.
I have a container in my template, and on the home page I'd like to specify slightly different padding to this element.
My current CSS is as follows:
#main_content .container {
position: relative;
padding: 120px 0;
}
I'd like to bring the padding down to 80px if I'm on the Home page, otherwise keep it that way.
Is this something I'd have to do within the template or are there fancy 'WordPress only' CSS tricks that I am currently unaware of?
In my limited experience, I think I should be able to specify whether or not the page is_home
or similar, and select a custom stylesheet in the header.php
file for the home page. Presumably, with !important
after my padding change for the CSS.
Can I get some direction? The results I'm finding through searching aren't particularly what I'm trying to do.
I am relatively new to Wordpress, but I'm sure there's a way to do what I'd like to do.
I have a container in my template, and on the home page I'd like to specify slightly different padding to this element.
My current CSS is as follows:
#main_content .container {
position: relative;
padding: 120px 0;
}
I'd like to bring the padding down to 80px if I'm on the Home page, otherwise keep it that way.
Is this something I'd have to do within the template or are there fancy 'WordPress only' CSS tricks that I am currently unaware of?
In my limited experience, I think I should be able to specify whether or not the page is_home
or similar, and select a custom stylesheet in the header.php
file for the home page. Presumably, with !important
after my padding change for the CSS.
Can I get some direction? The results I'm finding through searching aren't particularly what I'm trying to do.
Share Improve this question edited Dec 4, 2013 at 6:33 Mayeenul Islam 12.9k21 gold badges85 silver badges169 bronze badges asked Dec 4, 2013 at 5:46 MrS1ckMrS1ck 1031 gold badge2 silver badges5 bronze badges2 Answers
Reset to default 16WordPress body_class($class)
is a nice dynamic way to load styles, js for specific body contents. If your theme doesn't support body class add them very simply:
- Open the
header.php
(or the template that contains the<body>
tag) - Edit the
<body>
tag and make it to<body <?php body_class(); ?>>
— you are Done! :)
Now when you are in:
Home
page, your body tag will render<body class="blog">
Front Page
, your body tag will render<body class="home">
- Blog post detail page (
single.php
), your body tag will render<body class="single">
- Page detail page (
page.php
), your body tag will render<body class="page">
So, you are free now. Style however you want. For external stylesheet, and for home page your style will be (@saifur already mentioned):
body.home #main_content .container {
position: relative;
padding: 120px 0;
}
Internal CSS
For internal CSS, there is a conditional checker in WordPress, called is_home()
, and another is is_front_page()
. With these two, you can check whether "you" are in home page or in front page, and then can load your internal CSS code:
<?php if( is_home() || is_front_page() ) : ?>
<style id="my-internal-css">
#main_content .container {
position: relative;
padding: 120px 0;
}
</style>
<?php endif; ?>
Similarly is_single()
, is_page()
, is_category()
, is_archive()
, is_day()
, ... so on...
Check the class of body tag, there is a class named home for home page. I hope the following css will help you.
.home #main_content .container {
position: relative;
padding: 120px 0;
}
本文标签: cssStyle something only on the home page
版权声明:本文标题:css - Style something only on the home page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745465748a2659528.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论