CSS Materialise 框架:导航栏中的响应式徽标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33444381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:33:00  来源:igfitidea点击:

Materialize framework: responsive logo in navbar

cssmaterial-designmaterialize

提问by Filip Perz

I'm creating a website in materialize framework. I have a problem with logo in navbar. So my logo is very big (6202x3800 px) and I don't have any other version. I want to put this logo in navbar but it always exceeds the frame of nav-wrapper. I tried to add class responsive-imgbut it didn't work at all.

我正在物化框架中创建一个网站。我在导航栏中的徽标有问题。所以我的标志非常大(6202x3800 像素),我没有任何其他版本。我想把这个标志放在导航栏中,但它总是超出nav-wrapper. 我试图添加类,responsive-img但它根本不起作用。

Here is my code:

这是我的代码:

#allcontent {
  background-color: white;
  margin: 2%;
}
body {
  background: #d26335;
}
nav {
  color: black;
}
<div class="row" id="allcontent">
  <div class="navbar-default" id="navbar">
    <nav class="white">
      <div class="nav-wrapper">
        <a href="index.html" class="brand-logo left"><img class="responsive-img" id="logo" src="<!-- my image -->"/></a>
        <ul id="nav-mobile" class="right hide-on-med-and-down">
          <li><a href="sass.html"><i class="material-icons">search</i></a>
          </li>
          <li>colors</li>
        </ul>
      </div>

    </nav>
  </div>
</div>

回答by vanburen

All you have to do is control the size of the image with CSS to whatever dimensions you want:

您所要做的就是使用 CSS 将图像的大小控制为您想要的任何尺寸:

.navbar-material .nav-wrapper .brand-logo img {
    height: 64px;
}

Or use a image editor to resize the image to something more reasonable for a logo to start with. See Photoshop, GIMPor Sketchto name a few.

或者使用图像编辑器将图像调整为更合理的大小,以便徽标开始。参见PhotoshopGIMPSketch 等

(*And definitely compress images; if you're not using a build system to do this there's always something like TINYpng)

(*并且绝对压缩图像;如果您不使用构建系统来执行此操作,那么总会有类似TINYpng的东西)

See working example Snippet.

请参阅工作示例代码段。

(**note all classes used are default MaterialCSSminus the .navbar-materialclass and it looks like you're mixing Bootstrap3 classes with MaterialCSS classes)

(**注意所有使用的类都是默认的MaterialCSS减去.navbar-material类,看起来你正在混合 Bootstrap3 类和 MaterialCSS 类)

$(".button-collapse").sideNav();
body {
  background: #d26335;
}
nav.navbar-material {
  background: #d26335;
  border: none;
  box-shadow: none;
}
.navbar-material .nav-wrapper {
  background: white;
  margin: 20px;
}
.navbar-material .nav-wrapper > ul > li > a {
  color: black;
}
.navbar-material .nav-wrapper .brand-logo img {
  height: 64px;
}
.navbar-material .nav-wrapper .button-collapse i {
  color: black;
}
@media (max-width: 600px) {
  .navbar-material .nav-wrapper .brand-logo img {
    height: 56px;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/css/materialize.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<nav class="navbar-material">
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo">
      <img src="http://placehold.it/6202x3800/FF001E/fff">
    </a>
    <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>

    <ul class="right hide-on-med-and-down">
      <li><a href="sass.html">Sass</a>

      </li>
      <li><a href="badges.html">Components</a>

      </li>
      <li><a href="collapsible.html">Javascript</a>

      </li>
      <li><a href="mobile.html">Mobile</a>

      </li>
    </ul>
    <ul class="side-nav" id="mobile-demo">
      <li><a href="sass.html">Sass</a>

      </li>
      <li><a href="badges.html">Components</a>

      </li>
      <li><a href="collapsible.html">Javascript</a>

      </li>
      <li><a href="mobile.html">Mobile</a>

      </li>
    </ul>
  </div>
</nav>