问题描述
我在想,当我们写background: inherit;
时,它应该完全采用所有父属性,并根据它,应该复制子元素的背景,对吗?
但是今天,当我使用后台附件时,我遇到了一个奇怪的结果,看来当我们使用background-attachment: fixed;
时,并没有进一步的继承:
body{
background-image: url('https://helpx.adobe.com/content/dam/help/en/stock/how-to/visual-reverse-image-search/jcr_content/main-pars/image/visual-reverse-image-search-v2_intro.jpg ');
background-attachment: fixed;
}
#first{
margin:80px 160px;
background: inherit;
border: dotted;
width: 200px;
height: 200px;
}
<div id="first"></div>
如您所见,以上代码的结果似乎与#first{ background:transparent; ...}
等效。
有人能解释为什么background-attachment: fixed;
会发生这种情况吗?我通过互联网进行搜索,但找不到答案,几乎所有的网站在下面的非理性解释中都给了我相同的答案:
解决方法
背景附件设置属性,是背景图像随页面其余部分滚动还是固定。 就像带图片的相对位置