2017-03-08 18 views
0

我正在製作一個網站,並且在正文上有一個背景圖像屬性。我希望背景圖像具有指定的像素寬度,但我找不到任何可行的東西。如何強制背景圖像具有固定的像素寬度

這是我到目前爲止有:

body { 
 
    background-image: url("http://kids.nationalgeographic.com/content/dam/kids/photos/animals/Birds/H-P/mallard-male-standing.jpg.adapt.945.1.jpg"); 
 
    background-size: cover; 
 
}
<!DOCType html> 
 
<html> 
 
    <body> 
 
    </body> 
 
</html>

+0

那是你的形象在試圖代碼中使用....因爲這不適合我,如果我改變它爲本地圖像工作正常。 – Toxide82

+0

有人剛剛發佈了答案,並且因爲某種原因被拒絕了,現在它已經不存在了,但是'background-size'屬性就是你所需要的。 – Brad

+0

我喜歡你在標題中放置一個表情 –

回答

1

body { 
 
    background-image: url("https://images.unsplash.com/photo-1477915737647-b5246ee6de6f?dpr=1&auto=format&fit=crop&w=1500&h=1000&q=80&cs=tinysrgb&crop="); 
 
    background-size: 500px auto; 
 
    background-repeat: no-repeat; 
 
    background-attachment: fixed; 
 
    background-position: center; 
 
}
<!DOCType html> 
 
<html> 
 
    <body> 
 
    </body> 
 
</html>

0
.your-div { 
    display: inline-block; 
    width: 100px; 
}