Make a dropdown menu in flexbox navbar

flexbox dropdown menu responsive
responsive flexbox dropdown navigation
css drop down menu on click
responsive drop down menu with submenu
dropdown menu css
flexbox menu
convert ul li to dropdown css
drop down navigation menu html

I have made a navbar with flex properties. Now I wish to add a drop down menu to a element in navbar, but it doesn't worked as expected.

@font-face {
    font-family: Oxygen;
    src: url('https://fonts.googleapis.com/css?family=Oxygen');
}
body{
    margin: 0;
}
nav {
    background-color: #f8f8f8;
    display: flex;
    justify-content: space-between;
}
nav ul {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
}
nav a {
    text-decoration: none;
    color: #777;
    padding: 15px;
    font-family: sans-serif;
    font-size: 18px;
}
nav a:hover {
    color: #000;
}
.logo a {
    font-size: 25px;
}
nav ul {
    list-style: none;
}
ul.drop-menu li {
    display: none;
    list-style: none;
}
li:hover > ul.drop-menu li {
    display: flex;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Navbar</title>
    <link rel="stylesheet" href="nav.css">
</head>
<body>
    <nav>
        <ul class="left">
            <li class="logo"><a href="#">SoulOTrip</a></li>
            <li >
                <a href="#">Adventure Trips</a>
                <ul class="drop-menu">
                    <li>1</li>
                    <li>2</li>
                    <li>3</li>
                    <li>4</li>
                </ul>
            </li>
            <li><a href="#">Top Destinations</a></li>
            <li><a href="#">Explore</a></li>
        </ul>
        <ul class="right">
            <li class=""><a href="#">Username</a></li>
            <li class=""><a href="/login">Login</a></li>
            <li class=""><a href="/register">Register</a></li>
        </ul>
</nav>
</body>
</html>

By adding position: relative to the nav and position: absolute to the dropdown, will make the dropdown position/size relative to the nav

Setting flex: 1 on the dropdown's flex items (li) will make them stretch horizontally

Updated/added these 3 rules

nav {
    position: relative;
    background-color: #f8f8f8;
    display: flex;
    justify-content: space-between;
}

li:hover > ul.drop-menu li {
    display: flex;
    flex: 1;
}
li > ul.drop-menu {
    position: absolute;
    display: flex;
    left: 0;
    top: 100%;
    width: 100%;
}

Stack snippet

@font-face {
    font-family: Oxygen;
    src: url('https://fonts.googleapis.com/css?family=Oxygen');
}
body{
    margin: 0;
}
nav {
    position: relative;
    background-color: #f8f8f8;
    display: flex;
    justify-content: space-between;
}
nav ul {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
}
nav a {
    text-decoration: none;
    color: #777;
    padding: 15px;
    font-family: sans-serif;
    font-size: 18px;
}
nav a:hover {
    color: #000;
}
.logo a {
    font-size: 25px;
}
nav ul {
    list-style: none;
}
ul.drop-menu li {
    display: none;
    list-style: none;
}
li:hover > ul.drop-menu li {
    display: flex;
    flex: 1;
}
li > ul.drop-menu {
    position: absolute;
    display: flex;
    left: 0;
    top: 100%;
    width: 100%;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Navbar</title>
    <link rel="stylesheet" href="nav.css">
</head>
<body>
    <nav>
        <ul class="left">
            <li class="logo"><a href="#">SoulOTrip</a></li>
            <li >
                <a href="#">Adventure Trips</a>
                <ul class="drop-menu">
                    <li>1</li>
                    <li>2</li>
                    <li>3</li>
                    <li>4</li>
                </ul>
            </li>
            <li><a href="#">Top Destinations</a></li>
            <li><a href="#">Explore</a></li>
        </ul>
        <ul class="right">
            <li class=""><a href="#">Username</a></li>
            <li class=""><a href="/login">Login</a></li>
            <li class=""><a href="/register">Register</a></li>
        </ul>
</nav>
</body>
</html>

How to Create Dropdown Navigation Menu Using Flexbox, Responsive Dropdown Menu with Flexbox | CSS Flexbox Tutorial - Duration: 8:​12 Duration: 8:52 Posted: Jun 15, 2018 How to Create Drop Down Navigation Menu with CSS and HTML | Pure CSS Dropdown Navigation Bar - Duration: 8:22. Divinector 1,814 views

You don't need display:flex for li elements in dropdown

@font-face {
    font-family: Oxygen;
    src: url('https://fonts.googleapis.com/css?family=Oxygen');
}
body{
    margin: 0;
}
nav {
    background-color: #f8f8f8;
    display: flex;
    justify-content: space-between;
}
nav ul {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin: 0;
}
nav ul>li{
    position:relative;
}
nav a {
    text-decoration: none;
    color: #777;
    padding: 15px;
    font-family: sans-serif;
    font-size: 18px;
}
nav a:hover {
    color: #000;
}
.logo a {
    font-size: 25px;
}
nav ul {
    list-style: none;
}
ul.left>li.drop-menu{
    display:none;
    position:absolute;
    left:0;
    
}
.drop-menu li{
    display:block;
}
ul.left>li:hover .drop-menu{
    display:block;
}

How to Create Dropdown Menu using Flexbox Tutorial, How to Create Dropdown Menu using Flexbox Tutorial Is it intended that u use "display Duration: 15:43 Posted: Apr 6, 2018 Flexbox is a versatile layout module with which we can create one-dimensional layouts that require flexibility, such as responsive menus. Using flexbox’s ordering, alignment, and sizing properties, we can build navigation bars that adapt their layouts to the viewport size while keeping the HTML outline logical and accessible.

I developed a large responsive_flex.css file for my works and my jumperl.com site.

While I was simplifying to the maximum, I found this post, here is the solution good man.

/* Menu Dropdown! please use div */
.dropdown{
    display: flex;
    flex-wrap: wrap;
    flex-direction:column;
}
.dropdown > .dropdown-title{
    /* put the height and width here! */
}
.dropdown > .dropdown-sub{
    display: none;
    z-index: 1;
    flex-direction: column; /* or row */
}
.dropdown:hover > .dropdown-sub {
    display: flex;
}.dropdown:hover > .dropdown-sub  > .dropdown-option:hover{
    background-color: #abcdef;
}
<div class="dropdown" style="background-color:#aaa;">
    <div class="dropdown-title" style="background-color:#bbb; border:1px solid #000000;">Titulo</div>
    <div class="dropdown-sub" style="background-color: #cccccc;">
        <div class="dropdown-option">option 1</div>
        <div class="dropdown-option">option 2</div>
        <div class="dropdown-option">option 3</div>
    </div>
</div>

Solved with CSS! Dropdown Menus, Let's see if we can make one of these menus with CSS alone. We'll create a list of links within a nav component like so: <nav role="navigation">  Dropdown menus are used in almost all the websites. In this video you will learn how to create a rdropdown navigation menu using Flexbox. If you want to lear

this resolve one problem about likely position abosolute on sub menu.

Perdón my poor english amico mio

/* Menu Dropdown! please use div */
.dropdown{
    display: flex;
    flex-wrap:wrap;
    flex-direction: row; /* or column */
    /* put the height and width here! */
}
.dropdown > .dropdown-title{
    width: 100%;
    height: 100%;
}
.dropdown > .dropdown-sub{
    display: none;
    z-index: 1;
    flex-direction: column; /* or row */
    /* width: 100%; */
}
.dropdown:hover > .dropdown-sub {
    display: flex;
}.dropdown:hover > .dropdown-sub  > .dropdown-option:hover{
    /* background-color: #abcdef; */
}
<div class=" dropdown" style="background-color:#aaa;height: 20px;">
    <div class="dropdown-title" style="background-color:#bbb; border:1px solid #000000;">Titulo</div>
    <div class="dropdown-sub" style="background-color: #cccccc;">
        <div class="dropdown-option">option 1</div>
        <div class="dropdown-option">option 2</div>
        <div class="dropdown-option">option 3</div>
    </div>
</div>
<div>Random bottom item</div>

Flexbox dropdown navigation menu, View Compiled HTML; Analyze HTML; Maximize HTML Editor; Minimize HTML Editor; Fold All; Unfold All. 46. 1. <header>. 2. <nav role="navigation">. 3. <ul>. 4. Learn how to build a nav bar that is fully responsive tutorial with CSS Flexbox. We'll be using some Javascript alongside our HTML & CSS to create the navigation bar menu. We'll add a bit of

Responsive Flexbox Dropdown Navigation, Maximize HTML Editor; Minimize HTML Editor; Fold All; Unfold All. 21. 1. <nav class="main-navigation">. 2. <ul class="menu">. 3. <li><a href="#">Home</a></li​>. On small devices such as tablet and mobile, the navbar will convert into a toggle menu which can be accessed when the user clicks. Just to mention here, I am not going to do something fancy here but will build a basic responsive navbar with pure CSS only. Many menu bars including dropdown are created using a combination of HTML, CSS3, and jQuery. But here we will create it using only CSS.

Building Mega Menus with Flexbox, Building the navigation bar: Using flexbox to build a simple navigation bar for our imaginary e-commerce platform; Building a single drop-down  A mega drop-down menu navigation system is a decent way to demonstrate the power and simplicity of Flexbox, which I hope I have conveyed in this tutorial. As you can see, flexbox is useful for more than just centering content. If you’ve used a different flexbox-based technique to build a mega menu system,

How to Build a Responsive Navigation Bar With Flexbox, In this tutorial we will use flexbox to create a mobile-first, responsive, toggleable The best thing about flexbox menus is that they are really very they are presented as links, as they are part of the toggleable dropdown list). Let’s start by telling the browser that we want to lay out the elements in the navigation bar with Flexbox by setting the display property of the container element to flex..navbar {display: flex;} This makes .navbar a flex container while its direct children (.logo and .nav-links) become flex items.

Comments
  • I am planning something else for the li elements, so I added the flex property.