Linking to an image from Media Folder in CSS

Everything to do with Joomla! 4.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
mowen10
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Thu Jan 19, 2012 12:01 pm

Linking to an image from Media Folder in CSS

Post by mowen10 » Tue Apr 23, 2024 11:22 am

Hi, I have managed to migrate my site from 3.9 to 4.4 and I am now trying to get my site up and running using the Cassiopeia template. I have my articles, modules with there positions and I have changed these over to the new positions and these are all showing up. The issue I am having is with images within my media folder and a banner that I have.

I have added a user.css file and within there for example I have the following which used to work in my old site:

#mainbox {
float: left;
position: relative;
background: url(../images/box.png) no-repeat;
height: 249px;
max-width: 100%;
}

When I refresh my site, the image does not load, but I can see the URL of the image which is incorrect and this shows:

http://localhost/mynewsite/media/templa ... es/box.png

The URL of the image in the Media Folder is:

http://localhost/mynewsite/images/box.png

I tried changing the URL in the CSS to:

background: url(./images/box.png) no-repeat;
background: url(/images/box.png) no-repeat;

but none of this works.

Can somebody please advise on how I should be writing this? Thanks.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 31029
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Linking to an image from Media Folder in CSS

Post by Per Yngve Berg » Tue Apr 23, 2024 11:42 am

You have traverse up several steps

../../../images/box.png

mowen10
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Thu Jan 19, 2012 12:01 pm

Re: Linking to an image from Media Folder in CSS

Post by mowen10 » Tue Apr 23, 2024 1:03 pm

Thanks Per Yngve Berg, the problem is the media/templates/ when I check the URL for the image in the media folder just shows:

http://localhost/mynewsite/images/box.jpg

but when I set what you have mentioned:

http://localhost/mynewsite/media/templa ... es/box.png

User avatar
Pavel-ww
Joomla! Ace
Joomla! Ace
Posts: 1671
Joined: Tue Jun 30, 2020 12:17 pm

Re: Linking to an image from Media Folder in CSS

Post by Pavel-ww » Wed Apr 24, 2024 7:34 am

Hi. If the image is located here http://localhost/mynewsite/images/box.jpg in the css should be url(/images/box.jpg).

If this does not work, provide a link to the site (upload on real hosting), because we can guess endlessly.

And by the way, I will assume that the reason may be in this httр://localhost/mynewsite/images...

Even on localhost, the site folder should have the appearance of a domain, for example mynewsite.loc

mowen10
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Thu Jan 19, 2012 12:01 pm

Re: Linking to an image from Media Folder in CSS

Post by mowen10 » Wed Apr 24, 2024 1:47 pm

Pavel-ww wrote:
Wed Apr 24, 2024 7:34 am
Hi. If the image is located here http://localhost/mynewsite/images/box.jpg in the css should be url(/images/box.jpg).

If this does not work, provide a link to the site (upload on real hosting), because we can guess endlessly.

And by the way, I will assume that the reason may be in this httр://localhost/mynewsite/images...

Even on localhost, the site folder should have the appearance of a domain, for example mynewsite.loc
Hi Pavel, thanks for your help, whilst messing around with the code I have managed to sort the issue.

I needed to write it like this:

/mynewsite/images/box.jpg

and that fixed it. Can close this post now, thank you so much.

User avatar
Pavel-ww
Joomla! Ace
Joomla! Ace
Posts: 1671
Joined: Tue Jun 30, 2020 12:17 pm

Re: Linking to an image from Media Folder in CSS

Post by Pavel-ww » Wed Apr 24, 2024 2:50 pm

mowen10 wrote:
Wed Apr 24, 2024 1:47 pm
I needed to write it like this:

/mynewsite/images/box.jpg
Not fixed. This means that your localhost is incorrectly configured, since after transferring to real hosting you will need to change it back to
/images/box.jpg.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 31029
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Linking to an image from Media Folder in CSS

Post by Per Yngve Berg » Wed Apr 24, 2024 2:59 pm

Create a new Virtual Host in your web server.


Post Reply

Return to “Templates for Joomla! 4.x”