Jump to content
opalepatrick

[Solved] CSP & inline styles

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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>

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...