简体   繁体   English

背景重复:空间; 有时在 css 中不工作

[英]background-repeat: space; not working sometimes in css

I am trying to have a smaller background image repeat to make a pattern in the background of my site using this code in a stylesheet:我正在尝试使用样式表中的以下代码重复较小的背景图像以在我的网站背景中制作图案:

body
{
  background-image: url("../img/bknd3.png");
  background-position: 0px 1000px;
  background-repeat: space;
  background-color: blue;
  font-family: helvetica;
}

On most of my pages, this works how I want it to.在我的大多数页面上,这都是我想要的。 There are 2 out of 6 pages where the background-repeat: space doesn't work. 6 页中有 2 页background-repeat: space不起作用。 The background-color works on all the pages, oddly.奇怪的是, background-color适用于所有页面。 Essentially, on the working pages, the background repeats and creates the background pattern I want, while the pages that don't work do not show the image to be repeated at all, while still having the blue background color.本质上,在工作页面上,背景重复并创建了我想要的背景图案,而不工作的页面根本不显示要重复的图像,同时仍然具有蓝色背景颜色。 I am using a separate css stylesheet, so I don't think there should be any problems since the other 4 pages are referencing the same stylesheet and working fine (although I could be completely wrong).我正在使用单独的 css 样式表,所以我认为应该没有任何问题,因为其他 4 个页面都引用了相同的样式表并且工作正常(尽管我可能完全错了)。

I am fairly certain that it is the background-repeat: space;我相当肯定它是background-repeat: space; attribute, because when I change it to repeat-y or repeat-round they work for the 2 pages, although repeat-x , and repeat do not work properly either.属性,因为当我将其更改为repeat-yrepeat-round它们适用于 2 页,尽管repeat-xrepeat也不能正常工作。

When I remove the background-position: 0px 1000px , what happens is that on the pages that aren't working, the repeat: space looks like what repeat-x is supposed to do.当我删除background-position: 0px 1000px时,发生的情况是在不工作的页面上, repeat: space看起来就像repeat-x应该做的那样。

Here are screenshots of working vs. not working:以下是工作与不工作的屏幕截图:

working page工作页面

not working page不工作页面

The repeat-space did not work because on those 2 pages, the only content was a重复空间不起作用,因为在这 2 页上,唯一的内容是

tag with basic placeholder text, so the page wasn't long enough to have the pattern repeat.带有基本占位符文本的标签,因此页面不够长,无法重复模式。 The working pages had plenty of elements, so they were big enough to have the pattern repeat.工作页面有很多元素,所以它们足够大,可以重复模式。

I think you should do that:我认为你应该这样做:

  1. background-position: may top right or top center or %..etc not putting 1000px.背景位置:可能右上角或顶部中心或 %..etc 不放置 1000px。
  2. background-repeat: should use repeat for all x, y | background-repeat: 应该对所有 x, y 使用重复 | or repat-x for horizontal |或 repat-x 用于水平 | or repeat-y for vertical.或重复-y 表示垂直。
  3. put them all in background shorthand https://developer.mozilla.org/en-US/docs/Web/CSS/background将它们全部放在后台简写https://developer.mozilla.org/en-US/docs/Web/CSS/background

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

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