Jump to content

Change section background image on dark mode

Recommended Posts

Hi all!

 

I am working on a dark mode version of my website. I am trying to change the first section background image of the landing page to another image when the viewer uses dark mode, but can't manage to make it work. Here is what I tried so far:

@media (prefers-color-scheme: dark) {
[data-section-id="5feca0a7dc82f97fd38e575d"] .section-background img {
    visibility: hidden;
}
/* set new image */
[data-section-id="5feca0a7dc82f97fd38e575d"] .section-background {
    background-image: url(https://static1.squarespace.com/static/5f0cd7575142de45f1d531a7/t/5feca8261d1415656f7995fb/1609345064730/WEBtransats_landingpage_night_123020.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
}
}
}

Any help is appreciated.

Thank you!

Link to comment
  • Replies 2
  • Views 741
  • Created
  • Last Reply
27 minutes ago, TOMweb said:

Site URL: https://endive-denim-89ds.squarespace.com/

pw: 1404-Hello

 

Hi all!

 

I am working on a dark mode version of my website. I am trying to change the first section background image of the landing page to another image when the viewer uses dark mode, but can't manage to make it work. Here is what I tried so far:


@media (prefers-color-scheme: dark) {
[data-section-id="5feca0a7dc82f97fd38e575d"] .section-background img {
    visibility: hidden;
}
/* set new image */
[data-section-id="5feca0a7dc82f97fd38e575d"] .section-background {
    background-image: url(https://static1.squarespace.com/static/5f0cd7575142de45f1d531a7/t/5feca8261d1415656f7995fb/1609345064730/WEBtransats_landingpage_night_123020.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
}
}
}

Any help is appreciated.

Thank you!

You got wrong id of the section, use this extension to find correct id

Chrome Web Store - Extensions (google.com)

@media (prefers-color-scheme: dark) {
      section[data-section-id="5f0cddf0784c68415c9814fb"] .section-background img {
        visibility: hidden;
      }
      /* set new image */
      section[data-section-id="5f0cddf0784c68415c9814fb"] .section-background {
        background-image: url(https://static1.squarespace.com/static/5f0cd7575142de45f1d531a7/t/5feca8261d1415656f7995fb/1609345064730/WEBtransats_landingpage_night_123020.jpg);
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center center;
      }
}

image.thumb.png.fed43e9a67819213174fcccd791cfa4a.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.