Jump to content

Different background video for mobile to desktop

Go to solution Solved by Spark-Plugin,

Recommended Posts

Posted (edited)

Hey!

I have added a background video to homepage of the website

I have a vertical version of the video that I would like as the background video for mobile. 

Can anybody show me how it is possible to add 2 different videos please.

 

Thanks so much

 

Edited by visual_ess
  • Replies 3
  • Views 100
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution
Posted

Hello @visual_ess, You can create a dedicated section with a vertical video background specifically for mobile devices while keeping your current background video section for desktop view. With custom CSS, we’ll ensure the vertical video section appears only on mobile devices, providing a tailored experience for both views. Here’s how you can proceed:

  1. Add a New Section:

    • Go to your Squarespace editor.
    • Create a new section just below your desktop background video section.
    • Add your vertical video to this new section.
  2. Get the Section ID:

    • In the Squarespace editor, inspect the section using this extension to locate the ID for the vertical video section (e.g., #block-id).
  3. Apply Custom CSS:
    Once you have the section ID, use the following CSS:

/* Hide video on desktop screens (768px and wider) */
@media screen and (min-width: 768px) {
  #block-yui_4_12_2_1_2718520257422_12345 {
    display: none; /* Completely hides this video block on desktop and larger screens */
  }
}

/* Hide video on mobile screens (767px and narrower) */
@media screen and (max-width: 767px) {
  #block-yui_1_17_2_1_2717496829514_12345 {
    display: none; /* Completely hides this video block on mobile and smaller screens */
  }
}

Replace #block-id with the ID of the vertical video section and #desktop-video-section-id with the ID of your desktop video section.

 

Let me know if it works:)

- Answered by Iuno from sparkplugin.com

forumsignature-recommendedcopy2.png.0579645eb1430dc7c1059541dc6456c6.png

Posted

1. Upload the Videos

  • Go to Settings > Files in your Squarespace dashboard and upload both videos:
    • Desktop Video: Wide version
    • Mobile Video: Vertical version
  • Copy the URLs for the uploaded videos.

Then, insert a Code Block where you want the videos to

<div class="background-video-container">
    <!-- Desktop Video -->
    <video class="background-video desktop-video" autoplay muted loop playsinline>
        <source src="YOUR_DESKTOP_VIDEO_URL.mp4" type="video/mp4">
        Your browser does not support the video tag.
    </video>

    <!-- Mobile Video -->
    <video class="background-video mobile-video" autoplay muted loop playsinline>
        <source src="YOUR_MOBILE_VIDEO_URL.mp4" type="video/mp4">
        Your browser does not support the video tag.
    </video>
</div>

Add this below code into custom css:

/* Ensure both videos cover their containers */
.background-video-container {
    position: relative;
    width: 100%;
    height: 100vh; /* Full height */
    overflow: hidden;
}

.background-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Hide the mobile video by default */
.mobile-video {
    display: none;
}

/* Show desktop video on screens wider than 768px */
@media (min-width: 768px) {
    .desktop-video {
        display: block;
    }

    .mobile-video {
        display: none;
    }
}

/* Show mobile video on screens narrower than 768px */
@media (max-width: 767px) {
    .desktop-video {
        display: none;
    }

    .mobile-video {
        display: block;
    }
}

 

Posted
4 hours ago, Spark-Plugin said:

Hello @visual_ess, You can create a dedicated section with a vertical video background specifically for mobile devices while keeping your current background video section for desktop view. With custom CSS, we’ll ensure the vertical video section appears only on mobile devices, providing a tailored experience for both views. Here’s how you can proceed:

  1. Add a New Section:

    • Go to your Squarespace editor.
    • Create a new section just below your desktop background video section.
    • Add your vertical video to this new section.
  2. Get the Section ID:

    • In the Squarespace editor, inspect the section using this extension to locate the ID for the vertical video section (e.g., #block-id).
  3. Apply Custom CSS:
    Once you have the section ID, use the following CSS:

/* Hide video on desktop screens (768px and wider) */
@media screen and (min-width: 768px) {
  #block-yui_4_12_2_1_2718520257422_12345 {
    display: none; /* Completely hides this video block on desktop and larger screens */
  }
}

/* Hide video on mobile screens (767px and narrower) */
@media screen and (max-width: 767px) {
  #block-yui_1_17_2_1_2717496829514_12345 {
    display: none; /* Completely hides this video block on mobile and smaller screens */
  }
}

Replace #block-id with the ID of the vertical video section and #desktop-video-section-id with the ID of your desktop video section.

 

Let me know if it works:)

Amazing! Worked perfectly and so easy! Thank you so much!! 

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • 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.