Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Quark: different hero-images for different screen-sizes

theme

Solved by AH View solution

Started by AH 3 years ago · 2 replies · 611 views
3 years ago

I installed a Quark One-Page Site Skeleton, Maybe this will be our new band website.
In order for the band to be fully represented on the Hero image on both large, horizontally oriented displays and small, vertically oriented displays, a separate image would have to be inserted for small screens.
horizontal|690x446
vertical|265x500

I've tried in CSS with the @media tag, but have failed so far. I don't see which class the background-image belongs to.

Maybe someone can find a solution?

last edited 09/12/23 by AH
3 years ago Solution

I have found the following solution which is sufficient for my needs. Surely it could be done more elegantly.

  1. templates/partials/hero.html.twig
    Delete in line 1:
    {% if hero_image %}style="background-image: url('{{ hero_image.url }}');"{% endif %}
  2. css/custom.css
    Add:
    section.section.hero {
    background-image: url('/0eg/user/pages/01.home/01._hero/eghorizontal.jpg');
    }
    @media (max-width: 840px) {
    section.section.hero {
    background-image: url("/0eg/user/pages/01.home/01._hero/egvertical.jpg");
    }
    }

I still need to get closer to the optimal breakpoint.

3 years ago

I have the exact same issue but I'm using modular pages. This post was a huge help!

These are the changes I made to have different hero images for a modular page

I had to edit the hero.html.twig in templates/modules and remove {% set hero_image = page.header.hero_image ? page.media[page.header.hero_image] : page.media.images|first %}

Then the css class for modular is .modular-hero.hero {

👍 2

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 193 2 months ago
Themes & Styling · by Ian, 2 months ago
3 91 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 451 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 45 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 125 3 months ago