使用 CSS 實現背景影像的響應性


你可以嘗試執行以下程式碼,以使用 CSS 實現背景影像的響應性 −

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content="width = device-width, initial-scale = 1.0">
      <style>
         div {
            width: 100%;
            height: 300px;
            border: 2px dashed blue;
            background-image: url('https://tutorialspoint.tw/python/images/python-data-science.jpg');
            background-repeat: no-repeat;
            background-size: contain;
         }
      </style>
   </head>
   <body>
      <p>To check the effect, you need to resize the browser.</p>
      <div></div>
   </body>
</html>

更新於: 2020-07-04

140 次瀏覽

開啟你的 職業

完成課程獲得認證

開始
廣告
© . All rights reserved.