HTML照片墻是一個常見的網頁元素,可以讓網站更加美觀有趣。下面是一份完整的HTML照片墻代碼。
<!DOCTYPE html> <html> <head> <title>HTML照片墻</title> <style> .photo-container { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; } .photo { width: 200px; height: 200px; background-size: cover; background-position: center; } </style> </head> <body> <div class="photo-container"> <div class="photo" style="background-image: url('photo1.jpg')"></div> <div class="photo" style="background-image: url('photo2.jpg')"></div> <div class="photo" style="background-image: url('photo3.jpg')"></div> <div class="photo" style="background-image: url('photo4.jpg')"></div> <div class="photo" style="background-image: url('photo5.jpg')"></div> <div class="photo" style="background-image: url('photo6.jpg')"></div> <div class="photo" style="background-image: url('photo7.jpg')"></div> <div class="photo" style="background-image: url('photo8.jpg')"></div> <div class="photo" style="background-image: url('photo9.jpg')"></div> </div> </body> </html>
以上代碼由三個部分組成:
1.頭部聲明DOCTYPE,引入網頁標題和樣式。
2.在具有class為‘photo-container’的div中添加了9張圖片,實際環境中可以換成自己的照片。
3.完成后,瀏覽器將顯示照片墻。