CSS 教學

Upper House 全屏視頻 Hero — 沉浸式首頁完整實現

4 分鐘閱讀 · · 2026年7月12日
Upper House 全屏視頻 Hero — 沉浸式首頁完整實現

Upper House 全屏視頻 Hero — 沉浸式首頁完整實現


點解全屏視頻 Hero 咁吸睛?

上過 Upper House(upperhouse.com)個網站嘅朋友一定記得,一打開就見到一段好靚嘅全屏視頻 — 無邊無際,畫面直接填滿成個螢幕,文字浮喺視頻上面,成個感覺好有沉浸感。對比起普通嘅靜態圖片 Hero,視頻背景可以帶出更多情緒同氛圍。

對於植物店嚟講,呢個效果簡直係絕配。想像一下:用一段微風吹拂綠植搖曳嘅視頻做背景,再配搭簡潔嘅店名同 Slogan,客人一入嚟就已經感受到大自然嘅氣息。今堂課就教你點樣做到。


HTML5 Video 標籤設定 — 打好基礎

做全屏視頻 Hero,首先要正確設定 `<video>` 標籤。有幾個屬性係必須要嘅:

<!-- ===== 全屏視頻 Hero HTML 結構 ===== -->
<section class="video-hero">
  <!-- 視頻背景 -->
  <video 
    class="video-hero__bg"
    autoplay         <!-- 自動播放 -->
    muted            <!-- 必須靜音(瀏覽器政策) -->
    loop             <!-- 循環播放 -->
    playsinline      <!-- iOS 行內播放(唔會強制全屏) -->
    poster="images/hero-poster.jpg"  <!-- 載入前顯示嘅封面圖 -->
  >
    <source src="videos/plants-hero.webm" type="video/webm">
    <source src="videos/plants-hero.mp4" type="video/mp4">
    <!-- 後備文字 -->
    <p>你嘅瀏覽器唔支援視頻播放。</p>
  </video>
  
  <!-- 半透明遮罩層 -->
  <div class="video-hero__overlay"></div>
  
  <!-- 內容層 -->
  <div class="video-hero__content">
    <h1 class="video-hero__title">綠意空間</h1>
    <p class="video-hero__subtitle">讓自然融入生活每一個角落</p>
    <a href="#products" class="video-hero__cta">探索植物系列</a>
  </div>
  
  <!-- 向下捲動提示 -->
  <div class="video-hero__scroll-hint">
    <span>向下捲動</span>
    <svg class="scroll-arrow" viewBox="0 0 24 24">
      <path d="M7 10l5 5 5-5z"/>
    </svg>
  </div>
</section>

⚠️ **重要**:`muted` 屬性係必須嘅!現代瀏覽器(Chrome、Safari)唔會俾自動播放有聲視頻,冇 `muted` 嘅話視頻根本唔會播。


CSS 全屏視頻核心代碼 — 填滿成個螢幕

呢段 CSS 係成個效果嘅靈魂,`object-fit: cover` 確保視頻無論喺咩螢幕尺寸都會填滿畫面:

/* ===== 全屏視頻 Hero 核心 CSS ===== */

/* Hero 容器 — 佔滿整個視口 */
.video-hero {
  position: relative;
  width: 100%;
  height: 100vh;           /* 100% 視口高度 */
  min-height: 600px;       /* 最細高度 */
  overflow: hidden;        /* 裁切超出部分 */
  display: flex;           /* 用 Flexbox 置中內容 */
  align-items: center;
  justify-content: center;
}

/* 視頻背景 — 絕對定位填滿 */
.video-hero__bg {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  transform: translate(-50%, -50%);  /* 完美置中 */
  object-fit: cover;                 /* 保持比例填滿 */
  z-index: 1;
}

/* 半透明遮罩層 — 令文字更易讀 */
.video-hero__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.3) 0%,
    rgba(0, 0, 0, 0.5) 100%
  );
  z-index: 2;
}

/* 內容層 — 置中最前面 */
.video-hero__content {
  position: relative;
  z-index: 3;
  text-align: center;
  color: #FFFFFF;
  max-width: 800px;
  padding: 0 2rem;
}

/* 標題 */
.video-hero__title {
  font-size: clamp(2.5rem, 6vw, 5rem);  /* 響應式字體 */
  font-weight: 700;
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
  line-height: 1.2;
}

/* 副標題 */
.video-hero__subtitle {
  font-size: clamp(1rem, 2.5vw, 1.5rem);
  font-weight: 300;
  margin-bottom: 2rem;
  opacity: 0.9;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.3);
}

/* CTA 按鈕 */
.video-hero__cta {
  display: inline-block;
  padding: 1rem 2.5rem;
  background-color: #2D5016;          /* 植物綠 */
  color: #FFFFFF;
  text-decoration: none;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 500;
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.video-hero__cta:hover {
  background-color: transparent;
  border-color: #FFFFFF;
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* 向下捲動提示 */
.video-hero__scroll-hint {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  color: #FFFFFF;
  text-align: center;
  font-size: 0.875rem;
  opacity: 0.7;
  animation: bounce 2s infinite;
}

.scroll-arrow {
  width: 24px;
  height: 24px;
  fill: currentColor;
  margin-top: 0.5rem;
}

/* 彈跳動畫 */
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateX(-50%) translateY(0);
  }
  40% {
    transform: translateX(-50%) translateY(-10px);
  }
  60% {
    transform: translateX(-50%) translateY(-5px);
  }
}

📸 **截圖位置**:顯示視頻填滿全屏 + 深色遮罩 + 白色標題置中嘅完整效果


性能優化 — 影片唔好大過 5MB

視頻 Hero 最緊要就係快,如果載入慢成個網站都會被拖慢。以下係必做嘅優化:

/* ===== 性能優化相關 CSS ===== */

/* 視頻載入前顯示 poster 圖 */
.video-hero__bg {
  /* poster 圖會喺視頻載入前顯示 */
  background-image: url('images/hero-poster.jpg');
  background-size: cover;
  background-position: center;
}

/* 確保視頻載入後蓋住 poster */
.video-hero__bg[src] {
  background-image: none;
}

/* 降低移動端數據用量 */
@media (max-width: 768px) {
  .video-hero__bg {
    /* 移動端改用較低解析度視頻 */
    /* 或乾脆用 poster 圖代替 */
  }
  
  .video-hero {
    min-height: 500px;
  }
}

/* 偏好減少動畫嘅用戶 */
@media (prefers-reduced-motion: reduce) {
  .video-hero__bg {
    display: none;  /* 唔播視頻 */
  }
  
  .video-hero {
    background-image: url('images/hero-poster.jpg');
    background-size: cover;
    background-position: center;
  }
}

視頻壓縮建議

參數 建議值
解析度 1920×1080(桌面)/ 1280×720(移動端)
編碼 H.264(MP4)+ VP9(WebM)
檔案大小 盡量控制在 3-5MB
長度 5-10 秒循環
Bitrate 2000-4000 kbps

💡 **工具推薦**:用 HandBrake(免費)壓縮視頻,或者 ffmpeg 命令行壓縮。


植物店專用版本 — 綠植搖曳背景

以下係專為植物店設計嘅完整版本,視頻內容改為綠植搖曳:

<!-- ===== 植物店全屏視頻 Hero ===== -->
<section class="plant-hero">
  <video 
    class="plant-hero__video"
    autoplay muted loop playsinline
    poster="images/green-plants-poster.jpg"
  >
    <source src="videos/green-plants-swaying.webm" type="video/webm">
    <source src="videos/green-plants-swaying.mp4" type="video/mp4">
  </video>
  
  <!-- 綠色調遮罩 — 呼應植物主題 -->
  <div class="plant-hero__overlay"></div>
  
  <div class="plant-hero__content">
    <span class="plant-hero__badge">🌿 香港本地植物店</span>
    <h1 class="plant-hero__title">讓綠意住入你屋企</h1>
    <p class="plant-hero__desc">
      精心挑選嘅室內植物,由專人照顧到你手中<br>
      每一棵都帶住大自然嘅祝福
    </p>
    <div class="plant-hero__buttons">
      <a href="#shop" class="btn btn--primary">立即選購</a>
      <a href="#care" class="btn btn--outline">植物護理指南</a>
    </div>
  </div>
</section>
/* ===== 植物店專用 CSS ===== */

.plant-hero {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 700px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.plant-hero__video {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  transform: translate(-50%, -50%);
  object-fit: cover;
  z-index: 1;
}

/* 綠色調半透明遮罩 */
.plant-hero__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(26, 48, 9, 0.7) 0%,
    rgba(45, 80, 22, 0.5) 50%,
    rgba(26, 48, 9, 0.6) 100%
  );
  z-index: 2;
}

.plant-hero__content {
  position: relative;
  z-index: 3;
  text-align: center;
  color: #FFFFFF;
  max-width: 700px;
  padding: 0 1.5rem;
}

/* 小標籤 */
.plant-hero__badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  padding: 0.5rem 1.25rem;
  border-radius: 50px;
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  letter-spacing: 0.05em;
}

.plant-hero__title {
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 700;
  margin-bottom: 1rem;
  line-height: 1.2;
  text-shadow: 0 2px 15px rgba(0, 0, 0, 0.4);
}

.plant-hero__desc {
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.8;
  margin-bottom: 2rem;
  opacity: 0.9;
}

/* 按鈕組 */
.plant-hero__buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  padding: 0.875rem 2rem;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.3s ease;
  cursor: pointer;
  border: 2px solid transparent;
}

.btn--primary {
  background-color: #4A7A28;
  color: #FFFFFF;
}

.btn--primary:hover {
  background-color: #5A9632;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(74, 122, 40, 0.4);
}

.btn--outline {
  background-color: transparent;
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.5);
}

.btn--outline:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: #FFFFFF;
}

/* 響應式調整 */
@media (max-width: 768px) {
  .plant-hero {
    min-height: 100svh;  /* 使用 svh 避免地址欄問題 */
  }
  
  .plant-hero__buttons {
    flex-direction: column;
    align-items: center;
  }
  
  .btn {
    width: 100%;
    max-width: 280px;
  }
}

📸 **截圖位置**:顯示綠植視頻背景 + 綠色調遮罩 + 雙按鈕佈局嘅植物店 Hero


常見問題

**Q:視頻唔自動播放點算?**

確保有 `muted` 屬性!Chrome 同 Safari 都要求自動播放必須靜音。如果仍然唔得,檢查視頻路徑是否正確。

**Q:iPhone 上面視頻會強制全屏?**

加 `playsinline` 屬性,iOS 10+ 就會行內播放。

**Q:視頻太大載入慢?**

用 poster 圖先做 placeholder,視頻用 `preload=”metadata”` 延遲載入。


重點回顧

技巧 作用
`object-fit: cover` 保持比例填滿容器
`position: absolute` + `translate(-50%, -50%)` 完美置中
半透明遮罩 確保文字可讀性
`playsinline` iOS 行內播放
`prefers-reduced-motion` 尊重用戶動畫偏好

下一步

下一堂我哋會教你整 **毛玻璃導航欄**,學 K11 網站嗰種 `backdrop-filter: blur()` 效果,令導航欄有通透嘅質感,襯埋今堂嘅視頻 Hero 一流!


**關於 TrendyOnly**

TrendyOnly 係專為香港中小企打造嘅 AI 網站生成平台。唔識設計?冇問題!我哋幫你分析全球頂尖品牌嘅設計策略,自動生成最啱你行業嘅網站。開植物店嘅話,我哋會自動推薦綠色調、植物主題排版,連視頻 Hero 都可以一鍵生成。

上 [trendyonly.com](https://trendyonly.com) 免費試用,5 分鐘見效果!