Home > Enterprise >  How to Create a Smooth Dropping Animation in CSS?
How to Create a Smooth Dropping Animation in CSS?

Time:05-19

I am trying to create a smooth animation of my nav-bar in CSS here's my HTML Code-

<body>
    <nav >
        <ul >
            <li><n>Engine</n></li>
            <li><a href="#home">Home</a></li>
            <li><a href="#About">About</a></li>
            <li><a href="#Contact Us">Contact Us</a></li>
            <li><button type="button" id="mysearch">More</button></li>
        </ul>
 
    </nav>
    <hr>
</body>
</html>

Here's my CSS Code-

*{
    margin: 0;
    padding: 0;
}
html{
    background-color: white;
    background-image: url("img/ManHattanImage.webp");
}
li{
    align-items: left;
    width: 100px;
    height: 100%;
    display: inline-block;
    margin-right: 170px;
    font-size: 20px;
    /* background-color: black; */
    color: black;
    font-size: 20px;
}
hr{
    color: black;
    margin-top: 30px;
}
n{
    /* background-color: black; */
    color: white;
    font-size: 40px;
    font-style: bold;
    font-family: "Lucida Console", "Courier New", monospace;
    margin-left: 20px;
    margin-top: 30px;
}
a { 
    text-decoration: none;
    color: white;
}
a:visited { text-decoration: none; }
a:hover {
    text-decoration: none;
    /* background-color: black; */
}
a:focus { text-decoration: none; }
a:hover, a:active { text-decoration: none; }
nav:hover{
    height:300px;
}

I want a clean Animation like of a good dropdown menu navbar and with clear overlaps, Also I may add some more elements inside the navbar (With Further Updates)?

CodePudding user response:

This is how to make a dropdown menu but I'm not sure how to do an animation. I hope this is what you meant by the dropdown menu.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.dropbtn {
  background-color: #ac0d0d;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #ffffff;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  color: rgb(18, 19, 85);
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {background-color: #ddd;}

.dropdown:hover .dropdown-content {display: block;}

.dropdown:hover .dropbtn {background-color: #ac0d0d;}
</style>
</head>
<body>


<div >
  <button >Dropdown menu</button>
  <div >
    <a href="#">first</a>
    <a href="#">second</a>
    <a href="#">third </a>
  </div>
</div>

</body>
</html>

CodePudding user response:

Animation Drop down menu on hover

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>

nav {
    width: 100%;
    height: 80px;
    background: #222;
}

ul {
    text-align: center;
}

ul li {
    font: 13px Verdana, 'Lucida Grande';
    cursor: pointer;
    -webkit-transition: padding .05s linear;
    -moz-transition: padding .05s linear;
    -ms-transition: padding .05s linear;
    -o-transition: padding .05s linear;
    transition: padding .05s linear;
}
ul li.drop {
    position: relative;
}
ul > li {
    display: inline-block;
}
ul li a {
    line-height: 80px;
    padding: 0 20px;
    height: 80px;
    color: #777;
    -webkit-transition: all .1s ease-out;
    -moz-transition: all .1s ease-out;
    -ms-transition: all .1s ease-out;
    -o-transition: all .1s ease-out;
    transition: all .1s ease-out;
}
ul li a:hover {
    color: #eee;
}

.dropOut .triangle {
    width: 0;
    height: 0;
    position: absolute;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid white;
    top: -8px;
    left: 50%;
    margin-left: -8px;
}
.dropdownContain {
    width: 160px;
    position: absolute;
    z-index: 2;
    left: 50%;
    margin-left: -80px; /* half of width */
    top: -400px;
}
.dropOut {
    width: 160px;
    background: white;
    float: left;
    position: relative;
    margin-top: 0px;
    opacity: 0;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    -webkit-box-shadow: 0 1px 6px rgba(0,0,0,.15);
    -moz-box-shadow: 0 1px 6px rgba(0,0,0,.15);
    box-shadow: 0 1px 6px rgba(0,0,0,.15);
    -webkit-transition: all .1s ease-out;
    -moz-transition: all .1s ease-out;
    -ms-transition: all .1s ease-out;
    -o-transition: all .1s ease-out;
    transition: all .1s ease-out;
}

.dropOut ul {
    float: left;
    padding: 10px 0;
}
.dropOut ul li {
    text-align: left;
    float: left;
    width: 125px;
    padding: 12px 0 10px 15px;
    margin: 0px 10px;
    color: #777;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    -webkit-transition: background .1s ease-out;
    -moz-transition: background .1s ease-out;
    -ms-transition: background .1s ease-out;
    -o-transition: background .1s ease-out;
    transition: background .1s ease-out;
}

.dropOut ul li:hover {
    background: #f6f6f6;
}

ul li:hover a { color: white; }
ul li:hover .dropdownContain { top: 65px; }
ul li:hover .underline { border-bottom-color: #777; }
ul li:hover .dropOut { opacity: 1; margin-top: 8px; }
</style>
<body>
<nav>
      <ul>
        <li >
          <a href="#">You</a>
    
          <div >
            <div >
              <div ></div>
              <ul>
                <li>Plan</li>
                <li>Account Settings</li>
                <li>Switch Account</li>
                <li>Sign Out</li>
              </ul>
            </div>
          </div>
    
        </li>
          </ul>
    </nav>
    </body>
</html>

CodePudding user response:

I recommend using jQuery for this. It saves a lot of time and reduce code. You can get your required output in like 3-4 lines of code.

  • Related