CSS: creating a subtle fade-in animation for an address element and an image

Can you help me out with some advice? I'm working on a navigation bar that has a dropdown button. Each item in the dropdown menu has a small image with an opacity animation applied to it. When you hover over the image, it becomes visible and vice versa. My issue is figuring out how to properly associate each item with its corresponding image so that the image also shows up when hovering over the item. Should I handle this in HTML or CSS?

Here's a snippet of my code:

.dropdown-content {
  cursor: auto;
  display: none;
  width: auto;
  position: fixed;
  right: 2%;
  overflow: hidden;
  border-radius: 10px;
  background-color: #cddc39;
  font-size: large;
}


/**ODKAZY: TEXT */

.bar-item {
  border-color: #cddc39;
  color: #cddc39;
  background-color: white;
  padding: 10px 10px;
  width: fit-content;
  display: block;
  float: left;
  text-align: left;
  text-decoration: none;
}

.klik {
  vertical-align: baseline;
  text-align: left;
  border-right: 40px;
  width: 25px;
  height: 25px;
  background-color: white;
  transition: all 0, 25s ease-out;
  opacity: 0;
}

.klik:hover,
.bar-item:hover {
  opacity: 1;
}
<div class="navbar dropdown-click">
  <div class="dropdown-click">
    <button class="w3-button" onclick="myFunction()">
      <img class="topnav-pic menu" src="images/icon-navbar.png" alt="navigation button"/>
    </button>
    <div id="demo" class="dropdown-content">
      <a href="#pt_about" class="bar-item"><img class="klik" src="images/favicon.png">about me</a>
      <a href="#pt_studium" class="bar-item"><img class="klik" src="images/favicon.png">study</a>
      <a href="#pt_prace" class="bar-item"><img class="klik" src="images/favicon.png">my work</a>
      <a href="#para" class="bar-item"><img class="klik" src="images/favicon.png">hobbies</a>
    </div>
  </div>
</div>

Answer №1

It appears that you are utilizing a blend of HTML and CSS to craft a navigation bar featuring a dropdown button and images. The CSS is used to set the style for the dropdown menu and images, while the HTML defines the structure of the navigation bar.

To associate each item with its respective image, one approach could be to enclose each item along with its corresponding image within a container element like a or . As an illustration, you might adjust your HTML in the following manner:

 <div class="navbar dropdown-click">   <div class="dropdown-click">
        <button class="w3-button" onclick="myFunction()">
          <img class="topnav-pic menu" src="images/icon-navbar.png" alt="navigační tlačítko"/>
        </button>
        <div id="demo" class="dropdown-content">
          <div class="nav-item">
            <a href="#pt_about" class="bar-item"><span class="item-text">about me</span><img class="klik"
    src="images/favicon.png" alt="about me"></a>
          </div>
          <div class="nav-item">
            <a href="#pt_studium" class="bar-item"><span class="item-text">study</span><img class="klik"
    src="images/favicon.png" alt="study"></a>
          </div>
          <div class="nav-item">
            <a href="#pt_prace" class="bar-item"><span class="item-text">my work</span><img class="klik"
    src="images/favicon.png" alt="my work"></a>
          </div>
          <div class="nav-item">
            <a href="#para" class="bar-item"><span class="item-text">hobbies</span><img class="klik"
    src="images/favicon.png" alt="hobbies"></a>
          </div>
        </div>   </div> </div>

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

Using AngularJS to iterate over a collection containing various types of data elements, but specifically filtering for dates

I'm currently using ng-repeat to iterate over a collection containing fields with various data types. I specifically want to format only the date fields using something like {{mydate | date}}, but I'm unsure how to apply this only to the date fie ...

Prevent scrolling on Bootstrap columns

My webpage is built with Bootstrap and I have a layout with 4 columns on the left and 6 on the right. I want to prevent the 4 columns on the left from scrolling. How can I achieve this? I am aware of the option to use class="affix" on the left column, b ...

Is it possible to show one element while hiding others upon clicking using JavaScript?

Concept My idea is to create a website with a navigation menu where only one section is visible at a time. Each section would become visible upon clicking a specific button in the navigation bar. Challenge I attempted to achieve this using the following ...

Take charge of JavaScript over CSS using Flash technology

Optimal scenario/arrangement: Imagine a webpage with one Flash movie and a separate section containing several hyperlinks. Each of these hyperlinks is given a distinct class name, like this: Copy code <ul> <li><a href="" class="randomna ...

"Troubleshooting problems with the display:none property in a media

Encountering a small dilemma with media queries within my HTML. One of the sections in my code contains the following: <div class="header-left"> </div> <div class="header-center"> <ul> <li class="end"> ...

Showing ASP code within a DIV element (inline)

Working on setting up a 'shopping cart' feature on our website, but running into some issues with the ASP code. Does anyone have any advice to offer? In the image below, you can see that when items are added to the cart, the 'total' is ...

Dynamic presentation created with Serif software

As a newcomer to web coding and one of the older generation, I recently created a basic .swf slideshow using Serif's graphic software. However, I realized that it does not display on an Apple iPad. You can experience this issue quickly here. My questi ...

Utilize CSS to style active buttons with JavaScript

In an HTML document, the dynamic generation of divs and buttons using JavaScript can be seen in the code snippet below. <div style="background: rgb(247, 247, 247);"> <button class ="xyz" disabled="disabled">Button1</button> </div> ...

Is it possible to store Json data in a value attribute to showcase it in a form?

JSON data is coming to me and I need to input it into a text box for editing purposes. Here's an example: <div class="form-group"> <label class="control-label col-sm-2" for="email">Email:</label> <div class="col-sm-10"&g ...

Issues with the Dropdown Menu

I'm currently working on a dropdown menu and I've encountered two issues. When I hover over the links in the main navigation bar (such as 'about' and 'connect'), only the actual words are clickable, not the entire area tha ...

Tips for creating a zoomable drawing

I have been working on this javascript and html code but need some assistance in making the rectangle zoomable using mousewheel. Could someone provide guidance? var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); var width ...

When implementing Critical CSS, the Jquery function fails to execute upon loading

Currently, I am working on optimizing my website at . In an attempt to improve its performance, I decided to implement critical CSS using penthouse. The Critical CSS code can be found here, generously provided by the main developer of penthouse. However, ...

What's the best way to expand the right side of .li following a left offset of -20px

My nested list structure looks like this... https://i.sstatic.net/sggVx.png What you see is a recursive ul/li setup... <div class="family d-block"> <span class="pb-2"> <small class="text-muted">Family:</small><br> < ...

The Jquery delete button is efficiently targeting and removing all image sources and identifiers within a Multiple Upload feature

I need help creating a delete button for my ImageUploader. I can successfully select an image and display it in a div on my page, but deleting the current image is proving to be challenging. When I click on the delete button, instead of getting the id and ...

The div is blocking the background image from displaying beneath it

Currently, a work in progress, the banner on this page displays the following structure: <div id="top"> <div class="sidebox"> <div class="boxhead"> <h2>Chalets des Bouleaux</h2> </div> ...

Unable to locate the element within the specified div using xpath or css selector

I have attempted to retrieve the output "January 27" using this code: task_offer_deadline = driver.find_element_by_xpath('//*[@id="table"]/div[2]/div/a/div[1]/span[2]/div/em').text The xpath was obtained from Google Chrome Console. Here is a sn ...

Unexpectedly, the jQuery get function retrieves the entire webpage

I'm encountering difficulties when using .get requests to update elements through page load or button press. Here is the code snippet... $(document).ready(function() { //updateVariable(); $('#dannychoolink').html('<?php dan ...

Switch the class of a div using jQuery when it is clicked

I need to implement functionality where 4 different links change the class of a specific div when clicked. For example, clicking on link 1 will change the class to s1, link 2 to s2, and so on. Below is some code that I have been working on, however, I am ...

Having trouble embedding the video in an iframe. Any tips on how to make it work?

I have encountered an issue while trying to embed a video in my WordPress site using an iframe. The video is not displaying completely on the page, with only the left part visible and the rest being cut off. Here is the code I am currently using: <P A ...

Input field modified upon focus

I am currently using selectize js in my section to create a select box. My goal is to make the input editable after selecting an option when it is focused on. Check out the live demo: live demo HTML <label>Single selection <select id=" ...