Score:-1

Change CSS without changing the website's filetree

cn flag

I need to change the CSS of my current theme a bit (say, up to 100 lines).

I don't want to create a sub-theme and I don't want to directly edit my theme's files (even though it's premium theme which gets upgraded maybe once in two years so migration, in such a case, would be easy).

Rather, I want to add some global CSS which effects any current theme (given selectors are still matched), but preferably in a way which doesn't alter the website's filetree (so that if I upgrade Drupal no global CSS file will mistakenly be deleted).

Is there any way to add such "database-global-CSS" (or "database-global-JS" by which I will indirectly add the CSS), via the core? Any nasty trick?

Score:2
de flag

Since you do not want to use a subtheme, I'd recommend to create a custom module to attach a custom library with your "global CSS". Simply attach the library on the appropriate preprocess_hook() and that should do the trick.

cn flag
Hello, thanks, wouldn't that alter the filetree? I don't want to touch any file in the filetree.
Kevin avatar
in flag
This is the only way.
misterdidi avatar
de flag
Well, it would add files, of course. But you cannot add any custom CSS/JS without either altering existing files or adding new files.
cn flag
@misterdidi that may be correct for Drupal, but it's not correct for MediaWiki, for example.
misterdidi avatar
de flag
@Alkalix, I was talking for Drupal only, yes. :-)
cn flag
You need to alter the markup, so unless you already have something installed on the site (contrib/custom module) which lets you hack CSS into the page via the database, every in-Drupal solution will require file system changes. The other option is to stick a proxy in front of the site and rewrite it on the fly to link to a CSS file you host somewhere else online. But you're in serious over-engineering territory there
Kevin avatar
in flag
MediaWiki has nothing to do with this...
cn flag
@Clive `The other option is to stick a proxy in front of the site and rewrite it on the fly to link to a CSS file you host somewhere else online. But you're in serious over-engineering territory there` with a bit more details may this be an answer? I use GitHub and call the code from there somehow.
cn flag
It's out of scope for here I'm afraid, but a lot of modern proxy services probably have this feature. Cloudflare seems to for example https://www.cloudflare.com/apps/add-css
Kevin avatar
in flag
Relying on GitHub to serve CSS is unreliable - youd have to have a host and CDN. Honestly, put a 12 line CSS file in a module or theme in Drupal.
cn flag
@Kevin yeah I think I see the point, thanks.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.