概要
Twitter Bootstrapを使ってページを作成するときに、navbarの色を変更したかったけど記事が見つからなくて自力でやったからそのメモ。
環境
- OS
- Linux www4322gi 3.2.0-64-generic #97-Ubuntu SMP Wed Jun 4 22:04:21 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
- Twitter Bootstrap
- version: 2.3.2
環境準備
Twitter BootstrapをダウンロードしてサンプルHTMLファイルを作る。wget http://getbootstrap.com/2.3.2/assets/bootstrap.zip unzip bootstrap.zip rm bootstrap.zip vim sample.html
sample.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Bootstrap, from Twitter</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <!-- Le styles --> <link href="http://sample.com/bootstrap/css/bootstrap.css" rel="stylesheet"> <style> body { padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ } </style> <link href="http://sample.com/bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> </head> <body> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> <button type="button" 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> </button> <a class="brand" href="#">Project name</a> <div class="nav-collapse collapse"> <ul class="nav"> <li><a href="#">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> </ul> </div><!--/.nav-collapse --> </div> </div> </div> <div class="container"> <h1>Bootstrap starter template</h1> <p>Use this document as a way to quick start any new project.<br> All you get is this message and a barebones HTML document.</p> </div> <!-- /container --> <!-- Le javascript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> <script src="http://sample.com/bootstrap/js/bootstrap.js"></script> </body> </html>
navbarの色変更
bootstrap/css/bootstrap.css
以下が変更対象部分。222222から111111へのグラデーションになっている。青色に変更する。... .navbar-inverse .navbar-inner { background-color: #1b1b1b; background-image: -moz-linear-gradient(top, #222222, #111111); background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#222222), to(#111111)); background-image: -webkit-linear-gradient(top, #222222, #111111); background-image: -o-linear-gradient(top, #222222, #111111); background-image: linear-gradient(to bottom, #222222, #111111); background-repeat: repeat-x; border-color: #252525; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff222222', endColorstr='#ff111111', GradientType=0); } ...
... .navbar-inverse .navbar-inner { background-color: #1b1b1b; background-image: -moz-linear-gradient(top, #0000cd, #0000ff); background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0000cd), to(#0000ff)); background-image: -webkit-linear-gradient(top, #0000cd, #0000ff); background-image: -o-linear-gradient(top, #0000cd, #0000ff); background-image: linear-gradient(to bottom, #0000cd, #0000ff); background-repeat: repeat-x; border-color: #006400; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0000cd', endColorstr='#ff0000ff', GradientType=0); } ...
navbar内の文字色を変更
このままだと文字の色が見えにくいので変更する。白色にしてhoverすると灰色にする。... .navbar-inverse .brand, .navbar-inverse .nav > li > a { color: #000000; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); } .navbar-inverse .brand:hover, .navbar-inverse .nav > li > a:hover, .navbar-inverse .brand:focus, .navbar-inverse .nav > li > a:focus { color: #999999; } .navbar-inverse .brand { color: #000000; } ...
... .navbar-inverse .brand, .navbar-inverse .nav > li > a { color: #ffffff; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); } .navbar-inverse .brand:hover, .navbar-inverse .nav > li > a:hover, .navbar-inverse .brand:focus, .navbar-inverse .nav > li > a:focus { color: #aaaaaa; } .navbar-inverse .brand { color: #ffffff; } ...