Panneau N0C 04 EN 250 250
Get 15% discount on our partner PlanetHoster with the code PHA-ceikay

Is there a CSS conflict in generated template?

More
5 years 9 months ago - 5 years 9 months ago #59646 by easistudio
I have seem to an issue with the template I created in TemplateCreatorCK as the complete page appears to shift across around 10px on certain pages.

Easiest way to explain is to give you 3 links
1. testing.cricketpages.co.uk/
2. testing.cricketpages.co.uk/directory
3. testing.cricketpages.co.uk/directory/batmakers

Firstly click link 1 and then put link 2 into the browser address and you will see something is making the page move around 10px to the right. However the weird thing is that if you then go to link 3, the page reverts back to link 1 position but links 2 and 3 are both generated using the same Joomla extension.

Same happens in both Chrome and Firefox but oddly not in Firefox when using the source code inspector (after opening inspect element).
Last edit: 5 years 9 months ago by easistudio.

Please Log in or Create an account to join the conversation.

More
5 years 9 months ago - 5 years 9 months ago #59647 by easistudio
Found the problem and it turned out to be nothing to do with a CSS conflict but something actually very basic.

The issue was that the right scrollbar was not appearing on pages with little or no content and this was causing these pages to shift to the right. The movement was not 10px but apparently 17px (the width of the scrollbar) and someone (not connected to this website) provided me with a quick JavaScript solution for my particular website.

This was his original solution which I stuck in the <head> section of custom code.
Code:
<script> window.addEventListener('load', function() { var directory = $('.contentheading').text(); if (directory == 'Directory'){ $('body').css('margin-left','-17px') } }) </script>

The above code relies on the page with no right scrollbar being called Directory so he provided the below solution that will detect any page without a scrollbar and effectively do the same as first solution.
Code:
<script> window.addEventListener('load', function() { const outer = document.createElement('div'); outer.style.visibility = 'hidden'; outer.style.overflow = 'scroll'; outer.style.msOverflowStyle = 'scrollbar'; document.body.appendChild(outer); const inner = document.createElement('div'); outer.appendChild(inner); const scrollbarWidth = (outer.offsetWidth - inner.offsetWidth); outer.parentNode.removeChild(outer); console.log(scrollbarWidth) var content = document.documentElement.scrollHeight; var view = document.documentElement.clientHeight; console.log(content,view) if(content == view || content < view){ console.log('make new margin') document.getElementsByTagName('body')[0].style = 'margin-left: -' + scrollbarWidth + 'px'; } }); </script>

I offer no guarantees with the code above but happy for Cedric to test it out and incorporate into TemplateCreator templates by default.
Last edit: 5 years 9 months ago by easistudio.

Please Log in or Create an account to join the conversation.

More
5 years 9 months ago #59653 by ced1870
Hi
this is easy to fix with CSS, to add in the custom css :
Code:
body { min-height: 101vh; }

it will create a scrollbar anyway, so there is no difference even if the content is smaller
CEd

Joomlack Webmaster and Developer

Please Log in or Create an account to join the conversation.

Time to create page: 0.182 seconds

Fast and powerful creation, customizable and responsive.

Read More

We have 1091 guests and one member online