Using HTML and CSS to include an image alongside each item in my menu list

I'm looking to enhance my list menu buttons by adding a small image in front of each item text (link1,2,3,4) with 5 pixels padding on the left. I want the image to remain visible even when hovering over the button, but I'm struggling to figure out how to achieve this.

Here's an example image you can use:

This is the code for my button list:

HTML:

<div id="menupadding">
<div id="menu">
 <ul>
<li><a href="#">link1</a></li>
<li><a href="#">link2</a></li>
<li><a href="#">link3</a></li>
<li><a href="#">link4</a></li>
 </ul>
</div>
</div>

CSS:

#menupadding {
    padding-top: 100px;
    padding-left: 302px;
}

#menu {
    margin:0;
    padding:0;
}

#menu li{
    display:block;
    list-style:none;
    padding-bottom:1px;
}

#menu ul{
    width: 140px;
    margin:0;
    padding:1px;    
}

#menu li a{
    display:block;
    font-family:Tahoma, Geneva, sans-serif;
    font-size:12px;

    color:#ffffff;

    text-decoration:none;

    background-color: #376596;

    padding-top:2px;
    padding-left: 20px;
    padding-bottom: 2px;    
}

#menu li a:hover{
    font-size:12px;
    color:#ffffff;
    padding-left: 40px;

    background-image: linear-gradient(bottom, rgb(0,65,139) 14%, rgb(33,42,66) 89%, rgb(0,0,0) 100%);
    background-image: -o-linear-gradient(bottom, rgb(0,65,139) 14%, rgb(33,42,66) 89%, rgb(0,0,0) 100%);
    background-image: -moz-linear-gradient(bottom, rgb(0,65,139) 14%, rgb(33,42,66) 89%, rgb(0,0,0) 100%);
    background-image: -webkit-linear-gradient(bottom, rgb(0,65,139) 14%, rgb(33,42,66) 89%, rgb(0,0,0) 100%);
    background-image: -ms-linear-gradient(bottom, rgb(0,65,139) 14%, rgb(33,42,66) 89%, rgb(0,0,0) 100%);

    background-image: -webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.14, rgb(0,65,139)),
        color-stop(0.89, rgb(33,42,66)),
        color-stop(1, rgb(0,0,0))
);
}

Answer №1

Update the CSS code below with this revised version

#menu li a{
    display:block;
    font-family:Arial, Helvetica, sans-serif;
    font-size:14px;

    color:#ffffff;

    text-decoration:none;

    background-color: #376596;

    padding-top:4px;
    padding-left: 25px;
    padding-bottom: 4px; 


     background-image:url('http://images.subeta.net/smilies/6398_emoticon_smile.gif');
        background-repeat:no-repeat;

}

For demonstration, view it live here

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

How do I utilize ng-if in Angular to apply to only the parent tag and not the following markup?

Suppose I have two HTML elements with the same tag but different properties. How can I conditionally select between them? Here are the two tags in question: <a ui-sref="root.one(::{param: value})"> <a target="_blank" href="{{::model}}"> I ne ...

Guide to creating a see-through right border for vertical tabs using Bootstrap 4

I have been working on creating vertical tabs in Bootstrap 4 and have almost completed the task. However, I am facing an issue with making the right border of the active tab transparent. Despite several attempts, I have not been successful in achieving thi ...

What is the best way to allow a container div to only show horizontal overflow, without relying on "display:inline-block" for its inner divs?

My coding challenge involves dynamically creating nested <div> elements within another <div> when a button is clicked. Upon clicking the button, a new inner <div> with a unique id is generated inside the outer <div>, each possessing ...

What is the technical process behind conducting A/B testing at Optimizely?

I'm currently experimenting with Google Analytics and Content Experiments for A/B testing on my website, but I'm encountering some challenges in making it seamless. To utilize the Google API properly, a few steps need to be taken. Firstly, I nee ...

Align an image in the middle with a heading

I am currently working on aligning a picture and heading in a header section. My goal is to center both elements, with the picture being twice as tall as the heading. So far, I have them stacked one above the other: .body { font: 15px/1.5 Arial, Helveti ...

Is it possible to include a relative URL with a different port number in a hyperlink?

Is it possible to link to a different port number on the same server without using Javascript or server-side scripting, especially if the hostname is unknown? For example: <a href=":8080">Check out the other port</a> (Note that this example ...

Vuetify - Best practices for vertically aligning rows in a v-treeview component

Just getting started with Vue js, so pardon me if this is a silly question. I've scoured the internet and can't seem to find a solution. I'm working on a v-treeview displaying a folder structure, with descriptions of each folder in a separa ...

The issue with the search box not being correctly displayed on Google CSE using Twitter Bootstrap

Having an issue with the Google Custom Search (CSE) as it is not displaying the search box and button correctly. I am using Twitter Bootstrap v3.1.0. <script> (function() { var cx = '009077552906670546181:2ufng0dmsos'; ...

Interested in editing videos with OpenCV?

Using OpenCV, I am attempting to apply a Gaussian Blur to a live video stream. The process involves capturing a frame, applying the blur, and then displaying the modified frame on the screen. Strangely, however, the video becomes stuck on the first frame o ...

Struggling with choosing a specific subcategory from the menu

Having trouble navigating through the submenus? Here's a solution! *,body{ margin: 0; padding: 0; box-sizing: border-box; list-style-type: none; font- ...

SyntaxError: Identifier was not expected

I am currently working on a function that involves a table of rows with edit buttons. Whenever the edit button is clicked, the following function is called and I encounter this error: Uncaught SyntaxError: Unexpected identifier The error seems to be poin ...

Submitting Form Data from Multiple Dropdown Boxes using PHP $_POST

I have been using multiple dropdown boxes with data from a MySQL database, but I have encountered an issue when trying to $_POST the information. Below is the code snippet I am using: <?php try { $dbo = new PDO('mysql:host=' . $dbhost_n ...

Display the text above overlapping div elements

I need a design where one div overlaps another, but the text inside the overlapping div must still be visible. <div class='box1'> <div class='sendAbove'> This message should remain visible in this div </div> ...

Effortlessly glide to the form and center your attention on the textarea

Upon clicking the link, I aim to accomplish three tasks: Implement smooth scrolling down to #form Automatically focus on the textarea for immediate message writing Add extra top margin to account for a fixed top bar on the website. <a class="link" ...

The presence of Bootstrap remains hidden unless space is designated for it

Question about Bootstrap 5.1.3: Is there a way to hide elements on a page using the bootstrap class ".invisible" without allocating space for them? Currently, when the elements are set to visible using the class ".visible", they occupy space on the page ...

What is the method for accessing font sizes through CSS code?

Why is the font size value in CSS returning incorrect values? Check out this jsFiddle example Here's the HTML code snippet: <div id="test">TEXT</div> <div id="test2">TEXT2</div> Now, take a look at the CSS: #test{ font ...

Seeking a precise placement, must find a CSS-only answer

After spending two days experimenting with different CSS styles like absolute positioning, inline/inline-block display, and flex display, I have yet to find a solution for styling a timestamp's label position using pure CSS. https://i.stack.imgur.com ...

Struggling with vertical alignment issues in a div element

Can anyone help me figure out how to vertically align a div? I've been struggling with it and can't seem to get it right. What am I missing? body { border: 1px solid red; height: 500px; } #contactUs { border: 1px solid blue; vertical-align: bo ...

Guide to implementing a radial gradient using CSS on a cairo surface in gtk4

I am attempting to create a circular shape on a Gtk4 GtkDrawingarea using CSS. The goal is to then save the circle as a PNG file upon clicking on it. However, I am encountering difficulties in transferring the drawing (gradient) from the drawing area to a ...

Angular class change on scroll

HTML <ion-app> <ion-content> <div #scrolledToElement class="second-block" [ngClass]="flag ? 'red' : 'green' "></div> </ion-content> </ion-app> CSS .second-block { margin ...