understrap / understrap-child

The starter child theme for Understrap, the renowned open-source WordPress starter theme.
GNU General Public License v3.0
581 stars 331 forks source link

Where to put theme images for CSS background images? #360

Closed currentcreative closed 2 years ago

currentcreative commented 2 years ago

I can see that Understrap does nothing with images at all. I've tried to put an img folder in src and in the main directory, but nothing I do is allowing me to target the images in my css like so:

background: url(img/myimage.jpg);

or even this (haha, this was just a test):

background: url(../../../img/myimage.jpg);

Any way I tried to direct the css path to it, the console says "Could not load image."

currentcreative commented 2 years ago

I figured it out by analyzing how fontawesome is linked in child-theme.css.

How To:

I put a folder called 'img' in the main directory sitting alongside css, fonts, and global-templates. I linked it in _child_theme.css like this:

background: url("../img/myimage.jpg");

also works without quotes like this: background: url(../img/myimage.jpg);

bacoords commented 2 years ago

Glad it worked out - yeah even though the SCSS files are nested very deep in various folders, the final CSS file is just one directory up from the root of the theme folder, so you're really basing it off of the final CSS location, not where you're editing the SCSS files.

currentcreative commented 2 years ago

I was initially thinking if I drop an 'img' folder in 'src' that it would automatically get copied over and compressed like some previous starter kits I've used. I don't know why I was confused long enough to post this and then immediately figured it out after I did post it.