In Drupal framework with the complex and extremely complicated design theme Olivero I have an element, the website’s sidebar wrapper, which contains two sidebar regions.
Often in mobile displays (under 1000px), this wrapper will just stick/juxtapose to the right of its parent element due to some grid behavior which I don’t intent to try to backward-engineer, but just hack if I can.
This didn’t centralize it this wrapper
margin: 0 auto 0 !important;
Giving to its parent element this didn’t centralize it:
display:flex !important;
justify-content: center !important;
Giving to its parent element this didn’t centralize it:
display: grid !important;
justify-content: center !important;
Is there a more “brutal” command to force the element to appear centralized in mobile displays (under 1000px) no matter what flex or grid directives it got?
Something with position and position offsets perhaps?
Rather than taking just about every tool off the table, why not investigate what is going on with the parent that might be preventing the element from being centered? I suspect that there is something going on there that might be a simple fix. Is there room in the parent? Is the parent having some pretty specific and harsh CSS rules being applied to it?
Like @Martyr2 says, rather than brute force it, figure out which style is being applied to the element, and see if you can mitigate it from there.
Right click on the abhorrent element, and inspect the element to bring up the developers tools. You can either scroll through the styles tab there and see how each style is applied, or use the compute tab which shows ALL of the applied styles in one space. You can use the arrows to drop down and see which line of which css file is being applied.
Both main parent elements of this wrapper are <div id="#main"> AND div class="sidebar-grid grid-full".
When I inspect both, I mostly find grid and flex directives which I just wont to battle in this complicated design theme Olivero.
Please, in your free time, check the problem in-vitro in this page and suggest a good approach to centralize the wrapper of the two sidebars.
Your grid is split into 11 columns. In this selector, you’re telling it to start in column 1, which is the far right column since its a RTL site, then it ends in column 9. This leaves two columns of space on the left.
You could try grid-column 2/10 but I’m not even sure you need grid for .region-content. Seems like overkill since you’re essentially working as one column.
That targets the wrong element… The class name would have needed to be on the parent element or indeed higher up the tree and the style order reversed.
Assuming you leave that new class in place you could use the :has selector instead and do this:
If I don’t want to change the Drupal markup more than I already did (wrapping the two sidebars in <div class="two_new_sidebars_based_on_original_one">) is there any hack left in that situation?
It can also be a JavaScript illusion of some sort (I don’t know almost anything about graphical tweaks with JavaScript).
That’s seemingly fantastic for me (the web browser support issue is minor for me in that case).
So please let me get straight what this actually does.
Pseudocode:
SELECT ANY ELEMENT WITH THE CLASS grid-full
IF IT **HAS** AT LEAST ONE CHILD ELEMENT WITH THE CLASS two_new_sidebars_based_on_original_one
THEN GIVE ANY SUCH CHILD ELEMENT THE FOLLOWING **EXCEPTIONAL** CSS DIRECTIVES