admin管理员组文章数量:1122846
I simply can't find the correct way or working way to do this. I've made an alternative header and added an option with redux theme option to have the alternative header. I've also made a custom-css.php where i can enter some files which are output in header. This should override any css from style.css
the thing i need is really simple but whatever way i have used, it doesn't work
an example
.header-fixed { background: transparent url(assets/images/mix1.png) repeat-x; }
With this option it doesn't work and the image with chrome inspector doesn't exist. If i add a full path like
background: transparent url(wp-content/themes/theme-name/assets/images/mix1.png) repeat-x !important;
then it works, why, i am not sure. But i don't believe this is a right call.
Other examples
background: url( ."/assets/images/mix1.png";) repeat-x !important;
background: url( " ."/assets/images/mix1.png"; ") repeat-x !important;
3.background: url( " /assets/images/mix1.png) repeat-x !important;
4.background-image:url(."/assets/images/mix1.png"); background-repeat:repeat-x;
- background-image:url(/assets/images/mix1.png); background-repeat:repeat-x;
And there were many more. So any tips pls
I simply can't find the correct way or working way to do this. I've made an alternative header and added an option with redux theme option to have the alternative header. I've also made a custom-css.php where i can enter some files which are output in header. This should override any css from style.css
the thing i need is really simple but whatever way i have used, it doesn't work
an example
.header-fixed { background: transparent url(assets/images/mix1.png) repeat-x; }
With this option it doesn't work and the image with chrome inspector doesn't exist. If i add a full path like
background: transparent url(wp-content/themes/theme-name/assets/images/mix1.png) repeat-x !important;
then it works, why, i am not sure. But i don't believe this is a right call.
Other examples
background: url( ."/assets/images/mix1.png";) repeat-x !important;
background: url( " ."/assets/images/mix1.png"; ") repeat-x !important;
3.background: url( " /assets/images/mix1.png) repeat-x !important;
4.background-image:url(."/assets/images/mix1.png"); background-repeat:repeat-x;
- background-image:url(/assets/images/mix1.png); background-repeat:repeat-x;
And there were many more. So any tips pls
Share Improve this question asked Oct 3, 2015 at 2:32 MaxMax 1294 silver badges14 bronze badges1 Answer
Reset to default 0UPDATE: Added a third example to show you how to output the path inside a PHP string, per the source code you provided in the comments.
There's nothing wrong with having a full path in your CSS but you want to make sure the path is being dynamically generated by WordPress for the most consistent results.
In this case the get_template_directory_uri() and/or get_stylesheet_directory_uri() helpers will be handy. The one you use depends on whether you are building in a standard theme vs. a parent theme with support for child themes. You can read more about the differences here: https://codex.wordpress.org/Function_Reference/get_template_directory_uri
On with the code, based on the example which you claim to be working as expected:
// standard theme / parent theme asset example
background: transparent url(<?php echo get_template_directory_uri(); ?>/assets/images/mix1.png) repeat-x !important;
// child theme asset example
background: transparent url(<?php echo get_stylesheet_directory_uri(); ?>/assets/images/mix1.png) repeat-x !important;
In your specific case, try this:
// specific example from your source file (line 23)
.header-fixed { background: transparent url(' . get_template_directory_uri() . '/assets/images/mix1.png) repeat-x !important; }
本文标签: cssBackground image call problem
版权声明:本文标题:css - Background image call problem 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287009a1927788.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论