首頁 > web前端 > css教學 > 如何使用 Bootstrap 3 創建具有透明顏色疊加的全寬背景?

如何使用 Bootstrap 3 創建具有透明顏色疊加的全寬背景?

DDD
發布: 2025-01-03 22:25:40
原創
575 人瀏覽過

How to Create a Full-Width Background with Transparent Color Overlays Using Bootstrap 3?

透明顏色疊加的Bootstrap 全寬背景

使用Bootstrap 3 建立具有透明顏色疊加的全角背景影像可能看起來令人畏懼,但透過巧妙的技術是可能的。

要實現這一目標,您將結合使用絕對定位、偽元素和顏色疊加。

HTML 結構:

<div class="container extra">
  <div class="row">
    <div class="col-sm-4 left"></div>
    <div class="col-sm-8 right"></div>
  </div>
</div>
登入後複製

CSS樣式:

.container {
  width: 50%;
  margin: auto;
  margin-top: 1em;
  position: relative;
  overflow: visible;
}
.extra:before {
  content: '';
  display: block;
  position: absolute;
  top: 0;
  left: 50%;
  width: 100vw;
  height: 100%;
  transform: translate(-50%, 0);
}
.left:before {
  content: '';
  position: absolute;
  height: 100%;
  width: 100vw;
  top: 0;
  right: 0;
  background: rgba(255, 0, 0, 0.5);
}
.right:before {
  content: '';
  position: absolute;
  height: 100%;
  width: 100vw;
  top: 0;
  left: 0;
  background: rgba(0, 0, 255, 0.25);
}
登入後複製

說明:

  • .container元素設定為特定寬度並以自動邊距居中。
  • 加入偽元素 .extra:before 將容器的寬度擴展到視窗之外,創造全角背景的錯覺。
  • .col 元素被賦予實心邊框以進行視覺化。
  • .left 和 .right 中的偽元素充當透明顏色疊加層,覆蓋

    此技術可讓您輕鬆使用 Bootstrap 3 實現所需的背景和疊加效果。

    以上是如何使用 Bootstrap 3 創建具有透明顏色疊加的全寬背景?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

  • 本網站聲明
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
    熱門教學
    更多>
    最新下載
    更多>
    網站特效
    網站源碼
    網站素材
    前端模板