Embedded CSS in a page.

jleonard99
Community Explorer

Using the canvas API I found that I can embed <style></style> blocks of CSS in the wiki_page[body].  for example:

<style>
  .fp-body-columnx{
    width:280px;
    word-wrap:break-word;
}
  .fp-body-container{
    display:flex;
    flex-wrap:no-wrap;
    justify-content: center;
  }
  @media (max-width:900px) {  // these don't work in Canvas!
  .fp-header-span-second {
    display: none;
  }
  }
</style>
<h2> and starts the page ...</h2>
<div class="fp-body-container">
<div class="fp-body-columnx">
</div>
</div>



While Canvas (through the API) is permitting the <style></style> blocks into the wikibody, for some reason it's decided to filter the @media attribute.  Note - if I open these pages in the Canvas page editor, all the style code disappear.  This is an API-only feature.

My app is autogenerating a responsive frontpage using module-items.  For narrow screens I'd like some of the data to disappear and others to be reformatted, depending on the display width of the browser.

Any suggestions for getting the @media tag to work?  I thought that perhaps the "@" was causing the problem, but I can insert a "@@" and the media tag shows.

Below is an example of one the autogenerated frontpages.  It reads module and module-item data from the current week and formats it into responsive columns.  As the screen size changes, the page reformats itself.  

This works great, except when the screen gets really narrow and one needs to change flex-box strategies.  I'd like to use the "@media" CSS code to change some of the CSS attributes depending on current screen size.

Thoughts?

2024-02-04_15-51-17.png

Labels (1)