Bootstrap 图标

简介

このチュートリアルでは、Bootstrap 2.0 ツールキットを使用してアイコンを作成する方法を学びます。Bootstrap アイコンは Glyphicons によって提供されています。プロジェクトでこれらのアイコンを使用する場合は、必ず提供してください。Glyphiconsのリンク。

CSSスプライトとして使用

すべてのアイコン画像はまとめてバンドルされ、...を介してbackground-position CSS 属性使用。画像ファイルは glyphicons-halflings.png で、Bootstrap メインフォルダー内の img フォルダーにあります。アイコンのスタイルおよび背景位置は、bootstrap.css の行番号 1168 から 1544 で規定されています。競合を避けるため、すべてのアイコン class は "icon-" をプレフィックスとしていることに注意してください。Bootstrap 2.0 では 120 個のアイコン class が定義されています。

自分のサイトやアプリでアイコンを使用する方法

サイトまたはアプリでアイコンを使うための一般的な構文は次のとおりです:

 <i class="icon_class_name"></i> 

其中 "icon_class_name" は bootstrap.css で定義されているアイコンクラスの名前です(例:icon-music、icon-star、icon-user など)。

白色のアイコンを使用したい場合は、追加の icon-white クラスを次のように追加します:

<i class="icon_class_name icon-white"></i>  </i>

アイコンを使用する際に何らかの文字列を伴わせたい場合は、後ろにスペースを追加することを忘れないでください。ボタンや一部のナビゲーションリンクでアイコンを使用する場合にこれが起こる可能性があります。

例:検索フォーム

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
<title>Bootstrap バージョン2.0 における検索アイコンの使用例</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Example of using icons in search form - Bootstrap version 2.0 from w3cschool.cc">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css.html" rel="stylesheet">
    <style type="text/css">
        form {
            margin-top: 50px;
        }
    </style>
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico.html">
    <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png.html">
    <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png.html">
    <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png.html">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="span12">
            <form class="well form-search">
                <input type="text" class="input-medium search-query">
<button type="submit" class="btn"><i class="icon-search"></i> 搜索</button>
            </form>
        </div>
    </div>
    <footer>
        <p>&copy; Company 2013</p>
    </footer>
</div>
</body>
</html>

オンラインで表示

異なるブラウザウィンドウで上記の例を表示します。

例:ナビゲーションでアイコンを使用

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
<title>Bootstrap バージョン 2.0 でナビゲーションにアイコンを使用する</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Example icons in navigation with Bootstrap version 2.0 from w3cschool.cc">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css.html" rel="stylesheet">
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico.html">
    <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png.html">
    <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png.html">
    <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png.html">
</head>

<body>
<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <a class="brand" href="../index.html">サンプル</a>
            <div class="nav-collapse">
                <ul class="nav">
                    <li class="active"><a href="../index.html"><i class="icon-user icon-white"></i> Home</a></li>
                    <li><a href="../index.html"><i class="icon-user icon-white"></i> User</a></li>
                    <li><a href="../index.html"><i class="icon-download icon-white"></i> Downlaod</a></li>
                    <li><a href="../index.html"><i class="icon-upload icon-white"></i> Upload</a></li>
                    <li><a href="../index.html"><i class="icon-play-circle icon-white"></i> Play Circle</a></li>
                    <li><a href="../index.html"><i class="icon-bookmark icon-white"></i> Bookmark</a></li>
                    <li><a href="../index.html"><i class="icon-gift icon-white"></i> Gift</a></li>
                </ul>
            </div><!--/.nav-collapse -->
        </div>
    </div>
</div>

<hr>
</div> <!-- /container -->

<!-- Le javascript
================================================== -->
<!-- ドキュメントのページ下部に配置して読み込み速度を速めます -->
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/jquery.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-transition.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-modal.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-dropdown.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-scrollspy.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tab.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tooltip.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-popover.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-button.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-collapse.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-typeahead.js.html"></script>

</body>
</html>

オンラインで表示

異なるブラウザウィンドウで上記の例を表示します。

例:ボタンとボタングループでアイコンを使用

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
<title>Bootstrap バージョン 2.0 でボタンとボタングループにアイコンを使用する</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Example of using icons in buttons and button groups - Bootstrap version 2.0 from w3cschool.cc">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="../bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css.html" rel="stylesheet">
    <style type="text/css">
        form {
            margin-top: 50px;
        }
    </style>
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/favicon.ico.html">
    <link rel="apple-touch-icon" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png.html">
    <link rel="apple-touch-icon" sizes="72x72" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png.html">
    <link rel="apple-touch-icon" sizes="114x114" href="../bootstrap/twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png.html">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="span4">
            <div class="btn-toolbar" style="margin-bottom: 9px">
                <div class="btn-group">
                    <a class="btn" href="../index.html"><i class="icon-align-left"></i></a>
                    <a class="btn" href="../index.html"><i class="icon-align-center"></i></a>
                    <a class="btn" href="../index.html"><i class="icon-align-right"></i></a>
                    <a class="btn" href="../index.html"><i class="icon-align-justify"></i></a>
                </div>
                <div class="btn-group">
                    <a class="btn btn-primary" href="../index.html"><i class="icon-user icon-white"></i> User</a>
                    <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="../index.html"><span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="../index.html"><i class="icon-pencil"></i> Edit</a></li>
                        <li><a href="../index.html"><i class="icon-trash"></i> Delete</a></li>
                        <li><a href="../index.html"><i class="icon-ban-circle"></i> Ban</a></li>
                        <li class="divider"></li>
                        <li><a href="../index.html"><i class="i"></i> Make admin</a></li>
                    </ul>
                </div>
            </div>
            <p>
                <a class="btn" href="../index.html"><i class="icon-refresh"></i> Refresh</a>
                <a class="btn btn-success" href="../index.html"><i class="icon-shopping-cart icon-white"></i> Checkout</a>
                <a class="btn btn-danger" href="../index.html"><i class="icon-trash icon-white"></i> Delete</a>
            </p>
            <p>
                <a class="btn btn-large" href="../index.html"><i class="icon-comment"></i> Comment</a>
                <a class="btn btn-small" href="../index.html"><i class="icon-cog"></i> Settings</a>
                <a class="btn btn-small btn-info" href="../index.html"><i class="icon-info-sign icon-white"></i> More Info</a>
            </p>
        </div>
    </div>
</div>
<!-- Le javascript
================================================== -->
<!-- ドキュメントのページ下部に配置して読み込み速度を速めます -->
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/jquery.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-transition.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-alert.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-modal.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-dropdown.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-scrollspy.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tab.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-tooltip.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-popover.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-button.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-collapse.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js.html"></script>
<script src="../bootstrap/twitter-bootstrap-v2/docs/assets/js/bootstrap-typeahead.js.html"></script>
</body>
</html>

オンラインで表示

異なるブラウザウィンドウで上記の例を表示します。

ここをクリックして、本チュートリアルで使用するすべてのHTML、CSS、JSおよび画像ファイルをダウンロードしてください。

其他扩展