opalepatrick Posted October 10, 2019 Share Posted October 10, 2019 I have pages with a masthead image that is loaded to a background using inline styles. They are dynamic depending on the page. The problem is that with CSP I can't use inline styles, therefore I lose the ability to load the background image dynamically as we can't use php in the css file where you would normally move the inline style to. I am checking flexbox at the moment, and have looked at a div with the image covering the whole visible area on a different z-index level, but that is ugly and doesn't work consistently... The reason that I need it as a background is because I have content (text) over. Any ideas appreciated. Link to comment Share on other sites More sharing options...
wbmnfktr Posted October 10, 2019 Share Posted October 10, 2019 What about this: <div class="masthead" data-bg="<?php echo $page->mastheadImage->url; ?>"> <span>My Text Above Image</span> </div> and this: <script> $(document).ready(function() { $('[data-bg]').each(function() { $(this).css('background-image', 'url(' + $(this).attr('data-bg') + ')'); }); }); </script> 2 Link to comment Share on other sites More sharing options...
opalepatrick Posted October 10, 2019 Author Share Posted October 10, 2019 Thank you very much @wbmnfktr - that worked perfectly and complies with CSP as well. 1 Link to comment Share on other sites More sharing options...
dragan Posted October 10, 2019 Share Posted October 10, 2019 CSP? Content Security Policy? o_O Link to comment Share on other sites More sharing options...
opalepatrick Posted October 10, 2019 Author Share Posted October 10, 2019 Yes, sorry :-) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now