“背景”速记属性中“背景位置”的问题

时间:2018-05-23 22:57:08

标签: css background-image

我试图使用background速记属性指定background-sizebackground-repeatbackground-color,但仍然失败。我最终意识到如果您设置background-position,则必须设置background-size,所以我只需将属性设置为inherit / contain no-repeat #FF7000,据我所知,默认为background-position应该从父(body,在本例中)继承,因为我没有明确设置body的{​​{1}}。它仍然无法正常工作。但是,这有效:background-position。为什么明确地设置它并允许它继承不起作用?我的猜测是我对center / contain no-repeat #FF7000如何运作的理解是错误的,但我不确定。

以下是相关代码的全部内容:

inherit

另外,如果这很重要,.side_img { width: 150px; height: 300px; background: center / contain no-repeat #FF7000; } #left_side { background-image: url("images/giraffe_painting.jpg"); } #right_side { background-image: url("images/giraffe_painting_reversed.jpg"); } 选择器会引用id s。

1 个答案:

答案 0 :(得分:1)

background属性的documentation所述,background-size无法单独设置,应与background-position一起使用。 inheritinitial也不是这些属性的有效值。

enter image description here