How to edit styles inside Kentico 12SP MVC page builder?

Jeremy Gouveia asked on February 4, 2021 22:03

Hi, I have a site running Kentico 12SP MVC. For reasons, I won't get into, my Header and Footer have a z-index in the millions. Unfortunately, the z-index is so high that it blocks the pagebuilder features in Kentico. How can I add CSS/JS to detect whether I am inside the page builder and adjust the z-index accordingly?

Correct Answer

Jeremy Gouveia answered on February 5, 2021 02:00

Ok I did it, it had nothing to do with caching. I was unable to get the suggested solution to work. I suspect it has to do with the nature of iframes.

That said, I found a working solution. In the MVC application, you can access the boolean property HttpContext.Current.Kentico().Preview().Enabled; to determine whether the page is being rendered via pagebuilder.

Solution: In PageTemplateLayout.cshtml

@using Kentico.Content.Web.Mvc
...
...
@{
   ...
   bool PreviewMode = HttpConteext.Current.Kentico().Preview().Enabled;
}
...
...
<header class="other-classes @(PreviewMode ? "page-builder" : string.Empty)">
    ...
</header>
...
<!-- body -->
...
<footer class="other-classes @(PreviewMode ? "page-builder" : string.Empty)">
    ...
</footer>

then in your scss (assuming you're setting constants in a _variables.scss file)

header,footer { 
    &.page-builder { 
        z-index: $your-z-value 
    }
}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on February 4, 2021 22:19

Typically your styles are defined in the SCSS/LESS stylesheets in the MVC project. See the structure of this particular project. So you'll have to go back to your stylesheets in the project and make adjustments there, then publish that code change.

Image Text

0 votesVote for this answer Mark as a Correct answer

Jeremy Gouveia answered on February 4, 2021 22:31

Hi thank your for your prompt reply, I am referring to the modifying these styles when you're in page builder mode via the Kentico CMS. As I mentioned, my nav header has a z-index that surpasses the Kentico Widget PageBuilder. I need to alter the nav header's z-index when the page is loaded via the CMS.

How can I modify the CSS only when the site is loaded via CMS? How would I check if the page is being loaded via the page builder page tab via MVC code?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 4, 2021 22:40

Thanks for the more clear definition of what you're looking for. To find out what is overriding your site's CSS do the following:

  1. Go to the page in question in Xperience on the Page tab.
  2. Right-click on the area in question and inspect that.
  3. Determine what class is overriding the z-index. This element is nested within an i-frame and most likely has a parent/grantparent element with the class of page-builder.
  4. In your MVC css, add an override for something like .page-builder .your-class .thats-causing .problems { z-index: 0; }

What this will do is when you're on the Page tab using page builder functionality, it will force that z-index to be lower so page builder items are displayed/work.

0 votesVote for this answer Mark as a Correct answer

Jeremy Gouveia answered on February 4, 2021 22:56

Thank you for your suggestion. I tried your approach but even something as simple as:

.page-builder { display: none; }

Yielded no changes to the CSS inside the page tab. Could this have something to do with the fact that the page is loaded via iFrames?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 4, 2021 23:02 (last edited on February 4, 2021 23:02)

Caching is very heavy in Xperience, so I'd suggest going to a private browser window and trying the same thing again. Also, simply try making your edits directly in the Inspection editor and that will help you find what specific css selector you need.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.