我在我的cakephp网站的默认布局中添加了一个图像作为按钮。 但是某些视图没有加载图像。
<input type="image" class="search_button" src="img/search.png" style="background-color: #066; margin-left: 5px; margin-top: -5px; vertical-align: middle" />
图片位于webroot,img文件夹
答案 0 :(得分:0)
您遇到的问题是用于访问图像的网址是相对于当前网址的
表示当前页面是否为:
http://example.com
从
请求图像http://example.com/img/search.png
我们假设上面的图像存在。如果当前页面是:
http://example.com/some/text
从
请求图像http://example.com/some/text/img/search.png
不存在。
适当的行动是使用绝对网址
<input type="image" class="search_button" src="/img/search.png"
^
或使用适当的帮助方法生成标记。但是在这种情况下 - 最好使用css:
// file in webroot/css/foo.css
.search_button {
background-image:url('../img/search.png');
}