首頁 > web前端 > css教學 > 主體

如何使用CSS建立一個響應式圖片庫

王林
發布: 2023-08-22 14:29:02
轉載
801 人瀏覽過

如何使用CSS建立一個響應式圖片庫

使用CSS建立響應式圖庫,您可以嘗試執行以下程式碼

範例

##線上示範
<!DOCTYPE html>
<html>
   <head>
      <style>
         div.myGallery {
            border: 2px solid orange;
         }
         div.myGallery:hover {
            border: 1px solid blue;
         }
         div.myGallery img {
            width: 100%;
            height: auto;
         }
         div.desc {
            padding: 20px;
            text-align: center;
         }
         .responsive {
            padding: 0 5px;
            float: left;
            width: 24.99999%;
         }
         @media only screen and (max-width: 700px) {
            .responsive {
               width: 49.99999%;
               margin: 5px 0;
            }
         }
         @media only screen and (max-width: 500px) {
            .responsive {
               width: 100%;
            }
         }
         .clearfix:after {
            content: "";
            display: table;
            clear: both;
         }
      </style>
   </head>
   <body>
      <div class = "responsive">
         <div class = "myGallery">
            <a target = "_blank" href="https://www.tutorialspoint.com/assets/videotutorials/courses/3d_animation_online_training/380_course_211_image.jpg">
               <img src = "https://www.tutorialspoint.com/assets/videotutorials/courses/3d_animation_online_training/380_course_211_image.jpg" alt="3D Animation Tutorial"    style="max-width:90%"  style="max-width:90%">
            </a>
            <div class = "mydiv">3D Animation Tutorial></div>
         </div>
      </div>
      <div class = "responsive">
         <div class = "myGallery">
            <a target = "_blank" href = "https://www.tutorialspoint.com/assets/videotutorials/courses/swift_4_online_training/380_course_210_image.jpg">
               <img src = "https://www.tutorialspoint.com/assets/videotutorials/courses/swift_4_online_training/380_course_210_image.jpg" alt="Swift Video Tutorial"    style="max-width:90%"  style="max-width:90%">
            </a>
            <div class = "mydiv">Swift Video Tutorial</div>
         </div>
      </div>
      <div class = "responsive">
         <div class = "myGallery">
            <a target = "_blank" href = "https://www.tutorialspoint.com/assets/videotutorials/courses/css_online_training/380_course_215_image.jpg">
               <img src = "https://www.tutorialspoint.com/assets/videotutorials/courses/css_online_training/380_course_215_image.jpg" alt="CSS Video Tutorial"    style="max-width:90%"  style="max-width:90%">
            </a>
            <div class="mydiv">CSS Tutorial</div>
         </div>
      </div>
      <div class = "clearfix"></div>
   </body>
</html>
登入後複製

以上是如何使用CSS建立一個響應式圖片庫的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!