Including a drop-down arrow or triangle next to the initial button

In the navigation bar displayed below

https://codepen.io/shaswat/pen/XzpRXL

Is it possible to create a down triangle or arrow next to the "home" link, which changes direction upward when hovered over? How can this be achieved without modifying any HTML elements (such as input type and value)? Additionally, no Bootstrap should be used.

  1. No modifications to the existing HTML structure are allowed, but new elements can be added without disrupting the current appearance of the navigation bar.

  2. Avoid utilizing Bootstrap for this task.

HTML

<div id='cssmenu'>
<ul>
   <li ><input type=submit value=home>
     <ul>
         <li><input type=submit value=home1 /></li>
         <li><input type=submit value=home2 /></li>
         <li><input type=submit value=home3 /></li>
      </ul>


   </li>
   <li><input type=submit value=products class=active />

   </li>
   <li><input type=submit value=about />
   </li>
   <li><input type=submit value=Contact /></li>
</ul>
</div>

CSS

#cssmenu > ul ul input{
  border-top: 1px solid;  
}
#cssmenu input {
  padding: 0;
  border-right: 1px solid;
  border-top: none;
  border-bottom: none;
  border-left: none;
  background: none;
    border-radius : 0px 5px 0px 0px;
}
/* Menu CSS */#cssmenu,
#cssmenu > ul {
  background: black;  
  padding-bottom: 3px; 
  border-radius: 5px 5px 5px 5px;
}
#cssmenu:before,
#cssmenu:after,
#cssmenu > ul:before,
#cssmenu > ul:after {
  content: "";
  display: table;
  box-sizing: border-box;
}
#cssmenu:after,
#cssmenu > ul:after {
  clear: both;
}
#cssmenu {
  width: auto;
  zoom: 1;
}
#cssmenu > ul {
  background: blue;
  margin: 0;
  padding: 0;
  position: relative;
}
#cssmenu > ul li {
  margin: 0;
  padding: 0;
  list-style: none;
}
#cssmenu > ul > li {
  float: left;
  position: relative;
}
#cssmenu > ul > li > input {
  padding: 12px 25px;
  display: block;
  color: white;
  font-size: 13px;
  text-decoration: none;  
  text-shadow: 0 -1px 0 #0d0d0d;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.7);

}
#cssmenu > ul > li:hover > input {
  background: red;
  -webkit-transition: all 0.40s ease-in-out;
  -moz-transition: all 0.40s ease-in-out;
  -ms-transition: all 0.40s ease-in-out;
  transition: all 0.40s ease-in-out;
}

#cssmenu > ul > li.active > input,
#cssmenu > ul > li > input.active {
  background: black;
  color:#fff;
}
/* Childs */
#cssmenu > ul ul {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  top: 40px;
  background: green;
  margin: 0;
  padding: 0;
  z-index: -1;
  box-shadow: 5px 5px 5px #808080;
}
#cssmenu > ul li:hover ul {
  opacity: 1;
  visibility: visible;
  margin: 0;
  color: #fff;
  z-index: 2;
  top: 40px;
  left: 0;
}

#cssmenu > ul ul li {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
#cssmenu > ul ul li input {
  padding: 12px ;
  display: block;
  color: white;
  font-size: 14px;
  text-decoration: none;
  width: 150px;
  border-left: 4px solid transparent;
  -webkit-transition: all 0.30s ease-in-out;
  -moz-transition: all 0.30s ease-in-out;
  -ms-transition: all 0.30s ease-in-out;
  transition: all 0.30s ease-in-out;
}
#cssmenu > ul ul li input:hover {
  border-left: 10px solid #d64e34;
  background: grey;
}
#cssmenu > ul ul li input:active {
  background: green;
}

Answer №1

Utilize font awesome icons with the classes fa-caret-up and fa-caret-down, along with JavaScript functions onmousehover and onmouseout to toggle the caret icon up and down.

Make sure to import the necessary Font Awesome and jQuery libraries in your project.

<a onmouseover="changecaretup()" onmouseout="changecaretdown()" >home <i id="caret" class="fa fa-caret-down" aria-hidden="true"></i></a>

JavaScript:

function changecaretup(){
    $("#caret").removeClass("fa-caret-down");
    $("#caret").addClass("fa-caret-up");
}

function changecaretdown(){
    $("#caret").removeClass("fa-caret-up");
    $("#caret").addClass("fa-caret-down");
}

Answer №2

Finally accomplished it on my own using HTML unicode method

https://codepen.io/shaswat/pen/XzpRXL

Utilized only CSS to create a smooth transition effect between the up arrow and down arrow

HTML

<div id='cssmenu'>
<ul>
   <li ><input type=submit value='Home'/>
     <div class="downArrow"> &#9660; </div>
     <div class="upArrow"> &#9650; </div>     
     <ul>
         <li><input type=submit value=home1 /></li>
         <li><input type=submit value=home2 /></li>
         <li><input type=submit value=home3 /></li>
      </ul>


   </li>
   <li><input type=submit value=products class=active />

   </li>
   <li><input type=submit value=about />
   </li>
   <li><input type=submit value=Contact /></li>
</ul>
</div>

CSS

#cssmenu > ul ul input{
  border-top: 1px solid;  
}
#cssmenu input {
  padding: 0;
  border-right: 1px solid;
  border-top: none;
  border-bottom: none;
  border-left: none;
  background: none;
    border-radius : 0px 5px 0px 0px;
}
/* Menu CSS */#cssmenu,
#cssmenu > ul {
  background: black;  
  padding-bottom: 3px; 
  border-radius: 5px 5px 5px 5px;
}
#cssmenu:before,
#cssmenu:after,
#cssmenu > ul:before,
#cssmenu > ul:after {
  content: "";
  display: table;
  box-sizing: border-box;
}
#cssmenu:after,
#cssmenu > ul:after {
  clear: both;
}
#cssmenu {
  width: auto;
  zoom: 1;
}
#cssmenu > ul {
  background: blue;
  margin: 0;
  padding: 0;
  position: relative;
}
#cssmenu > ul li {
  margin: 0;
  padding: 0;
  list-style: none;
}
#cssmenu > ul > li {
  float: left;
  position: relative;
}
#cssmenu > ul > li > input {
  padding: 12px 30px;
  display: block;
  color: white;
  font-size: 13px;
  text-decoration: none;  
  text-shadow: 0 -1px 0 #0d0d0d;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.7);

}
#cssmenu > ul > li:hover > input {
  background:violet;
  -webkit-transition: all 0.40s ease-in-out;
  -moz-transition: all 0.40s ease-in-out;
  -ms-transition: all 0.40s ease-in-out;
  transition: all 0.40s ease-in-out;
}

#cssmenu > ul > li.active > input,
#cssmenu > ul > li > input.active {
  background: black;
  color:#fff;
}
/* Childs */
#cssmenu > ul ul {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  top: 40px;
  background: green;
  margin: 0;
  padding: 0;
  z-index: -1;
  box-shadow: 5px 5px 5px #808080;
}
#cssmenu > ul li:hover ul {
  opacity: 1;
  visibility: visible;
  margin: 0;
  color: #fff;
  z-index: 2;
  top: 40px;
  left: 0;
}

#cssmenu > ul ul li {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
#cssmenu > ul ul li input {
  padding: 12px ;
  display: block;
  color: white;
  font-size: 14px;
  text-decoration: none;
  width: 150px;
  border-left: 4px solid transparent;
  -webkit-transition: all 0.30s ease-in-out;
  -moz-transition: all 0.30s ease-in-out;
  -ms-transition: all 0.30s ease-in-out;
  transition: all 0.30s ease-in-out;
}
#cssmenu > ul ul li input[type=submit]:hover {
  border-left: 10px solid #d64e34;
  background: grey;
}
#cssmenu > ul ul li input[type=submit]:active {
  background: green;
}

.downArrow { 
    display: block;  
    position: absolute;
    top: 12px;
    right: 2px;  
    color:white;
}

.upArrow { 
  display: none;
    position: absolute;
    top: 12px;
    right: 2px;  
  color:white;    
}

#cssmenu li:first-child:hover .upArrow{
   display: block;
}

#cssmenu li:first-child:hover .downArrow{
   display: none;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When a block is clicked, jQuery will reveal that block while hiding the others sequentially, starting with the second block, then the third, and finally the fourth

Creating a navigation menu with 4 blocks can be a bit tricky, especially when trying to show one block at a time upon click. Here is my code attempt, but unfortunately it's not working as expected. I would greatly appreciate any help or suggestions on ...

Obtain an Array Containing all Current Page Paths in Gatsby

While creating a custom `404` page in Gatsby, I am looking to provide users with recommended similar path names based on the non-existent path they have accessed. Can anyone guide me on how to retrieve an array of all the current pages on my website? ...

What purpose does the div tagged with the class selection_bubble_root serve in Nextjs react?

Just starting out with Nextjs and setting up a new Next.js React project. I used create-next-app to initialize the code base, but then noticed an odd div tag with the class 'selection_bubble_root' right inside the body. Even though its visibility ...

Container will keep items from spreading out

Experiencing an issue with the card layout in my weather dashboard app. The cards within a container are not spreading out evenly to match the 100% width of the header. I want the container with the 5 cards to be the same width as the header and wrap prope ...

What is the strategy used by jQuery to select elements by class name?

Is there a "getElementsByClass" function in JavaScript? If not, how does jQuery manage to do it without looping through all elements which would be very inefficient? Also, how can I specify CSS for elements with two or more classes? <a class="one two ...

creating a table displaying data in a horizontal format sourced from ajax/json transformation

I am currently working on a piece of code that retrieves a list of IDs from local storage and compares them to IDs in a JSON file. If there is a match, the corresponding data is displayed in a table. However, I am facing an issue with my table layout as i ...

Error during compilation due to a missing parenthesis in the loop structure

I've been experimenting with creating a carousel using just html and css, without any Javascript. I've been exploring resources on the web and following tutorials to achieve this goal. However, I've encountered an issue. I created a mixin l ...

Missing arrow icon in Bootstrap 4 navbar menu and sub menu

I am attempting to use the navbar component from Twitter Bootstrap 4 with a nested sub menu, but the arrow in the menu item that has a sub menu is not appearing at all, and I am unsure why. Here is where the arrow appears: https://i.sstatic.net/J6xI4.jpg ...

Converting nested json objects to HTML format with the help of jQuery

I've been wracking my brain on this issue for quite some time and I just can't seem to crack it. After posting a question, I received some helpful answers and decided to implement the code provided in the second response (be sure to check out my ...

The inline feature of the Bootstrap input group addon is not being utilized

Check out my code snippet here: http://www.bootply.com/iR1SvOyEGH <form> <div class="form-group"> <label for="inputEmail">Company Name</label> <input type="text" class="form-control"> <span class="input-gro ...

Tips for implementing personalized/modified CSS on Vuetify components?

Let's say I've included the v-text-field component from Vuetify in my Vue component as shown below: <v-text-field v-model="email" name="email" type="email" color="#90C143" label="Email"> Upon inspecting the element, it generates regular H ...

Execute a PHP script upon button click without the need to refresh the page

I'm facing an issue with integrating PHP and JavaScript. Objective: To execute a .php script when the event listener of the HTML button in the .js file is triggered without causing the page to reload. Expected outcome: On clicking the button, the PH ...

How to display content in separate divs using jQuery hover functionality

I'm in the process of creating my online portfolio by using bootstrap and jquery. I have a series of images arranged side by side with each other, and I want to make the description for each image appear when that specific image is hovered over. Each ...

Avoid HTML code injection in an ExtJS4 grid by properly escaping the href attribute

I am facing an issue with escaping HTML in my Extjs grid. I have used the following configuration : return Ext.String.htmlEncode(value); In the renderer of my column, this method works perfectly for simple HTML tags like h1, b, i, etc. However, if I in ...

What is the process for customizing styles within the administrative area of a Wordpress website, such as modifying the shade of the admin toolbar?

Can someone provide guidance on changing the color of a specific dashicon in the WordPress admin toolbar? I've tried adjusting the color using the browser inspector, but I can't seem to get it to work when I add the code to my stylesheet. #admin ...

Whenever I select the checkbox, it causes my Bootstrap modal pop-up to close unexpectedly

I have created a form in a modal popup with 5 checkboxes where autopostback is set to true. Whenever I click on one of the checkboxes, the modal popup automatically closes. I have also used an update panel and included ScriptManager.RegisterStartupScrip ...

Is it recommended to add the identical library to multiple iFrames?

Here's a quick question I have. So, my JSP page has 4 different iFrames and I've included JQuery UI libraries in it: <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> <script src="http://c ...

What is preventing my image from moving upwards?

I've been struggling to move this image up, despite trying several methods. I really want it to be aligned horizontally with the PV picture. I need the HP image to be moved directly upwards so that it aligns horizontally with the PV image. This is t ...

Aligning a DIV using javascript

Hey everyone, I'm encountering an issue with the JavaScript on my website. I'm struggling to center the div in order to properly display the image I click on. It seems to work fine on the second attempt, but on initial click, the div always appea ...

I'm currently utilizing CSS GRID to create a map layout, but I'm encountering an issue where the layout is not filling the entire screen. I'm wondering how I can achieve this in Angular

Here is the unique html code snippet for a layout that dynamically creates grids using json input: <!DOCTYPE html> <html lang="en"> <head> <title>Booking Page</title> </head> <body> <div ...