Html background-image:no-repeat 不起作用,语法正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11109013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:08:58  来源:igfitidea点击:

background-image:no-repeat not working, syntax is correct

htmlcss

提问by X10nD

Below is the syntax I am using for the background Image. For some reason it is repeating on Y. I cannot use overflow:hidden;

下面是我用于背景图像的语法。出于某种原因,它在Y上重复。我不能使用overflow:hidden;

<style>
body{background-image:url('<?php echo $ActualPath; ?>images/backgroundimage.jpg'); background-image:no-repeat;}

</style>

I want the background-image no-repeat on x and y.

我想要 x 和 y 上的背景图像不重复。

回答by lucideer

The syntax you should use is

您应该使用的语法是

background-image: url(path/images/backgroundimage.jpg);
background-repeat: no-repeat;

.. or alternatively

.. 或者

background: url(path/images/backgroundimage.jpg) no-repeat;

if you prefer the short-hand syntax.

如果您更喜欢简写语法

background-imagealways just defines an image file, so in your example, the second background-imagerule is attempting to override the first one, but since "no-repeat" isn't a valid image file the browser just ignores it.

background-image总是只定义一个图像文件,所以在你的例子中,第二个background-image规则试图覆盖第一个,但由于“无重复”不是一个有效的图像文件,浏览器只是忽略它。

The various background properties are listed herefor reference.

此处列出各种背景属性以供参考。

回答by sachleen

The backgroundproperty has a few properties you can change.

background属性有一些您可以更改的属性。

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
  • 背景颜色
  • 背景图片
  • 背景重复
  • 背景附件
  • 背景位置

You can set each one individually, like what you're trying to do. If you set the same one twice, only the last one will take effect.

你可以单独设置每一个,就像你想要做的那样。如果两次设置相同的,只有最后一个才会生效。

You're setting background-imagetwice where the second one should be background-repeat.

您在background-image第二个应该设置的位置设置了两次background-repeat

There is also a shorthand notation where you do something like

还有一个速记符号,您可以在其中执行类似的操作

background:#ffffff url('img_tree.png') no-repeat right top;

to set multiple properties in one line. You could use that to change your code to

在一行中设置多个属性。你可以用它来改变你的代码

body{ background: url('<?php echo $ActualPath; ?>images/backgroundimage.jpg') no-repeat; }

回答by ama2

you can use background-repeat:no-repeat;

您可以使用 background-repeat:no-repeat;

回答by S.Nirmala Josphine

For getting no repeat of background in html use this syntax: CSS(Internal stylesheet) use this code in style tag in head part

为了在 html 中不重复背景,请使用以下语法:CSS(内部样式表)在头部的样式标记中使用此代码

background-image:url("some picture url");
background-repeat:no repeat;

-It will provide background image of single view without repeatation.

- 它将提供单一视图的背景图像而无需重复。