dir.by  
  Search  
Programming, development, testing
Bootstrap - buttons, menus, dialog, slider ... Containers for placing elements
"Navbar" in the Bootstrap 4.0 - this is the main horizontal menu for the site (navigation headers)
  Looked at 5748 times    
 "Navbar" in the Bootstrap 4.0 - this is the main horizontal menu for the site (navigation headers) 
last updated: 10 January 2019
Example 1
Example we look, we test
Source code
  Html  
<html>

<!-- title -->
<head>
<meta charset="utf-8">
<title>Example</title>
</head>

<body>
     <!-- connect library jQuery -->
     <script src="https://dir.by/example_lib/jquery/jquery-3.3.1.min.js"></script>

     <!-- connect library Bootstrap (js file) -->
     <script src="https://dir.by/example_lib/bootstrap-4.1.3/js/bootstrap.min.js"></script>
    
     <!-- connect library Bootstrap (css file) -->
     <link rel="stylesheet" href="https://dir.by/example_lib/bootstrap-4.1.3/css/bootstrap.min.css">

     <!-- HTML Elements -->
     <nav class="navbar navbar-expand-sm bg-dark navbar-dark">

          <a class="navbar-brand" href="#">Logo</a>
    
          <ul class="navbar-nav">
               <li class="nav-item active">
                    <a class="nav-link" href="#">Active1</a>
               </li>

               <li class="nav-item">
                    <a class="nav-link" href="#">Link2</a>
               </li>

               <li class="nav-item">
                    <a class="nav-link" href="#">Link3</a>
               </li>

               <li class="nav-item">
                    <a class="nav-link disabled" href="#">Disabled4</a>
               </li>
          </ul>
     </nav>

</body>
</html>
Example 2
Collapse the navigation bar
Very often, especially on small screens, you want to hide navigation links and replace them with a single button.
To create a foldable navigation bar, use the button with
class="navbar-toggler"
data-toggle="collapse"
class="collapse navbar-collapse"
 
Example we look, we test
Source code
  Html  
<html>

<!-- title -->
<head>
<meta charset="utf-8">
<title>Example</title>
</head>

<body>
     <!-- connect library jQuery -->
     <script src="https://dir.by/example_lib/jquery/jquery-3.3.1.min.js"></script>

     <!-- connect library Bootstrap (js file) -->
     <script src="https://dir.by/example_lib/bootstrap-4.1.3/js/bootstrap.min.js"></script>
    
     <!-- connect library Bootstrap (css file) -->
     <link rel="stylesheet" href="https://dir.by/example_lib/bootstrap-4.1.3/css/bootstrap.min.css">

     <nav class="navbar navbar-expand-lg navbar-light bg-light">

          <!-- the reduced version appears when there is no space -->
          <a class="navbar-brand" href="#">Navbar</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#myNavbarMenu" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
               <span class="navbar-toggler-icon"></span>
          </button>

          <!-- all elements -->
          <div class="collapse navbar-collapse" id="myNavbarMenu">
               <ul class="navbar-nav mr-auto">

                    <!-- link -->
                    <li class="nav-item">
                         <a class="nav-link" href="#">Link</a>
                    </li>

                    <!-- combo box -->
                    <li class="nav-item dropdown">
                         <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                              Dropdown1
                         </a>
                         <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                              <a class="dropdown-item" href="#">Home</a>
                              <a class="dropdown-item" href="#">Work</a>
                              <div class="dropdown-divider"></div>
                              <a class="dropdown-item" href="#">Book</a>
                         </div>
                    </li>
               </ul>

               <!-- form -->
               <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="search" placeholder="Search">
                    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
               </form>

          </div>
     </nav>

</body>
</html>
Explanation of the example
navbar-expand-lg
Element disappears if the area is smaller lg
Learn more: class="navbar-expand-lg" in the Bootstrap 4.0 ...
mr-auto
move elements to the right edge
Learn more: class="mr-auto" in the Bootstrap 4.0 ...
form-inline
Items on a single line.
Learn more: class="form-inline" in the Bootstrap 4.0 ...
my-2
my-lg-0
my-sm-0
mr-sm-2
alignment and indentation
Read more: my-2 my-lg-0 my-sm-0 mr-sm-2 in the Bootstrap 4.0 ...
 
← Previous topic
Bootstrap 4 difference from Bootstrap 3
 
Next topic →
class="form-inline" items on a single line | Bootstrap 4.0
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

  Объявления  
  Объявления  
 
What the Bootstrap?
Bootstrap where to download and how to connect?
Containers in the Bootstrap ("container-fluid" and "container")
Bootstrap Version 4.0
Bootstrap 4 difference from Bootstrap 3
Elements
"Navbar" in the Bootstrap 4.0 - this is the main horizontal menu for the site (navigation headers)
Styles
class="form-inline" items on a single line | Bootstrap 4.0
class="navbar-expand-lg" disappears if the area size is smaller lg | Bootstrap 4.0
class="mr-auto" move to the right edge , class="ml-auto" move to the left edge | Bootstrap 4.0
Vertical indentation, horizontal indentation | Bootstrap 4.0
to study
WEB Sites to explore Bootstrap 4.0
Bootstrap items for the version 3 and 4
Create a grid "col-md-number" in the Bootstrap 3 and Bootstrap 4
WWW sites for learning Bootstrap
Sites to explore Bootstrap

  Ваши вопросы присылайте по почте: info@dir.by  
Яндекс.Метрика