Display background image on home page only

For support and discussion related to templates and themes in phpBB 3.3.
exemplary1
Registered User
Posts: 192
Joined: Mon Feb 05, 2024 11:41 am

Display background image on home page only

Post by exemplary1 »

Hi,
I have added background image to forum, but I want to display on home page only.
How do I do that ?
Edit : I am using Prolight style.
Thank you.
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: Display background image on home page only

Post by Gumboots »

Use the .section-index class on the body tag.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
exemplary1
Registered User
Posts: 192
Joined: Mon Feb 05, 2024 11:41 am

Re: Display background image on home page only

Post by exemplary1 »

I did try editing overall_header.html's body tag and adding css to custom.css with the help of AI, didn't work.
User avatar
Steve
Registered User
Posts: 1495
Joined: Tue Apr 07, 2009 7:48 pm
Name: Steven Clark

Re: Display background image on home page only

Post by Steve »

You can use in the overall_header.htm:

Code: Select all

{% if SCRIPT_NAME eq 'index' %}
	<link href="{T_THEME_PATH}/my_css_file.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet">
{% endif %}
Note that 'index' is for the index.php file and my_css_file.css needs to be in your theme's folder, you can also name the CSS file what ever.
@ The Chief Medical Officers guideline for men is that: You are safest not to drink regularly more than 14 units per week.
- I drank that today++ :lol: 🍺

No: https://phpbb3bbcodes.com/viewforum.php?f=66 [r=66]Steve[/r=66]
exemplary1
Registered User
Posts: 192
Joined: Mon Feb 05, 2024 11:41 am

Re: Display background image on home page only

Post by exemplary1 »

Steve wrote: Tue Sep 10, 2024 7:55 pm You can use in the overall_header.htm:

Code: Select all

{% if SCRIPT_NAME eq 'index' %}
	<link href="{T_THEME_PATH}/my_css_file.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet">
{% endif %}
Note that 'index' is for the index.php file and my_css_file.css needs to be in your theme's folder, you can also name the CSS file what ever.
And how do I add image path in css file ?
User avatar
Steve
Registered User
Posts: 1495
Joined: Tue Apr 07, 2009 7:48 pm
Name: Steven Clark

Re: Display background image on home page only

Post by Steve »

What code do you have so far, please?
@ The Chief Medical Officers guideline for men is that: You are safest not to drink regularly more than 14 units per week.
- I drank that today++ :lol: 🍺

No: https://phpbb3bbcodes.com/viewforum.php?f=66 [r=66]Steve[/r=66]
exemplary1
Registered User
Posts: 192
Joined: Mon Feb 05, 2024 11:41 am

Re: Display background image on home page only

Post by exemplary1 »

Ok I have added following, and seems its working.

Code: Select all

body {
   background-image: url('./images/background.jpg');
    background-size: cover;
    background-position: center;
}
Thank you very much.
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: Display background image on home page only

Post by Gumboots »

You don't need to add logic in the template, and you don't need another CSS file just for this. Do things the easy way. I just tested this live on this site via Stylus. It works. Add it to any CSS file.

Code: Select all

.section-index {
	background: url(https://www.phpbb.com/community/styles/prosilver/theme/en/icon_user_online.gif);
}
Hey, presto: the index page background gets tiled online gif's all over it.* No other page is affected. It will work with any image and any valid url. It may need more specificity in the selector if you are trying to override another declaration, but if so that is easy to track down (learn to use the browser's document inspector).

And don't bother tying to use AI for this. Use your own intelligence, It has had far more beta testing.

*I must say it's quite a radical look. :lol:
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
exemplary1
Registered User
Posts: 192
Joined: Mon Feb 05, 2024 11:41 am

Re: Display background image on home page only

Post by exemplary1 »

Well, I can do basic CSS changes but I am not aware how Phpbb/CSS logic works, such as - .section-index

This code is working. At first, it didn't work, as I copied your image path and its behind cloudflare. Then used local image.
Thank you.
User avatar
Sniper_E
Registered User
Posts: 1189
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey

Re: Display background image on home page only

Post by Sniper_E »

I didn't know about .section-index either. I'll have to remember this.

I assume .section-posting and .section-viewtopic and so on will work also?
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: Display background image on home page only

Post by Gumboots »

Sure, and .section-viewforum and .section-search and .section-memberlist and .section-ucp and probably a few others I can't recall offhand. Just check the body classes on any page.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦

Return to “[3.3.x] Styles Support & Discussion”