What is the best way to restrict the width and height of the background image in my unique bullet list design?

I am currently experimenting with customizing a bullet list. My goal is to apply the same background image, while changing the background position to create a unique effect.

Here is my CSS code:

#sidebar ul{
    width:190px;
    list-style:none;
    margin:0;
    padding:0;
}

#sidebar li{
    border-top:1px dashed #ddd;
    background:#FAFAFA url('./images/bullet.png') no-repeat 15px 9px;
}

#sidebar li:hover{
    background-color:#fff;
    background-position:15px 0px;
}

#sidebar li a{
    display:block;
    padding:5px 20px 5px 26px; /*26 to give extra 6px for the bullet*/
}

The bullets are changing correctly, and everything looks good. However, I am facing an issue where both bullets are always visible.

I am seeking suggestions on how to hide the other bullet. One idea could be to move the images far beyond the visible area (more than the height will ever be), but I consider this approach impractical as it would increase the image size significantly.

If you have any alternative methods or better ways to achieve the desired effect, please share your insights with me. I am open to exploring different approaches.

Answer №1

If you're looking to enhance the aesthetics, consider utilizing a design similar to this one. Make sure to customize the values according to your requirements.

<li><span></span></li>

.

li { position: relative; }
li span { 
    position: absolute; 
    left: 0;
    width: 16px;
    height: 16px;
    margin-right: 16px;
    background: url('img.jpg') 0 0 no-repeat;
}
li:hover span { background-position: 0 -16px; }

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

Arrange children of varying heights in a line

Wondering if it's feasible to design a flexbox layout with wrapping children while aligning them to the top? .container { display: flex; flex-wrap: wrap; justify-content: space-between; } .container .element { flex: 0 0 auto; } This piece o ...

testing to see if the value is equal to "null"

I'm having trouble determining if a value is "null." Here is the code snippet I'm working with: Milestone: any={}; constructor(public toastController: ToastController) { this.Milestone.MilestoneType=''; this.Milestone.date=&apo ...

How to turn off automatic password suggestions in Chrome and Firefox

Currently, I have integrated a 'change password' feature which includes fields for 'old password', 'new password', and 'retype password'. However, the autocomplete feature is suggesting passwords from other user acco ...

What is the best way to define ngOptionValue for my ng-option selection?

After updating my select/option code to include a search feature, it caused an issue with my function create. Here is the HTML code: <div class="input-group"> <label htmlFor="categoria" class="sr-only"> ...

Adjusting the positioning of links with bootstrap scrollyspy

Having trouble getting the scrollyspy links to align properly in the center of the navbar. Can someone offer some assistance? Much appreciated! <ul class="nav nav-pills"> <li class="nav-item"> < ...

inner element positioned absolutely overlapping scrollbar

I was unable to locate this specific question. I have configured a page as <div id="page"> <div id="chrome"> <div id="element">bla</div> <div id="content">bla</div> </div> </div> #p ...

Toggling Bootstrap Tooltip divs within a nested structure triggers the Tooltip of the parent div

I have a setup with 2 nested <div> elements, both utilizing the tooltip() function. When I hover over the inner <div>, the tooltip of the outer <div> also displays. To resolve this issue, I attempted to clear the title of the inner <di ...

Create Stunning Half-Brick Image Layouts Using HTML and CSS

Can anyone offer advice on creating complex image layouts such as the half-brick pattern using HTML, CSS, and jQuery? I am looking to be able to rotate and scale the image as well. The background-image CSS property does not seem to support scaling. I have ...

Tips for Keeping Sub Menu Visible Without Having to Click

I am working on an HTML navigation menu that opens submenus on click like this... $("#nav_evnavmenu > li > a").click(function () { // bind onclick if ($(this).parent().hasClass('selected')) { $("#nav_evnavmenu .selected div div ...

Displaying the chosen plan value in a text field using vue js and html – a guide

Here is the json data I have: {"status": true, "plans": [{"planId": 1, "name": "Basic", "cost": 500.0, "validity": 365}, {"planId": 3, "name": "Free", "cost": 0.0, "validity": 999}, {"planId": 4, "name": "Premium", "cost": 500.0, "validity": 500}, {"planI ...

Ways to achieve a clickable user icon that leads to the user's profile display

I am attempting to create a clickable user profile icon in bootstrap/html that reveals the user's information (email address) and logout functionality. Can anyone provide guidance on how to achieve this using bootstrap or html, similar to the example ...

Getting HTML from Next.js middleware - a step-by-step guide

Is there a way to send the HTTP Status Code 410 (gone) together with a customized HTML message? I want to display the following content: <h1>Error 410</h1> <h2>Permanently deleted or Gone</h2> <p>This page is not foun ...

Having spaces between elements is necessary due to the insertion of a new line and the use

I am working on an HTML page where I have the following code snippet: <div id="div"></div> My task is to dynamically add two elements within this div using JavaScript. The issue arises when adding a and button elements. a1 = document.createEl ...

Element appearing on screen but not found in the document structure

While using Selenium for HCI tests, I encountered a situation where Selenium was unable to locate a visible element. After some investigation, it seems that the element is visible but not present in the DOM. I could be wrong, but that’s how it appea ...

Tips for perfectly centering a SPAN element within a DIV both vertically and horizontally

Here is an example of my HTML code: <div id="slideClick"> <div style="padding: 0; margin: 0 auto; width: 100%; height: 100%; text-align: center; border: 1px solid blue;"> <span class="sideMsg">MESSAGES</span> </d ...

How can I make angular material data table cells expand to the full width of content that is set to nowrap?

This example demonstrates how the mat-cells are styled with a specific width: .mat-cell { white-space: nowrap; min-width: 150rem; } If the width is not specified, the table will cut off the text due to the white-space property being set to nowrap. Is ...

JavaScript functioning exclusively for specific list items within an unordered list

After implementing JavaScript on my website, I noticed that it only works when clicking on certain list items (li's) and not on others. Specifically, the functionalities for Specialties, Contact Us, and Referral Schemes are not working correctly. ...

When using Vue.js, binding may not function properly if it is updated using jQuery

Link to JsFiddle Below is the HTML code: <div id="testVue"> <input id="test" v-model="testModel"/> <button @click="clickMe()">Click me</button> <button @click="showValue()">Show value</button> </div& ...

Designing a custom CSS for enhancing the look of the orchard menu

Right now, I am in the process of implementing a layout that is already established in an MVC4 project. I am facing challenges in figuring out how to create a custom menu in the latest version of Orchard (using the source version so it runs in Visual Stud ...

Information from contact forms gets inputted into the URL

Currently, I am in the process of developing a website and implementing a Contact Form that allows customers to email me directly. To test if the mail function is working correctly, I am using a Test Mail Server listening on Port 25 through a WAMP server v ...