Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1222532

    Hi,
    I’m trying to create submenus as you can see on the screenshot in private content. This submenu is for PREMIER ÂGE – ÉVEIL section and I gonna fill it with a background image.
    I would like to create all my submenus exactly the same way, so the would be superimposed (all at the same place).
    The problem is I can’t find any solution to center them. I found some bad solutions like add something like left: -XX% or left: -XXpx on each submenu but this is not a solution because like this, the position depends on screen size…
    What is the way to simply center a submenu on all screens?
    If needed, you can find a link and credentials to my website in private content.
    Thanks a lot!

    #1223734

    Hi guys,
    Any help on this?
    Thanks a lot! :-)

    #1224034

    Hi,

    I added following code to bottom of Quick CSS field

    
    .main_menu .menu li#menu-item-2120 ul { 
    transform: translate(-18%);
    }
    .main_menu .menu li#menu-item-2127 ul {
        transform: translate(-23%);
    }
    .main_menu .menu li#menu-item-2098 ul { 
    transform: translate(-21%);
    }

    Please review your website :)

    Best regards,
    Yigit

    #1224178

    Hi Yigit,
    Thanks for your reply.
    It works for some page widths, but not for others.
    For example, if the page is 1080px, submenus are not at the same place.
    I already tried to do this by setting position by codes like left: -XX% or left: -XXpx but the same problem appears.
    Isn’t there any code to center the submenu and not move it?
    Thanks a lot!

    #1225437

    Hi,

    The sub menu looks exactly like the screenshot now, so we are not really sure which element you’re trying to center here.

    You should be able to center align an element relative to the parent container using the transform property.

    
    .parent{
      position: relative;
    }
    .child{
      position: relative;
      left: 50%;
      transform: translateY(-50%);
    }

    Best regards,
    Ismael

    #1225874

    Hi Ismael,

    Thanks for your reply.
    I think I am confused in my words, so I made a video screenshot of what I’m talking about. You could find it in private content.
    As you can see, submenus are nearly centered on some screen widths, but not on others and this is of course not what I want.

    I’m looking for a solution to make submenus same width (this is solved) and ALWAYS centered in the middle of the screen, so this way they will all be at the exact same place.

    I tried your previous code with something like:

    .responsive {
      position: relative;
    }
    #menu-item-2089 {
      position: relative;
      left: 50%;
      transform: translateY(-50%);
    }

    just to see if #menu-item-2089 element would be centered, but it is not.

    What I need seems to be so easy, but I’m completely lost on this! :-(

    #1226349

    Hi,

    You can use following code to adjust their position on smaller screens

    @media only screen and (max-width: 1080px) {
    .main_menu .menu li#menu-item-2120 ul { 
    transform: translate(-18%);
    }
    .main_menu .menu li#menu-item-2127 ul {
        transform: translate(-23%);
    }
    .main_menu .menu li#menu-item-2098 ul { 
    transform: translate(-21%);
    }}

    Best regards,
    Yigit

    #1227355

    Hi Yigit,
    Thanks for your reply.
    I’m sorry but I really don’t want to use codes to align my submenus approximately and to make them not really centered on some screen widths…
    Does a code exist to really center this kind of elements?
    Thanks a lot!

    #1229756

    Hi,
    Sorry for the late reply, unfortunately, this is not possible. Each sub-menu is a child of a main menu item and it’s left edge is position zero for that tree of elements, but that position is different for each menu item. When you center the sub-menu it is within its tree, not the page, to place all of the sub-menus in the same location the calculations will need to be done on the screen size instead of the parent location.
    I hope I have explained this well, from your video it looks like you are using a laptop sized screen, on my desktop the sub-menus move much more, so perhaps they looked like they are very close to being superimposed.
    I tried to write a script to move the sub-menus based on the screen size in order to find a fixed location, and while it works for the most part, its limitations are that after the sub-menus are moved its hard to move your mouse from the main menu into the sub-menu without losing focus on a desktop, and it’s based on screen size.

    I’ll post the script here, perhaps it can be used for something else.

    function bad_custom_script(){
      ?>
      <script>
    (function($){
      $(document).ready(function() {
    jQuery.fn.center = function () {
        this.css("position","fixed");
        this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 3) + 
                                                    $(window).scrollTop()) + "px");
        this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 6) + 
                                                    $(window).scrollLeft()) + "px");
        return this;
    }
    $('.menu-item-top-level.dropdown_ul_available ul.sub-menu').center();
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'bad_custom_script');

    I tried to think of some other ways such as if the sub-menus were actually a moral, or lightbox, but I think you would have the same issues with the mouse unless it was triggered by click instead of hover.
    Sorry, but I believe the best solution is @Yigit’s css.

    @media only screen and (max-width: 1080px) {
    .main_menu .menu li#menu-item-2120 ul { 
    left: -520px;
    }
    .main_menu .menu li#menu-item-2127 ul {
        transform: translate(13%);
    }
    .main_menu .menu li#menu-item-2098 ul { 
    transform: translate(-21%);
    }}

    Best regards,
    Mike

    #1229762

    Hi Mike,
    Thanks a lot for your work!
    From what you tell me here, it seems to be difficult to code this properly and the result will not be perfect.
    So I think I gonna give up this idea and keep a more classic menu.
    Anyway, Yigit, Mike, thank you so much for your work guys!!
    Best regards ;-)

    #1229766

    Hi,
    We are happy to help, we will close this now. Thank you for using Enfold.

    For your information, you can take a look at Enfold documentation here
    For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)

    Best regards,
    Mike

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Centered submenus’ is closed to new replies.