OnsenUI - ion-navicon不显示图标

时间:2014-10-07 09:13:14

标签: html css angularjs onsen-ui

我试过这里。我在span中给出了这个标签。但是,它没有在导航栏中显示图标。

 <i class="ion-navicon" style="font-size:32px; vertical-align:-6px;"></i>

的index.html

<!doctype html>
<html lang="en" ng-app="my-app">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="onsenui.css"/>
    <link rel="stylesheet" href="onsen-css-components.css"/>
    <script src="angular.js"></script>
    <script src="onsenui.js"></script>
    <script>
     ons.bootstrap();
    </script>
    <style>
.navigation-bar {
  font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-weight: 400;
  font-size: 17px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
  white-space: nowrap;
  overflow: hidden;
  word-spacing: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  line-height: normal;
  cursor: default;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  z-index: 2;
  display: block;
  height: 44px;
  padding-left: 0;
  padding-right: 0;
  background: #f8f8f8;
  color: #1f1f21;
  -webkit-box-shadow: none;
  box-shadow: none;
  border-bottom: 1px solid #ddd;
  font-weight: 400;
  width: 100%;
  white-space: nowrap;
  overflow: visible;
}
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .navigation-bar {
    border-bottom: none;
    -webkit-background-size: 100% 1px;
    background-size: 100% 1px;
    background-repeat: no-repeat;
    background-position: bottom;
    background-image: -webkit-linear-gradient(90deg, #ddd, #ddd 50%, transparent 50%);
    background-image: -moz-linear-gradient(90deg, #ddd, #ddd 50%, transparent 50%);
    background-image: -o-linear-gradient(90deg, #ddd, #ddd 50%, transparent 50%);
    background-image: linear-gradient(0deg, #ddd, #ddd 50%, transparent 50%);
  }
}
.navigation-bar__line-height {
  line-height: 44px;
  padding-bottom: 0;
  padding-top: 0;
}
.navigation-bar__bg {
  background: #f8f8f8;
}
.navigation-bar__item,
.navigation-bar__left,
.navigation-bar__right,
.navigation-bar__center {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  line-height: normal;
  height: 44px;
  vertical-align: top;
  overflow: visible;
  display: block;
  vertical-align: middle;
  float: left;
}
.navigation-bar__left {
  max-width: 50%;
  width: 27%;
  text-align: left;
}
.navigation-bar__right {
  max-width: 50%;
  width: 27%;
  text-align: right;
}
.navigation-bar__center {
  width: 46%;
  text-align: center;
  line-height: 44px;
  font-size: 17px;
  font-weight: 500;
}
.navigation-bar__title {
  line-height: 44px;
  font-size: 17px;
  font-weight: 500;
  color: #1f1f21;
  margin: 0;
  padding: 0;
  overflow: visible;
}
.navigation-bar__center:first-child:last-child {
  width: 100%;
}

.toolbar-button,
.toolbar-button--outline,
.toolbar-button--quiet {
  font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-weight: 400;
  font-size: 17px;
  padding: 4px 10px;
  letter-spacing: 0;
  color: #1284ff;
  text-shadow: 0 1px none;
  vertical-align: baseline;
  background-color: rgba(0,0,0,0);
  -webkit-border-radius: 2px;
  border-radius: 2px;
  border: 1px solid transparent;
  font-weight: 400;
  font-size: 17px;
  -webkit-transition: none;
  -moz-transition: none;
  -o-transition: none;
  transition: none;
  vertical-align: middle;
}
.toolbar-button:active,
.toolbar-button--outline:active,
.toolbar-button--quiet:active {
  background-color: rgba(0,0,0,0);
  -webkit-transition: none;
  -moz-transition: none;
  -o-transition: none;
  transition: none;
  opacity: 0.2;
}
.toolbar-button:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}
.toolbar-button:focus,
.toolbar-button--outline:focus,
.toolbar-button--quiet:focus {
  outline: 0;
  -webkit-transition: none;
  -moz-transition: none;
  -o-transition: none;
  transition: none;
}
.toolbar-button:hover,
.toolbar-button--outline:hover,
.toolbar-button--quiet:hover {
  -webkit-transition: none;
  -moz-transition: none;
  -o-transition: none;
  transition: none;
}
.toolbar-button--outline {
  border: 1px solid #1284ff;
  margin: auto 8px;
  padding-left: 6px;
  padding-right: 6px;
}
    </style>
  </head>
  <body ng-controller="AppController">

        <!-- Page content -->

<div class="navigation-bar navigation-bar--transparent">
  <div class="navigation-bar__left">
    <span class="toolbar-button--quiet navigation-bar__line-height">
      <i class="ion-navicon" style="font-size:32px; vertical-align:-6px;"></i>
    </span>
  </div>
  <div class="navigation-bar__center">
    Navigation Bar
  </div>
  <div class="navigation-bar__right">
    <span class="toolbar-button--quiet navigation-bar__line-height">Label</span>
  </div>
</div>
  </body>
</html>

2 个答案:

答案 0 :(得分:5)

OnsenUI正在使用Ionicons。因此,为了显示它,您需要将ionicons.css文件添加到项目中。有两种方法可以做到:

  1. 在本地包含文件。转到here。然后,点击Download按钮。解压缩文件并将ionicons.css文件添加到项目中。请确保在您的项目中遵循此文件夹安排,如下所示:<link rel="stylesheet" type="text/css" href="ionicons/css/ionicons.css">。否则,图标仍然无法显示。
  2. 使用CDN网址自动包含文件。在ur html标题中添加此链接:      <link rel="stylesheet" type="text/css" href="http://code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css">
  3. 注意:我测试过,网站上当前的CDN网址似乎无效。因此,现在请手动添加文件,如步骤1所示。 我也通知了OnsenUI团队。他们表示将更新网站并告知用户有关此要求的信息。

答案 1 :(得分:2)

实际上onsen ui允许你使用离子和令人敬畏的字体图标。只要您包含必要的onsens js和css,您就可以使用它们(参见他们的CodePen示例),但当然您也可以手动添加它们,如前面的答案所示。在处理我的应用时,我没有必要。

请查看此处的文档:http://onsenui.io/guide/overview.html#UsingIcons

使用Font Awesome 如果icon属性的值以fa-开头,则使用相应的Font Awesome图标。可以在Font Awesome网站上找到可用图标列表。如果icon属性没有前缀,则将使用Font Awesome集合。

<ons-icon icon="fa-angle-left"></ons-icon>

<i class="fa-angle-left"></i> (as their site suggested) it works too!!

使用Ionicons 如果icon属性的值以ion-开头,则使用适当的Ionicons图标。可以在Ionicons网站上找到可用图标列表。

<ons-icon icon="ion-chevron-left"></ons-icon>

要找出要使用的值,请访问他们的网站:

http://ionicons.com/ 
http://fortawesome.github.io/Font-Awesome/icons/

希望这有帮助!