我为我创建的wordpress网站创建了一个视差滚动效果。使用了以下html和css:
HTML
<div class="container-above"></div>
<!-- Parallax Container element -->
<div class="parallax"></div>
<div class="container-below"></div>
css
.parallax {
/* The image used */
background-image: url("https://mywebsite.com/wp-content/uploads/2017/12/image.png");
/* Set a specific height */
height: 500px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
我进入页面,图像没有出现。我去“检查”,得到以下错误:
(索引):1混合内容:页面位于'https://mywebsite.com/'已通过HTTPS加载,但请求了不安全的映像'http://localhost/wpthemes/wordpress/wp-content/uploads/2017/12/image.png“。此内容也应通过HTTPS提供。img。png加载资源失败:net::ERR_连接被拒绝
这基本上意味着由于图像不在https url下,chrome不会显示它,因为技术上它不安全。这没有多大意义,因为我使用的图片网址是从wordpress网站的媒体库中提取的https。
所以我转到“查看页面源”,果然,在style.css文件中,它正在拉localhost链接“http://localhost/wpthemes/wordpress/wp-content/uploads/2017/12/image.png”,而不是wordpress图像链接。
所以我回到FTP中的style.css,但是css仍然是一样的:
.parallax {
/* The image used */
background-image: url("https://mywebsite.com/wp-content/uploads/2017/12/image.png");
/* Set a specific height */
height: 500px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
有人能解释一下吗?起初我认为这是缓存问题,但我在chrome中以匿名模式加载了该站点,得到了相同的效果和错误。
我觉得我需要用wordpress做一些事情,也许是将图像插入html而不是css,但我还没有遇到任何具体的东西。
提前感谢您的帮助。
为此,您可以使用PHP函数get\u stylesheet\u directory\u uri()
来帮助您设置相对路径。
get_stylesheet_directory_uri():检索当前主题/子主题的样式表目录uri。检查SSL。
把这个PHP放在你的超文本标记语言
中:
<?php echo get_stylesheet_directory_uri(); ?>
它将回响您当前的样式表目录
。
然后比较图像路径
和样式表路径
,并执行如下操作:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/aternus.png" alt="" width="" height="" />
或者,在找到sylesheet path
后,您可以像这样为CSS
中的图像
编写一个相对路径
:
background-image: url('./../uploads/2017/12/image.png');
// explanation: /. means current folder, ../ means one folder back (up)
@logos_164
如果您最近将此站点从本地开发人员移动到活动站点,我建议您在“设置”下签入您的wp管理员
(有时人们会导出他们本地的dev sql wordpress数据库,忘记在网站url上做一个查找/替换,最终所有的设置都localhost或*. dev)
如果这两个地址都不localhost,那就不是问题了。虽然我会做一个sql导出和搜索文件的任何引用localhost以防万一有一个设置/字段,仍然与localhost相关。
如果您最近确实将其从本地开发人员移动到了活动站点,我也会重新进行永久链接设置以重置。htaccess文件。
最后一种方法可能是通过ftp将图像上载到宿主环境中的文件夹中,并在样式中引用该位置。css而不是使用wordpress媒体上载文件夹。