<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dismas Banda</title>
    <description>The latest articles on DEV Community by Dismas Banda (@bandadismas).</description>
    <link>https://dev.to/bandadismas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1011623%2Fa50b0ca7-274b-44a5-9145-9d92e6da875b.jpeg</url>
      <title>DEV Community: Dismas Banda</title>
      <link>https://dev.to/bandadismas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bandadismas"/>
    <language>en</language>
    <item>
      <title>Dropdown Hover Menu + Underline Hover Effect</title>
      <dc:creator>Dismas Banda</dc:creator>
      <pubDate>Mon, 23 Jan 2023 13:31:52 +0000</pubDate>
      <link>https://dev.to/bandadismas/dropdown-hover-menu-underline-hover-effect-16i</link>
      <guid>https://dev.to/bandadismas/dropdown-hover-menu-underline-hover-effect-16i</guid>
      <description>&lt;p&gt;In this tutorial, we are going to create an underline hover effect and a dropdown menu on the menu items.&lt;/p&gt;

&lt;p&gt;First, let's create our navbar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;nav&amp;gt;
        &amp;lt;ul&amp;gt;
            &amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;About Me&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;Languages&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;Frameworks&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us now style the navbar so that it sits in the middle and looks pretty.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nav {
    display: flex;
    justify-content: center;
    background-color: #fff;
    box-shadow: 0 10px 40px rgba(159, 162, 177, .8);
}

nav ul {
    display: flex;
    list-style-type: none;
}

.menu-item {
    padding: 1rem 2rem;
    color: #83818c;
    position: relative;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We choose display flex for both the &lt;em&gt;nav&lt;/em&gt; and &lt;em&gt;ul&lt;/em&gt; so that all the items can sit nicely in a row. We remove the bullet points from the unordered list by setting the &lt;em&gt;list-style-type&lt;/em&gt; to &lt;em&gt;none&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the Underline hover effect
&lt;/h2&gt;

&lt;p&gt;To add the underline hover effect we need to use the ::before selector instead of the bottom border. This is because changing the border while the page has loaded will change the size of the elements which may cause the html elements to rearrange.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.menu-item:before {
    content: "";
    height: 3px;
    position: absolute;
    background-color: #00ABC7;
    bottom: 0;
    left: 0;
    width: 100%;
    border-radius: 8px;
    transform: scaleX(0); 
    transition: transform 0.3s ease;
}

.menu-item:hover:before {
    transform: scaleX(1);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add &lt;em&gt;transform-origin&lt;/em&gt; so that the underline transforms from either left or right instead of the center as in our case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the dropdown Menu
&lt;/h2&gt;

&lt;p&gt;First, let's add the submenu items to our html. Each submenu item sits under the menu item under an unordered list with a class of submenu.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;About Me&amp;lt;/a&amp;gt;
                &amp;lt;ul class="submenu"&amp;gt;
                    &amp;lt;li&amp;gt;Education&amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;Experience&amp;lt;/li&amp;gt;
                &amp;lt;/ul&amp;gt;
            &amp;lt;/li&amp;gt;
            &amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;Languages&amp;lt;/a&amp;gt;
                &amp;lt;ul class="submenu"&amp;gt;
                    &amp;lt;li&amp;gt;Java&amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;JavaScript&amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;Python&amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;C/C++&amp;lt;/li&amp;gt;
                &amp;lt;/ul&amp;gt;
            &amp;lt;/li&amp;gt;
            &amp;lt;li class="menu-item"&amp;gt;&amp;lt;a href="#"&amp;gt;Frameworks&amp;lt;/a&amp;gt;
                &amp;lt;ul class="submenu"&amp;gt;
                    &amp;lt;li&amp;gt;ExpressJs&amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;ReactJs&amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;Django&amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;Flask&amp;lt;/li&amp;gt;
                &amp;lt;/ul&amp;gt;
            &amp;lt;/li&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then give the submenu class a &lt;em&gt;display&lt;/em&gt; of &lt;em&gt;flex&lt;/em&gt; and a &lt;em&gt;flex-direction&lt;/em&gt; of &lt;em&gt;column&lt;/em&gt; to properly align them. We hide the submenu by setting its &lt;em&gt;visibility&lt;/em&gt; to &lt;em&gt;hidden&lt;/em&gt; and &lt;em&gt;opacity&lt;/em&gt; to &lt;em&gt;0&lt;/em&gt;. We'll show the submenu when we hover over the menu items by setting its &lt;em&gt;visibility&lt;/em&gt; value to &lt;em&gt;visible&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.submenu {
    display: flex;
    flex-direction: column;
    position: absolute;
    left: 0;
    top: 35px;
    width: 100%;
    padding: 0;
    background-color: #fff;
    opacity: 0;
    visibility: hidden;
    transform: translateY(50px);
    transition: all 0.5s ease;
}

.menu-item:hover .submenu {
    visibility: visible;
    opacity: 1;
    top: 60px;
    transform: translateY(0px);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that, we have a smooth underline hover effect and dropdown hover menu. You can experiment with the code in the codepen below or you can check it out on github by following this &lt;a href="https://github.com/bandadismas/hover-menu"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Dizmas/embed/LYBQmQO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>hovereffects</category>
      <category>dropdownmenu</category>
    </item>
  </channel>
</rss>
