Use with Drupal: Memory game does not honour style hook
Submitted by SirClickalot on Thu, 09/28/2023 - 07:00
Forums:
I am using H5P very successfully with Drupal 9 to create an educational site.
I routinely use the custom_h5p_overrides_h5p_styles_alter Drupal hook to modify the CSS style of components and I do this successfully with all sorts of components using...
function custom_h5p_overrides_h5p_styles_alter(&$styles, $libraries, $mode) { $styles[] = (object) [ // Path relative to drupal root 'path' => \Drupal::service('extension.list.module')->getPath('custom_h5p_overrides') . '/css/custom-h5p-overrides.css', // Cache buster 'version' => '?ver=1', ]; }
However, no matter what I try in my overriding CSS file such as (for example to remove the card roundedness) - even with some !importants in place.
.h5p-memory-game .h5p-memory-card .h5p-back, .h5p-memory-game .h5p-memory-card .h5p-front { border: none !important; border-radius: 0 !important; }
Yet, for other components such as multi-choice, override works a treat, for example (snapshot from the Chrome Inspector) ...
.h5p-multichoice .h5p-alternative-container { background: none; border: none; box-shadow: none; display: inline-flex; }
Can anyone help here?
Thanks
Content types:
otacke
Fri, 10/06/2023 - 19:58
Permalink
Hi!The CSS looks fine to me
Hi!
The CSS looks fine to me (except for the `!important` that should not be required and be replaceable by specificity, but I assume that's not news and should not play a role here).
One difference there is to e.g. MultipleChoice is that MemoryGame is one of the few content types that does not run inside an iframe. Potentially, then the override fails. Feels like a bug in some part of H5P then, but on the other hand that means that you do not need to use the override hooks. You should be able to restyle MemoryGame by adding your changes to your Drupal theme for instance, as MemoryGame is included in the page directly and not walled in inside an iframe.
Best,
Oliver
SirClickalot
Sat, 10/07/2023 - 16:12
Permalink
Brilliant, nice spot Oliver,
Brilliant, nice spot Oliver, thank you!
My Memory games now look in keeping with the rest of my site.
I agree that this is a bug because it shoiuld not have to live in an <iframe> in order for my custom module code and CSS to kick in.
Where do you perceive the bug to be:
Nick
otacke
Sat, 10/07/2023 - 17:36
Permalink
H5P in general can handle
H5P in general can handle both, content types inside iframes and without. It's the content type developers' choice, not a bug if it is one way or the other. It's merely one line in library.json.
And yes, the override should work either way. Might be that H5P integration (aka the plugin) or the core of H5P does only have code to add the stylesheet file to an iframe but does nothing if there's no iframe. Would need to be investigated.