CMS Development

jakeleong
Member

How to add the social icons inside the hamburger icon

SOLVE

Can you please advise how to add the social icons inside the hamburger icon when in mobile view (refer to pic1, pic2 & pic3). Just shrink your browser tab or view it in your mobile devices and you will be able to replicate this problem. Kindly assist on this, thanks.

pic1.JPGpic2.pngpic3.JPG

0 Upvotes
1 Accepted solution
Chris-M
Solution
Top Contributor

How to add the social icons inside the hamburger icon

SOLVE

Hi @jakeleong,

 

let me try again... different route 😄

 

This time with JS / jQuery, if you put some nice classes around, the code will look much better, but this works:

function socialPosition() {
  // if window width is smaller 991px
  if ($(window).width() < 991) {
     // take everything of this class '.social-links' and put it on the bottom of '#hs_menu_wrapper_module_1591238150661200_.active-branch' (that's your mobile menu)
     $('.social-links').appendTo('#hs_menu_wrapper_module_1591238150661200_.active-branch');
  }
  // if window width is biger 992px
  if ($(window).width() > 992) {
     // take everything of this class '.social-links' and put it back on the bottom of '#hs_cos_wrapper_module_1591238296584315.hs_cos_wrapper.hs_cos_wrapper_widget.hs_cos_wrapper_type_module' (your initial social container)
     $('.social-links').appendTo('#hs_cos_wrapper_module_1591238296584315.hs_cos_wrapper.hs_cos_wrapper_widget.hs_cos_wrapper_type_module');
  }
}
// Do it on the initial Page load (only if below 991px)
$(window).ready(function() {
  socialPosition(); 
});
// Do it if the user resize the window (only if below 991px)
$(window).resize(function() {
  socialPosition();
});

 

You have :

.social-links--right

on the width of 991px, this will not show any icons on your mobile menu, please cancel the text-align:right; and make it to a text-align:left;

@media (max-width: 991px) {
.social-links--right {
text-align: left;
}

 

 

In your css, there is a media query with the following: 

@media (max-width: 767px)
.hs-menu-wrapper, .hs-menu-wrapper  {
    webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    display: block;
    width: 100%;
}

This will make your buttons in single rows and very big, you need to cancel to the width and maybe a display: inline; for a single row of socials

 

- Chris

View solution in original post

6 Replies 6
Chris-M
Top Contributor

How to add the social icons inside the hamburger icon

SOLVE

Hi @jakeleong,

 

the easiest way is, if you remove/hide the socials (desktop) and show them again on the mobile navigation with CSS. 

- HTML => Add the socials (HTML) to the Mobile Nav (give it a special class, like "socialsMobile".

Put a new class to the desktop socials, or a div around it (if possible).

 

- CSS => Hide the desktop socials and show the mobile socials on <992px. Show the desktop socials and hide the mobile socials on >992px

.socialMobile {
display: none
}
@media (max-width: 991px) {
.socialMobile {
display: block;
}
}

@media
(min-width: 992px) {
.socialsDesktop {
display: none;
}
}

 This should do the trick, i hope this suites you.

- Chris

jakeleong
Member

How to add the social icons inside the hamburger icon

SOLVE

Hi @Chris-M ,

 

Thanks for the help and I have tried to add the codes that you provided earlier on but is still not working. And my goal is to add the social icons into the hamburger icon and not hiding the social icons in mobile view.

 

- Jake

0 Upvotes
Chris-M
Top Contributor

How to add the social icons inside the hamburger icon

SOLVE

Hi @jakeleong,

I made a small mistake on the media query, my bad. I fixed it below.

 

You are going to have 2 socials "bars" one on your website for the desktop view and one for the mobile view inside of your hamburger menu. Add some css classes of your choice, the classes in my code are just examples.

 

 

First you need to place another HTML with socials inside the hamburger menu on your desired place.

Now you should have 2 social bars (one inside the hamburger and one the page) .

The trick is, you are hidding the "mobile" social bar on default.

.socialMobile {
  display: none;
}

We are only showing the mobile social bar on screens smaller 991px this is when your hamburger starts

@media (max-width: 991px) {
.socialMobile {
display: block;
}
}

While we are showing the mobile social bar, you don't want to show the desktop social bar, so we are hidding it on screens smaller 991px

@media (max-width: 991px) {
.socialsDesktop {
display: none;
}
}

Now we are hidding the desktop socials on smaller (<991) screens and showing the mobile socials inside the hamburger menu. If we get bigger than the small screen the mobile gets the display: none; which hides it and the desktop bar will gets the initial display: block; back

 

Full code (bit shorter):

.socialMobile {
display: none;
}
@media (max-width: 991px) {
.socialMobile {
display: block;
}
.socialsDesktop { display: none; } }

 

I hope you can get my thoughts now 🙂

 

- Chris

jakeleong
Member

How to add the social icons inside the hamburger icon

SOLVE

Hi @Chris-M,

 

Thanks for the quick reply. The problem is I can't locate the place to add the social icons in the hamburger menu. From my understanding on your suggestion, you tried to add 2 social icons (socialmobile and socialdesktop) at the header and display them according to the screen size but from what I see they are still not inside the hamburger menu.

 

Currently what I did is to add the social icons module beside the header module and did some changes to the CSS so that they are aligned in desktop view but because they are still in different HTML div which is the cause of the icons not added inside the hamburger tab.

pic4.png

 

How to combine these two modules into one single module or where to locate the place to add the social icons inside the hamburger menu when in mobile view?

 

Here are the codes for my social icons module.

 

module.html

{% set networkData = [
  {
    "name": "facebook",
    "iconName": "facebook-f",
    "supportingText": "Facebook",
   "networkColor": "#3b5998"
  },
  {
    "name": "twitter",
    "iconName": "twitter",
    "supportingText": "Twitter",
    "networkColor": "#55acee"
  },
  {
    "name": "instagram",
    "iconName": "instagram",
    "supportingText": "Instagram",
    "networkColor": "#c32aa3"
  },
  {
    "name": "linkedin",
    "iconName": "linkedin-in",
    "supportingText": "LinkedIn",
    "networkColor": "#0077b5"
  },
  {
    "name": "youtube",
    "iconName": "youtube",
    "supportingText": "YouTube",
    "networkColor": "#ff0000"
  },
  {
    "name": "pinterest",
    "iconName": "pinterest-p",
    "supportingText": "Pinterest",
    "networkColor": "#bd081c"
  },
  {
    "name": "mail",
    "iconName": "envelope",
    "supportingText": "Email",
    "networkColor": "#00a4bd"
  },
  {
    "name": "website",
    "iconName": "link",
    "supportingText": "Website",
    "networkColor": "#2096f3"
  },
  {
    "name": "whatsapp",
    "iconName": "whatsapp",
    "supportingText": "Whatsapp",
    "networkColor": "#25d366"
  }
] %}

<div class="social-links social-links--{{ module.alignment }} social-links--{{ module.color_scheme }}">
 {% for network in module.social %}
    {% set networkInfo = networkData|selectattr('name', 'equalto', network.network)|first %}
    {% set href = network.link.url.type == "EMAIL_ADDRESS" ? "mailto:" ~ network.link.url.href : network.link.url.href %}

    <a href="{{ href }}" id="social-links__icon_{{ module.id }}" class="social-links__icon"
       style="padding-left: {{ module.spacing }}px; padding-right: {{ module.spacing }}px;"
       {% if network.link.open_in_new_tab %}target="_blank"{% endif %}
       {% if network.link.no_follow %}rel="nofollow"{% endif %}
       >
      {% if module.display != "text_only" %}
        {% if network.network == "icon" %}
          <img src="{{ network.network_image.src }}" style="height: {{ module.scale }}px";>
        {% else %}
          <span class="social-links__icon-wrapper social-links__icon-wrapper--{{ module.icon_shape }} social-links__icon-wrapper--{{ module.color_scheme }}"
                style="color: {{ networkInfo.networkColor if (module.icon_shape == "original") && (module.color_scheme == "color") }};
                       {% if ((module.icon_shape == "square") && (module.color_scheme == "color")) || ((module.icon_shape == "circle") && (module.color_scheme == "color")) %}background-color: {{ networkInfo.networkColor }};{% endif %}
                       height: {{ module.scale }}px; width: {{ module.scale }}px;">
            {% icon name="{{ networkInfo.iconName }}", style="solid", no_wrapper=True %}
          </span>
        {% endif %}
      {% endif %}
      {% if (module.display == "icon_text") or (module.display == "text_only") %}
        {{ network.supporting_text || networkInfo.supportingText }}
      {% endif %}
    </a>
  {% endfor %}
</div>


{% if (module.display == "icon_text") or (module.display == "text_only") %}
<style>
  #social-links__icon_{{ module.id }} {
    font-family:{{ module.font_style.font }};
    font-size: {{ module.font_style.size.value }}{{ module.font_style.size.units }};
    color: {{ module.font_style.color }};
    font-weight: {{ module.font_style.styles.bold ? 'bold' : 'normal' }};
    font-style: {{ module.font_style.styles.italic ? 'italic' : 'normal' }};
    text-decoration: {{ module.font_style.styles.underline ? 'underline' : 'none' }};"
  }
</style>
{% endif %}
  

module.css

.social-links--center {
  text-align: center;
}
.social-links--right {
  text-align: right;
}
.social-links__icon {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.social-links__icon-wrapper {
  display: inline-block;
  position: relative;
  width: 40px;
  height: 40px;
  margin: 0 5px;
  color: #fff;
}
.social-links__icon-wrapper:hover {
}
.social-links__icon-wrapper--circle {
  border-radius: 50%;
}
.social-links__icon-wrapper--grey {
  background-color: #666;
}
.social-links__icon-wrapper--black {
  background-color: #000;
}
.social-links__icon-wrapper--original {
  background-color: transparent;
}
.social-links__icon-wrapper--original.social-links__icon-wrapper--black {
  color: #000;
}
.social-links__icon-wrapper--original.social-links__icon-wrapper--white {
  color: #fff;
}
.social-links__icon-wrapper--original.social-links__icon-wrapper--grey {
  color: #666;
}
.social-links__icon-wrapper--circle.social-links__icon-wrapper--white,
.social-links__icon-wrapper--square.social-links__icon-wrapper--white {
  color: #000;
  background-color: #fff;
}
.social-links__icon-wrapper svg {
  fill: currentColor;
  height: 60%;
  width: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.sticky .span4:last-child {
    margin-top: 20px !important;
}

@media screen and (min-width:992px) {
    .custom-menu-primary .hs-menu-wrapper,
    .custom-menu-primary .hs-menu-wrapper > ul ul { 
        display:block !important;
    }


 

 

 

0 Upvotes
Chris-M
Solution
Top Contributor

How to add the social icons inside the hamburger icon

SOLVE

Hi @jakeleong,

 

let me try again... different route 😄

 

This time with JS / jQuery, if you put some nice classes around, the code will look much better, but this works:

function socialPosition() {
  // if window width is smaller 991px
  if ($(window).width() < 991) {
     // take everything of this class '.social-links' and put it on the bottom of '#hs_menu_wrapper_module_1591238150661200_.active-branch' (that's your mobile menu)
     $('.social-links').appendTo('#hs_menu_wrapper_module_1591238150661200_.active-branch');
  }
  // if window width is biger 992px
  if ($(window).width() > 992) {
     // take everything of this class '.social-links' and put it back on the bottom of '#hs_cos_wrapper_module_1591238296584315.hs_cos_wrapper.hs_cos_wrapper_widget.hs_cos_wrapper_type_module' (your initial social container)
     $('.social-links').appendTo('#hs_cos_wrapper_module_1591238296584315.hs_cos_wrapper.hs_cos_wrapper_widget.hs_cos_wrapper_type_module');
  }
}
// Do it on the initial Page load (only if below 991px)
$(window).ready(function() {
  socialPosition(); 
});
// Do it if the user resize the window (only if below 991px)
$(window).resize(function() {
  socialPosition();
});

 

You have :

.social-links--right

on the width of 991px, this will not show any icons on your mobile menu, please cancel the text-align:right; and make it to a text-align:left;

@media (max-width: 991px) {
.social-links--right {
text-align: left;
}

 

 

In your css, there is a media query with the following: 

@media (max-width: 767px)
.hs-menu-wrapper, .hs-menu-wrapper  {
    webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    display: block;
    width: 100%;
}

This will make your buttons in single rows and very big, you need to cancel to the width and maybe a display: inline; for a single row of socials

 

- Chris

jakeleong
Member

How to add the social icons inside the hamburger icon

SOLVE

Thank you @Chris-M, you are awesome! The output is exactly what I want, thanks for the quick response and I will set this ticket as resolved.

 

Regards,

Jake