Search code examples
javascriptbootstrap-4dropdown

Need split dropdown without bootstrap support


Looking for a split button dropdown field without any bootstrap package, I referred a lot but I didn't get any source.

enter image description here


Solution

  • Kindly refer the code below

    .btn {
      background-color: #2196F3;
      color: white;
      padding: 16px;
      font-size: 16px;
      border: none;
      outline: none;
    }
    
    .dropdown {
      position: absolute;
      display: inline-block;
    }
    
    .dropdown-content {
      display: none;
      position: absolute;
      background-color: #f1f1f1;
      min-width: 160px;
      z-index: 1;
    }
    
    .dropdown-content a {
      color: black;
      padding: 12px 16px;
      text-decoration: none;
      display: block;
    }
    
    .dropdown-content a:hover {background-color: #ddd}
    
    .dropdown:hover .dropdown-content {
      display: block;
    }
    
    .btn:hover, .dropdown:hover .btn {
      background-color: #0b7dda;
    }
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    </head>
    <body>
    
    <h2>Split Button Dropdowns</h2>
    <p>Move the mouse over the arrow icon to open the dropdown menu.</p>
    
    <button class="btn">Button</button>
    <div class="dropdown">
      <button class="btn" style="border-left:1px solid #0d8bf2">
        <i class="fa fa-caret-down"></i>
      </button>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </div>
    
    </body>
    </html>