css 背景圖片撐開容器高度


background-image是屬性,不是塊元素的內容,是無法撐開高度的。要想實現這種效果,一般通過:after,:before來填充。

   .teamDiv{
      background: url(/image/home_team.jpg);
      background-repeat:no-repeat; 
      background-size:100% 100%;
      background-position-x: center;
      margin: 0 auto;

    }
    .teamDiv::after{
      content: "";
      display: block;
      padding-bottom: 36%;

    }
   <div class=" teamDiv" >
     
      <div class="teamContent">
        <p class="text-center team-title">某某團隊</p>


<p class="text-center team-title_en">YOUKING TEAM</p> <p class="text-center team_p">二十年經驗的團隊</p> <p class="text-center team_p_en">Team of twenty years of experience</p> <p class="text-center team_p">提供高性價比方案的團隊</p> <p class="text-center team_p_en"> A team that offers a cost-effective solution </p> <p class="text-center team_p">作品國內外屢獲殊榮的團隊</p> <p class="text-center team_p_en"> Award-winning team at home and abroad </p> <p class="text-center team_p">思維奔放、嚴謹做事的團隊</p> <p class="text-center team_p_en"> A team that is open-minded and rigorous </p> <p class="text-center team_p">研究創新的團隊</p> <p class="text-center team_p_en">Research innovative team</p> <p class="text-center team_p">注重節能的團隊</p> <p class="text-center team_p_en">Energy-saving team</p> <p class="text-center team_p">多系統、多元化組合的團隊</p> <p class="text-center team_p_en">Multi-system, diverse team</p> </div> </div>

 附加:如果要隨着圖片的寬高撐開容器,還需要在圖片上添加內容(文字說明)的話,那么一般是定位寫了。

附加:上面的方法通常圖片可能會拉伸,需要計算寬高。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM