"Enhancing button design with an adjacent image - the step-by

I am having an issue with my hover dropdown menu where the image is not displaying properly in the main button. When I hover over the user12345 button, the image appears on the left side just before the hover shadow. Below is the code snippet for the dropdown nav. Any help would be greatly appreciated.

HTML:

body {
    font-family: arial;
    margin: 0;
    padding: 0;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
}

.dropdown {
    margin: 0 auto;
    
}

nav {
   height: 77px;
   text-decoration:none;
}

ul {
    
    padding: 0;
    margin: 0 auto;
    float: right;
    margin-right:30px;
   
}

 ul li {
    
    position: relative;
    list-style: none;
    display: inline-block;
   
    background: #343a40;
   

}

ul li a {
    display: block;
   padding: 0 15px;
    color: #D3D3D3;
    text-decoration: none;
    line-height: 60px;
    font-size: 20px;
    

}
ul li a:hover {
    background: #3b4044;
    text-decoration:none;
    opacity: 1 !important; 
}


ul ul {
    position: absolute;
    top: 62px;
    display: none;
    background: #343a40;
}

li:hover ul {
    display: block;
    text-decoration:none;
    background: #343a40 !important;
  }



h5 {
    margin-bottom: .5rem;
    font-family: inherit;
    
    line-height: 1.2;

}

b{
    font-weight: 542;
}


ul li:hover > ul {
 display: block;
}

ul ul li {
    width:150px;
    float: none;
    display: list-item;
    position: relative;
    
}

.user {
margin-left: 20px; }
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">

<div class="dropdown  "> 
    <nav class="navbar navbar-expand-md bg-dark navbar-dark py-3"> 

            <a id="name" href="index.html">
                    <img src="images/headericon.png" width="40" height="40" class="d-inline-block align-top"   alt="">
                
                </a>
                <h5 style="font-size: 22px" class="ml-2 text-info mt-2"><b>Gobble</b></h5>
            
                       

                             <ul> 
                                    <img src="images/noprofile.png" class="user " style="width:48px;height:48px">
                                 <li><a href="#"> &nbsp; User12345</a>
                                 <ul>
                            <li><a href="#" class="nav-item">Profile</a></li>
    </ul>
    </nav> </div>

Answer №1

Take a look at the solution provided below, it should help resolve your issue.

body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
}

.dropdown {
    margin: 0 auto;
    
}

nav {
   height: 77px;
   text-decoration:none;
}

.dropdown ul {
    margin:0;
    padding: 0;
    margin: 0 auto;
    float: right;
    margin-right:30px;
   
}

 ul li {
    
    position: relative;
    list-style: none;
    display: inline-block;
   
    background: #343a40;
   

}

ul li a {
    display: inline-block;
   padding: 0 15px;
    color: #D3D3D3;
    text-decoration: none;
    line-height: 60px;
    font-size: 20px;
}



ul li a img { 
 margin-right: 20px;
}

ul li a:hover {
    background: #3b4044;
    text-decoration:none;
    opacity: 1 !important; 
}


ul ul {
    position: absolute;
    top: 62px;
    display: none;
    background: #343a40;
}

li:hover ul {
    display: block;
    text-decoration:none;
    background: #343a40 !important;
  }



h5 {
    margin-bottom: .5rem;
    font-family: inherit;
    
    line-height: 1.2;

}

b{
    font-weight: 542;
}


ul li:hover > ul {
 display: block;
}

ul ul li {
    width:150px;
    float: none;
    display: list-item;
    position: relative;
    
}

.user {
margin-left: 20px; }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">

<div class="dropdown"> 
    <nav class="navbar navbar-expand-md bg-dark navbar-dark py-3"> 
        <a id="name" href="index.html">
            <img src="images/headericon.png" width="40" height="40" class="d-inline-block align-top" alt="">
        </a>
        <h5 style="font-size: 22px" class="ml-2 text-info mt-2"><b>Gobble</b></h5>
        <ul> 
            <li>
                <a href="#"><img src="images/noprofile.png" class="user" style="width:48px;height:48px">User12345</a>
                <ul>
                    <li><a href="#" class="nav-item">Profile</a></li>
                </ul>
            </li>
        </ul>        
    </nav> 
</div>

Answer №2

It appears that I have grasped your message accurately. To achieve the desired result, you need to include the img tag within your a tag.

<div class="dropdown  "> 
    <nav class="navbar navbar-expand-md bg-dark navbar-dark py-3"> 
            <a id="name" href="index.html">
                    <img src="images/headericon.png" width="40" height="40" class="d-inline-block align-top"   alt="">  </a>
<h5 style="font-size: 22px" class="ml-2 text-info mt-2"><b>Gobble</b></h5>

      <ul> 
        
        <li><a href="#"><img src="images/noprofile.png" class="user "
             style="width:48px;height:48px;"> &nbsp; User12345</a></li>
          <ul>
            <li><a href="#" class="nav-item">Profile</a
            </li>
         </ul>
        </ul>
    </nav> 
</div>

To align the img tag properly next to the a tag, you can apply the position:relative style.

An alternative approach is using flexbox, which is a versatile tool for positioning elements side by side. You may learn more about it on w3schools or css-tricks:

https://www.w3schools.com/css/css3_flexbox.asp

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

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

Tips for appending a new row to the ToolBarContent within a MudTable

I am currently facing a challenge in adding a second row with MudChipSet for my Filter within the ToolBarContent of MudTable. My main concern is ensuring that the first row remains unaffected by this addition. Below is my existing code, and I would appreci ...

Issues with Carousel Plugin Functionality

**Hey everyone, I could really use some help. As a beginner coder, please forgive any errors in my code. I am currently working on a webpage where I need to incorporate a carousel plugin within a panel body to display the latest photos. The code provided ...

How can I connect the box using the Interactive Picture jQuery tool?

When using the Interactive picture jQuery, I have the following code snippet within my document: jQuery(document).ready(function(){ $( "#iPicture6" ).iPicture({ animation: true, animationBg: "bgblack", animationType: "ltr-slide ...

Store the injected HTML within a PRE tag as a variable

My question pertains to a DIV HTML element that is responsible for displaying some HTML content from a variable: <div contenteditable="true" ng-bind-html="renderHtml(currentOperation.description)" ng-model='currentOperation.description&a ...

Guide on triggering a bootstrap popup modal using a TypeScript file

I am currently working on an Angular project where I need to launch a popup modal when my function is called. I came across an example on w3schools, but it only contains the HTML logic to open the popup. What I want to achieve is to open the popup from th ...

Fonts in Internet Explorer are displayed correctly only until the webpage has finished loading

I've encountered a very peculiar issue on a website I'm currently working on: While the page is loading, the fonts I've utilized (Georgia and Bebas Neue) appear correctly. However, once the page finishes loading, they switch to default sans ...

Choose an input that is not grouped with the rest

I am facing an issue where I need to group these three inputs together as one continuous form. However, there seems to be a problem with the select input not aligning correctly with the rest of the form. Is there something that I might be doing wrong? & ...

SQL Delete rows from Table

I am dealing with an issue where a table displaying notices has a clear option next to each row, but when the clear button is clicked nothing happens. The setup involves a button that triggers a clear function. What could be causing this problem? <bu ...

issues with the functionality of bootstrap modal

I'm currently working on a project where I need to set up a modal popup using bootstrap. The website I'm working on is organized by departments, so the only part of the code that I have control over is the main body of the site. I have included t ...

Aligning multiple items to the right using Flexbox

While it's common knowledge how to align one item to the right in flexbox, what about aligning multiple items, like the last two elements, to the right and the rest to the left? Take a look at this example where I want elements with the class .r to be ...

I am experiencing an issue with the button that is supposed to link to a section within the same page while it is located within the jumbotron. Interestingly, the button

I'm facing an issue with a button placed inside my jumbotron. The button is supposed to link to a specific section within the page, but it's unresponsive. Even hovering over it shows no interaction. Strangely, if I move the button outside of the ...

What is the best way to set the width of an inner element as a percentage of the Body's width?

Applying a percentage width to any inner element of a page will typically result in that element taking a percentage of its parent container's width. Is there a way to specify the width of an inner element as a percentage of the overall Body width, r ...

Modifying the CSS class of an element does not produce the desired effect after altering its styles using JavaScript

html: <input id="myinput" class="cinput" type="image" src="http://www.foodwater.org.au/images/triple-spiral-3-small-button.jpg"/> <br><br><br><br> <button id="s">set to visible class</button> <button id="h"> ...

Trying to extract data from the ASX website's table using web scraping techniques

My goal is to extract the current stock value from the ASX.com.au website. Specifically, I am interested in retrieving the current ASX value, which can be located here. The value I am looking for is in the second td from the left, currently standing at 30 ...

Any advice on how to horizontally center my css slideshow?

After using jsfiddle for the file, I encountered an issue with centering the slideshow at the bottom. Despite my efforts, it remains aligned to the left margin. Check out the end results here: https://jsfiddle.net/n6kae2rn/ https://jsfiddle.net/n6kae2rn ...

Elements in Motion

Working on a parallax effect, I've managed to assign unique scroll speeds to (almost) every element. Moreover, these elements are programmed not to activate their scroll speed until they enter the viewport. Below is the JavaScript code for trigger co ...

Is there a way to insert a dot after every two digits in a text field using Javascript upon keypress?

When inputting a 4-digit number (e.g. 1234) in my text field with value format 00.00, I want it to automatically adjust to the 12.34 format. How can I achieve this behavior using JavaScript on keyup event? ...

Looking for advice on designing a unique Gallery layout using CSS?

Tasked with converting various layouts, some of which utilize a specific layout pattern (refer to the image below.) I'm seeking advice on the most efficient way to use CSS to display a list of images in this manner without dividing items into separate ...

What is the reason behind the varying display of values?

When trying to set a value using the input tag, I encountered an issue. For example, if I type 1000.0009 into the input text, the valid value should be 1000.0001. However, the value displayed in the input tag is incorrect, while the value outside the tag i ...

Tips on accessing PDF files in a new window and downloading them within a blank pop-up screen

I am currently attempting to replicate a specific situation in order to debug an issue. In this scenario, I need to click on a date that will open a new pop-up window. However, the window is blank and a PDF file is downloaded within that window. Unfortunat ...