adc

clicks

How to Create Dropdown Menu Using Html and Css | CSS Dropdown Tutorial

A dropdown menu is very useful when it comes to organizing pages and subpages within your website. The effect can easily be created using CSS. In this tutorial, we’ll be showing you how to build a CSS dropdown menu. Let’s get started!


HTML

Before we start writing code first, we need to create a primary structure of the HTML document, so that the browser can understand and start working. The basic HTML structure looks like the following.

After writing the primary structure of the HTML document, you will also write the tags and content you need. After that, you can see the output in your browser. We know that HTML Sudu Mae is used for exposing content in a basic format. To complete our content we need to use CSS, which is an HTML insert and it creates an engaging user interface.

 <!DOCTYPE html>
<html>
<head>
    <title>Dropdown</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div class="container">
        <button class="click">Click Me</button>
        <div class="list">
            <button class="links">Mane</button>
            <button class="links">Contain</button>
            <button class="links">Caragori</button>
            <button class="links">About</button>
            <button class="links">lifestyle</button>
        </div>
    </div>
      <script>

            let click = document.querySelector('.click');
            let list = document.querySelector('.list');
            click.addEventListener("click",()=>{
                list.classList.toggle('newlist');

            });

        </script>

</body>
</html>

CSS 

Now, we have time to improve the HTML content, for that, we need to add CSS to the HTML file. CSS can be added to HTML documents in a total of three ways, here we are using outside CSS design using CSS will arrive here after typing and see the output in your browser.

 *{
    margin: 0;
    padding:0;
    box-sizing: border-box;
}
body{
    width: 100%;
    padding-top: 220px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: url(img/pic.jpg);
    background-repeat: no-repeat;
    background-size: cover;
}
.container{
    width: 220px;
    position: relative;
}
.click{
    background-color: #470000;
    color: white;
}
.click:hover{
    background-color: #214c61;
    color: white;
}

.click,.links{
    padding: 12px;
    font-size: 1.3em;
    font-family: fantasy;
    border:none;
    outline: none;
    width: 250px;
    color: white;
    transform: 0.3s;
}
.list{
    position: absolute;
    transform: scaleY(0);
    transform-origin: top;
    transform: 0.3s;
}
.newlist{
    transform: scaleY(1);
}
.links{
    background-color: #335533;
}
.links:hover{
    background-color: #11002c;
}

 Image link

Source Code

 

 Watch Videos

 

More Videos

 

 



How to Create Dropdown Menu Using Html and Css | CSS Dropdown Tutorial How to Create Dropdown Menu Using Html and Css | CSS Dropdown Tutorial Reviewed by easycoding on August 17, 2020 Rating: 5

No comments:

Powered by Blogger.