如何强制背景图像具有固定的宽度(以像素为单位)

时间:2017-03-08 15:00:35

标签: html css image

我正在创建一个网站,我的身体上有一个背景图像属性。我希望背景图像具有指定的宽度(以像素为单位),但我无法找到任何有效的内容。

这是我到目前为止所做的:



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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

&#13;
&#13;
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; 
 }
&#13;
<!DOCType html>
<html>
  <body>
  </body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

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