Newb CSS Question

Started by FrizzleFried, April 02, 2022, 03:26:53 AM

Previous topic - Next topic

FrizzleFried

OK... as a newb who wants to add CSS to an existing mod.  I know I can put the css in the index.css file and it works great... but how do I add the css to the package so that it adds the css to the index.css file at install and removes it an uninstall?


Doug Heffernan

Quote from: FrizzleFried on April 02, 2022, 03:26:53 AMOK... as a newb who wants to add CSS to an existing mod.  I know I can put the css in the index.css file and it works great... but how do I add the css to the package so that it adds the css to the index.css file at install and removes it an uninstall?



Do you mean if you create your own mod? Imo it is best to create your own .css file. I usually create a folder inside the mod package and call it default. Then inside that folder I create another folder called css and iside it I place the css file that I use in my mod.

Then in the package-info.xml file, I call the css file inside the <install for=... area with this:

<require-dir name="default/css" destination="$themedir" />
This will make sure to upload the css file in the right directory when the mod gets installed.

And to remove it upon uninstalltion I use the following code inside the <uninstall for... area

<remove-file name="$themedir/css/mycssfilename.css" />
where mycssfilename.css stands for the actual name of the css file.

This is the most efficient way to go about it imo.

Hope it helps.

FrizzleFried

Thank you!  One question...

Are all css files that are in the "theme/default/css" folder loaded in at all times?  I only ask as I see where you are having me install a css file to a specific folder, but I don't see where it's called from the code.

Doug Heffernan

Quote from: FrizzleFried on April 02, 2022, 09:44:40 AMThank you!  One question...

Are all css files that are in the "theme/default/css" folder loaded in at all times?  I only ask as I see where you are having me install a css file to a specific folder, but I don't see where it's called from the code.

You will have to call/define them. You can download and have a look at my Affiliates mod to see how it is being used. It will give you a much better understanding that way imo.

Advertisement: