2014-12-28 138 views
2

我做了一个独特的类的div元素,然后我给这个类一个背景图像,但它不显示。即使我检查元素一切都在那里,除了关于背景图像的一行。背景不显示在div

我的代码:

.godzillahatter{ 
background-image: url ("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 
background-repeat: no-repeat; 
background-attachment: fixed; 
background-position: center; } 

检查元素:

.godzillahatter { 
background-repeat: no-repeat; 
background-attachment: fixed; 
background-position: center center; 
} 

和URL: http://honlapkell.hu/verzio1/godzilla/

我不知道是什么问题。 div元素有内容,但我试图给它的高度和宽度只是肯定的。我寻找解决方案,但没有一个可行。

回答

4

欢迎SO!

更改此

background-image: url ("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

这个

background-image: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

没有空间url(之间

友好的忠告: 每当你看到一个黄色三角形这样在Chrome的检查,它通常意味着你的CSS语法是错误的。 enter image description here

+1

如果出现错误,我使用不显示黄色三角形的firefox。这是一个非常有用的信息,你让我的生活变得更轻松。非常感谢你! –

1

网址后删除多余的空间

background-image: url ("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

应该

background-image: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 
+1

谁downvoted ?答案是非常正确的,并且是第一个回答。 –

1

删除网址和支架之间的空间:

background-image: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 
2

测试和认证!

使用background属性,并删除url后的空间。

background: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

输出:

enter image description here

编辑:正如其他人所指出的,它会工作,如果你只是url后删除空间。

+0

有没有*“也”*,空间不能在那里:) –

+0

@ RokoC.Buljan你让我。 :) –

0

background-image的URL最好是不带引号,也如果使用外部电源,使用双斜线//,而不是http://

对于不太CSS代码结合的背景属性为一行:

.godzillahatter 
{ 
background: url(//honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg) no-repeat center center fixed; 
} 
+0

Downvote?请指出我的错误 – lolbas

+0

不是DV,但引号非常好,在'file://'环境中也会失败(尽管在localhost/server上很好,让浏览器获得正确的协议)。 –

+0

@DominatorX我们正在谈论css。 '//'不是那里的注释语法 – lolbas