简体   繁体   English

调整窗口大小时重复背景图像(背景重复是不重复的)

[英]Background-image repeating when resize window (background-repeat is no-repeat)

My background image is repeat even though in css I have background-repeat: no-repeat; 我的背景图片是重复的,尽管在CSS中我有background-repeat: no-repeat;

Why is this happening? 为什么会这样呢?

This happens when I resize my window. 当我调整窗口大小时会发生这种情况。

I have a TV on background as video layer. 我的背景电视上有电视作为视频层。

HTML: HTML:

<div class="tv">
   <video width="98%" height="78%" controls="controls">
          <source src="img/showreel.mp4" type="video/mp4">
   </video>
</div>

CSS: CSS:

.tv{
  text-align: center;
  position:relative;
  background-repeat: no-repeat;
  background: url(img/tv.png) center center;
  background-size: 100%;
  height: 650px;
  width: 100%;
}

.showreel-video{
  position:relative;
  margin-top: -40px;
}

Your background-repeat: no-repeat; 您的background-repeat: no-repeat; instruction is currently being overridden by the background:...; 指令当前被background:...;覆盖background:...; attribute because the latter also accepts a repeat/no-repeat instruction and is placed after . 属性,因为后者也接受重复/不重复指令,并置于之后

So, you must either add no-repeat to your background attribute like this: 因此,您必须像这样将no-repeat添加到您的background属性中:

background: url(http://lorempixel.com/400/200/) center center no-repeat;

or move background-repeat: no-repeat; 或移动background-repeat: no-repeat; after the background instruction. 在后台指令之后。

Just remove background-repeat and set background something like the following: 只需删除background-repeat并设置背景,如下所示:

 background: url(http://lorempixel.com/400/200/) center center no-repeat;

Demo: http://jsbin.com/cacofotaqo/1/ 演示: http//jsbin.com/cacofotaqo/1/

In your css the background-repeat is being overwritten by the defaults for your background declaration as CSS processes rules from top to bottom. 在CSS中,由于CSS从上至下处理规则,背景声明的默认值被背景声明的默认值覆盖。 If you switch background-repeat and background then it will work: 如果您切换背景重复和背景,那么它将起作用:

background: url(img/tv.png) center center;
background-repeat: no-repeat;
background-size: 100%;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM