简体   繁体   English

Bootstrap导航栏社交媒体图标移动版本

[英]Bootstrap navbar social media icon mobile version

I built a navigation panel using bootstrap. 我使用引导程序构建了一个导航面板。 I have a problem with the mobile version of my website. 我的网站的移动版本有问题。

Here is a sample on codepen . 这是Codepen上的示例

I tried to rebuild it, but the project breaks down all the time. 我试图重建它,但是该项目一直崩溃。

<nav class="navbar navbar-default navbar-fixed-top font">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>   
      </button>
      <a href="#up" class="navbar-brand">
    <img src="images/logo.jpg" alt="Logo" style="width:100px;">
      </a>
    </div>
    <div class="collapse navbar-collapse navbar-right" id="myNavbar">
      <ul class="nav navbar-nav">
        <li><a href="#about">O MNIE</a></li>
        <li><a href="#work">JAK PRACUJEMY</a></li>
        <li><a href="#portfolio">PROJEKTY</a></li>
        <li><a href="#contact">KONTAKT</a></li>
            <li class="nav-item"><a class="nav-link" href=""><i class="fab fa-facebook mr-1"></i></a></li>
            <li class="nav-item"><a class="nav-link" href=""><i class="fab fa-instagram"></i></a> </li>
        </ul>
  </div>
</div>

The easiest way for me to explain the effect is by sending you photos. 对于我来说,解释效果的最简单方法是向您发送照片。

before: 之前:

1


after

2

3

You could add a second pair of social media icons and then manually hide elements at certain widths with the @media rule. 您可以添加第二对社交媒体图标,然后使用@media规则手动隐藏某些宽度的元素。 That would make it look like they've moved when all you really did was hide one of them. 当您真正要做的只是隐藏其中之一时,这将使它们看起来像已经移动了。

This is how you do it: 这是您的操作方式:

Add this to the html right after your navbar-brand: 将其添加到导航栏品牌之后的html中:

<div class="collapse-social-icons">
  <a class="navbar-brand" href=""><i class="fab fa-facebook"></i></a>
  <a class="navbar-brand" href=""><i class="fab fa-instagram"></i></a>
</div>

and the class collapse-social-icons-dropdown to the icons that you want to hide on small screens. ,然后将该类折叠到您要隐藏在小屏幕上的图标上。 Like this: 像这样:

<li class="nav-item collapse-social-icons-dropdown"><a class="nav-link" href=""><i class="fab fa-facebook mr-1"></i></a></li>


Then I added this to the css: 然后我将其添加到css:

/* This is to float the social incons to the right */
.collapse-social-icons {
  position: relative;
  float: right;
  margin-right: 10px;
}

/* This is to add the same hover-effect as the other menu items */
.collapse-social-icons a:hover {
  background-color: #000000 !important;
  color: #ffffff !important;
}

/* This is to hide the "new" set of icons on big screens */
@media only screen and (min-width: 767px) {
  .collapse-social-icons {
    display:none !important;
  } 
}

/* This is to hide the "old" set of icons on small screens */
@media only screen and (max-width: 767px) {
  .collapse-social-icons-dropdown {
    display:none !important;
  } 
}

The @media rule in the css applies when the width of the page is smaller than 767px. 当页面的宽度小于767px时,css中的@media规则适用。 You can modify that anyway you want and you can allso specify a max-width if you want to. 您可以根据需要进行修改,也可以根据需要指定最大宽度。

Check it out here https://codepen.io/wenzzzel/pen/jXQVNv 在这里查看https://codepen.io/wenzzzel/pen/jXQVNv

Seems like you could add your social icons inside another div that is adjacent to the mobile button and utilize the d-none d-md-block to display them in mobile and hide them in larger views. 似乎您可以将社交图标添加到与移动按钮相邻的另一个div内,并利用d-none d-md-block在移动设备中显示它们并将其隐藏在较大的视图中。 You will also need to update your css to use Bootstrap 4's css lib. 您还需要更新CSS以使用Bootstrap 4的CSS库。

 <div class="d-flex justify-content-between">      
    <div class="d-block d-md-none">
    <a class="nav-link" href=""><i class="fab fa-facebook mr-1"></i></a>
    <a class="nav-link" href=""><i class="fab fa-instagram"></i></a>
    </div>
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>   
    </button>
    <a href="#up" class="navbar-brand">
      <img src="images/logo.jpg" alt="Logo" style="width:100px;">
    </a>
</div>

And then in your regular nav: 然后在常规导航中:

    <li class="nav-item d-none d-md-block"><a class="nav-link" href=""><i class="fab fa-facebook mr-1"></i></a></li>
    <li class="nav-item d-none d-md-block"><a class="nav-link" href=""><i class="fab fa-instagram"></i></a></li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM