Let's make bootstrap dropdown menu
Bootstrap has many great features. Easy and great-looking dropdown menu is one of the things. At first, look at the reference in the page of http://getbootstrap.com/.
<div class="dropdown">
<button class="btn dropdown-toggle sr-only" type="button" id="dropdownMenu1" data-toggle="dropdown">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
</ul>
</div>
Dropdown is a 'Component' of bootstrap. How we can make a dropdown menu? First you need the unordered list(<ul>). Its class is 'dropdown-menu' and role is 'menu'. <li> can be divider if it is added with the class of 'divider'. 'aria-labelledby' will be treated later.
Dropdown Menu will be shown up when you click the some button or something. 'Dropdown menu' cannot exist itself, so it must be linked. In upper example, there is the button named Dropdown. It must be linked with
those button. Linking is so easy. You can simply link the dropdown menu with the button.
1. Make button.
2. Give ID to the button.
3. Set 'data-toggle' to 'dropdown'.
4. 'aria-labelledby' of the unordered list(<ul>, dropdown menu) is ID of the button.
Although you don't want to link with the buttons, the process almost same. For example, there is the navbar.
Navbar can have dropdown-menu, too.
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
It won't need the ID because what is linked with dropdown-menu is so obvious. You can make dropdown-menu by simply adding classes and data-toggle option.
In these work, jQuery and bootstrap's JS must be required. Because making something show or hide is the JS's role. So,
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
It is the general code. Do you realize why jQuery and JS are needed?
'Creation > Design' 카테고리의 다른 글
[jQuery] 누르면 크기가 늘어나는 검색창 (9) | 2014.05.04 |
---|---|
[CSS3] box-shadow 속성 (11) | 2014.05.04 |
CSS Grayfilter with crossbrowsing (16) | 2014.04.17 |
Offcanvas가 있는 반응형 스킨의 구조 설계 (14) | 2014.03.30 |
Bootstrap Customize - Boost your bootstrap (7) | 2014.03.16 |
부트스트랩의 col-push와 col-pull 속성 (1) | 2014.03.05 |
[CSS+Javascript] 간단한 Back to top 버튼 넣기 (6) | 2014.02.26 |
[CSS] 구글 애드센스 노란색 뒷배경 제거하기 (1) | 2014.02.26 |
[CSS] CSS로만 만든 배경 / 그레디언트 들어간 배경 쓰기 (5) | 2014.02.24 |
[폰트] 구글 Fonts이용, 영문 웹폰트 적용시키기 (9) | 2014.02.22 |