我如何使用CSS背景属性?

时间:2017-12-09 14:29:58

标签: html css css3 background

body {
  background: #fff url("milkshakeonthewindowsill.jpg") cover no-repeat fixed;
}

这是我的身体的CSS,然而,它不会加载图像,但不知何故,

body {
  background-color: #fff; 
  background-image: url("milkshakeonthewindowsill.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

这段代码确实如此。我错过了什么或做错了什么?

3 个答案:

答案 0 :(得分:3)

根据我的经验,尺寸$certs = ls Cert:\LocalMachine\ -Recurse | Select @{Name = '{#CertInfo}'; Expression = {$_.FriendlyName}} | Where { $_.'{#CertInfo}' } | Sort '{#CertInfo}' 必须单独添加:

cover

答案 1 :(得分:2)

使用速记属性时,属性值的顺序为:

background-color
background-image
background-repeat
background-attachment
background-position

如果其中一个属性值丢失,则无关紧要,只要其他属性值按此顺序排列即可。

background: #fff url("milkshakeonthewindowsill.jpg") cover no-repeat fixed; 

您正在使用缩写语法不支持的后台大小,它应该按照上面给出的顺序工作。所以,正确的语法是:

background: #fff url("milkshakeonthewindowsill.jpg") no-repeat fixed;
background-size:cover;

答案 2 :(得分:0)

必须单独添加背景大小封面:

List<KeyValuePair<int,int>> sequence = new List<KeyValuePair<int,int>>();

// Populate keys in sequence with random numbers 1-5
// ...

public static void SetSequenceValues()
{
    Random randNum = new Random();
    bool allValuesSet = false;

    // count is the max (non-inclusive) in each range of 4
    // i.e. first loop is 1-4
    // then count += 4
    // second loop is 5-8, etc.
    int count = 5;

    while (allValuesSet == false)
    {
        int randPos = randNum.Next(count - 4, count);

        // If changing the first key in the range,
        // the desired key index = count-4
        if (randPos == count - 4)
        {
            var oldKVP = sequence[count - 4];
            sequence[count - 4] = new KeyValuePair<int, int>(oldKVP.Key, 1);
        }
        else if (randPos == count -3)
        {
            var oldKVP = sequence[count - 3];
            sequence[count -3] = new KeyValuePair<int, int>(oldKVP.Key, 1);
        }
        else if (randPos == count - 2)
        {
            var oldKVP = sequence[count - 2];
            sequence[count - 2] = new KeyValuePair<int, int>(oldKVP.Key, 1);
        }
        else if (randPos == count - 1)
        {
            var oldKVP = sequence[count - 1];
            sequence[count - 1] = new KeyValuePair<int, int>(oldKVP.Key, 1);
        }

        // Increase count by 4, so on the next loop, e.g. the range looked at will be 4-8 (not including 8, i.e. 4-7)
        count += 4;

        if (count >= sequence.Count)
            allValuesSet = true;
    }
}