主頁
CSS
CSS 背景
Tryit: background-size - 使用 contain 和 cover
執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> .div1 { border: 1px solid black; height: 120px; width: 150px; background: url(img_flwr.gif); background-repeat: no-repeat; background-size: contain; } .div2 { border: 1px solid black; height: 120px; width: 150px; background: url(img_flwr.gif); background-repeat: no-repeat; background-size: cover; } .div3 { border: 1px solid black; height: 120px; width: 150px; background: url(img_flwr.gif); background-repeat: no-repeat; } </style> </head> <body> <h1>The background-size Property</h1> <h2>background-size: contain:</h2> <div class="div1"> <p>Lorem ipsum dolor sit amet.</p> </div> <h2>background-size: cover:</h2> <div class="div2"> <p>Lorem ipsum dolor sit amet.</p> </div> <h2>No background-size defined:</h2> <div class="div3"> <p>Lorem ipsum dolor sit amet.</p> </div> <p>Original image:</p> <img src="img_flwr.gif" alt="Flowers" width="224" height="162"> </body> </html>