I want each <li> element to have a unique background image

I'm a beginner in HTML and I have created a simple webpage with a div called "navbar" containing a list ('ul') of buttons. Each button should have a different background image, which I created in Photoshop. I tried giving each 'li' an id and manipulating them in CSS but it didn't work. Can anyone help me achieve this? If more information is needed, please let me know.

Thank you!

<head>
    <link rel="stylesheet" type="text/css" href="main.css" />

    <title>Resonance Recording & Rehearsals</title>
</head>

<body>
    <div id="wrapper">

        <div id="header">
        </div>


        <div id="navbar">
            <ul>
                <li id="gallerybutton"> <a href="gallery.html"> Gallery </a> </li> 
                <li id="homebutton"> <a href="index.html"> Home </a> </li> 
                <li is="about_usbutton"> <a href="about_us.html"> About Us </a> </li> 
            </ul>
        </div>

        <div id="cgiform">
        </div>

        <div id="footer">
        </div>

    </div>
</body>

CSS:

body{
background-image:url("mainbg.png");
background-repeat:no-repeat;
background-color:#000000;
background-size: 100%;

height: 100%; 
width: 100%;

}

#header{

background-image:url("mainheader.png"); 
height: 146px;
width: 1000px;
margin: 0px auto;
background-size: 100%;
}

#navbar{

background-image:url("mainnavbar.png");
height: 88px;
width: 1000px;
margin: 0px auto;
background-size: 100%;

}

ul{
list-style-type: none;
list-style-position: initial;
list-style-image: initial;
padding: 28px 0px 0px 40px; /* padding syntax = top right bottom left */
}

li{
color: #fff;
display:inline; 

}

a:link {
text-decoration:none;
color: #fff;
}

a:visited {
text-decoration:none;
color: #fff;
}

a:hover {
text-decoration:underline;
color: #fff;
}

a:active {
text-decoration:underline;
color: #fff;
}

#navbar #gallerybutton{
background-image:url("gallery.png") no-repeat top center;
}

Answer №1

There are a couple of important things to note here. First, nesting the li ID's within #navbar is unnecessary since ID's are unique elements on their own. This can cause confusion and is not needed, especially considering there will only ever be one instance of #gallerybutton.

Each ID requires specific CSS styling like so:

#ID {
    background: url("gallery.png") no-repeat top center;
}

If using a one-line background in CSS, simply use the property background, as background-image alone will not work. For more customization, include background-position and background-repeat.

Using ID's for other elements may spark a different discussion altogether and might not be advisable.

Answer №2

Replace the CSS property "background-image" with "background". Here's how:

#navbar #gallerybutton{
  background:url("gallery.png") no-repeat top center;
}

Answer №3

Ensure to repeat this process for all other identification numbers as well, ensuring the proper height and width settings.

#gallerybutton {
background:url("picture.jpg") no-repeat top left; display: block; height: 50px; width: 200px;
}

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

The hover effect on the menu button is not covering the entire button when the screen is resized

It appears that I am encountering a problem with the hover functionality. When my screen is at full size, hovering over a menu option causes the entire background color to change. However, upon resizing the screen, only a part of the background color chang ...

I can't seem to figure out why this isn't functioning properly

Upon examining the script, you'll notice the interval() function at the very bottom. The issue arises from bc-(AEfficiency*100)/5; monz+((AEfficiency*100)/5)((AFluencyAProduct)/100); For some reason, "bc" and "monz" remain unchanged. Why is that so? T ...

In my PHP loop, I am creating radio buttons and I only want one of them to be selected at a time

How can I ensure that only one radio button is selected out of the 99 radio buttons generated in this for loop? for($x = 2; $x <= 101; $x++){ $out .= "<img src='/img/channel_icons/".$icons[$x]."' class='ch ...

Adjust the dimensions of a div element based on the screen size

I'm struggling with adjusting the size of a div responsively based on the surrounding divs. My layout includes buttons on both sides of the page and text in the middle that varies from 0 to 140 characters. What I aim to achieve is for the buttons to ...

Strange behavior of dropdown submenu

I've encountered an issue where my child's ul li elements are not behaving as expected, despite following advice from other sources. After days of debugging with no success, I am unable to pinpoint the problem. The image showcases the issue perfe ...

The equal height feature in Bootstrap 4's card-deck is not functioning as expected

I am having an issue with the card-deck property where it is not being applied correctly. The .card-deck class should create a grid of cards that are equal in height and width, and the layout should adjust automatically as more cards are added. Here is th ...

Menu selection popper JavaScript

Struggling to create a dropdown menu and encountering this error: "Uncaught Error: Bootstrap dropdown require Popper.js (https://popper.js.org) at bootstrap.min.js:6 at bootstrap.min.js:6 at bootstrap.min.js:6" Explored various solutions in f ...

"Enhancing Your Web Design with Ruby On Rails: Optimal Methods for Integrating CSS

I am a newcomer to Ruby on Rails and I am seeking advice on the best method to incorporate CSS/JS libraries for a specific controller and method in order to avoid unnecessary requests. Currently, I am using the following somewhat inefficient method: - # ...

Learn how to transform the html:options collection into html:optionsCollection

What is the best method to transform this code snippet: <html:options collection='catList' property='catId' labelProperty='catName'> using the <html:optionsCollection> tag? ...

How is the height or width of the Bootstrap modal determined?

I'm having trouble utilizing Jschr's modified Bootstrap-Modal for different modal sizes. I can't seem to understand why some modals appear taller, wider, or have other specific dimensions. For more information, refer to the documentation: ...

Reducing the Distance Between Columns in Bootstrap 4

I am currently working on embedding two websites onto my own website. The idea is to showcase these websites side by side within a custom-sized iframe that adjusts responsively based on the viewport size. To achieve this, I am utilizing Bootstrap 4's ...

Troubleshooting Problem: Adjusting the hover border color for TextField in ReactJS Material UI

I'm having trouble setting the hover border color of a TextField to a theme variable. It seems that in order for the hover borderColor to work, it needs the "!important" tag. However, I am unsure of how to incorporate this into the theme variable. Th ...

Is there a PHP function that can strip out line breaks and HTML entities from a given string?

I currently have descriptions stored in a database that are formatted using HTML tags as shown below: &#149; Description bullet blah blah <br /> &#149; Description bullet blah blah <br /> &#149; Description bullet blah blah My pla ...

Having difficulty retrieving the text of the xpath using Selenium

I am encountering challenges with web scraping on certain pages where the structure consists of numerous nested divs. Here is a snippet of the HTML code: <div> <section class="ui-accordion-header ui-state-default ui-corner-all ui- ...

Difficulty arranging objects in both horizontal and vertical orientation within a single flexbox container

I'm struggling with aligning my bootstrap flexbox container properly. I want the image to remain horizontal on the left, while the title, description, and "powered by" sections stack vertically to its right. So far, all my attempts to achieve this hav ...

What is the process for terminating a prototype ajax request?

Currently, I have an AJAX call that is sending requests every 10ms: function sendRequest(){ new Ajax.Request(getProgressUrl, { method: 'get', onComplete: function(transport) { setTimeout(updateCsvExportProgre ...

Is there a way to adjust the spacing between cards in Bootstrap?

I am attempting to replicate the layout shown in the attached picture. How can I adjust this property? Expected output: I would like the elements to be closer together and centered on the page, but I am struggling to achieve this. I have tried adjusting ...

Vertical and floating alignment

Can you help me with this HTML/CSS challenge? User: Support: Emily Johnson Alex Roberts I am looking to have two input boxes aligned vertically on both the left and right ...

Splitting two distinct dropdown menus in Bootstrap 4: A step-by-step guide

I recently came across a helpful tutorial on Bootstrap 4 by W3Schools (https://www.w3schools.com/bootstrap4/bootstrap_button_groups.asp) and was curious about how dropdown menus function. <div class="btn-group"> <button type="button" class="b ...

What is the reason behind HTML5 Canvas drawing layering a fresh path onto the current path with each new point added?

Trying to explain the issue is a bit challenging, which is why I created a JS Fiddle to demonstrate what's happening: http://jsfiddle.net/dGdxS/ - (Only compatible with Webkit browsers) When you hover over the canvas, you can draw, but you may need to ...