Using CSS to Change List Bullet to Custom Polygon Bullet (Resizable)

My ultimate objective is to design a bullet that can adjust its size based on the screen resolution.

In certain cases of CSS, you have the option to either include a large image within a container that can be resized or utilize multiple images of different sizes and display the appropriate one depending on the screen resolution.

Here's a straightforward example using an image:

li {
list-style-type: square; /* Default */
list-style-image: url("https://i.sstatic.net/gtv3o.jpg"); /* Custom */
}
<!doctype html>
<html>
<head>
</head>
<body>
  <ul>
    <li>This is a line item</li>
    <li>This is a line item</li>
  </ul>
</body>
</html>

I am uncertain about how to manage the size of the "list-style-image" (e.g. scaling the image), which I prefer over using multiple images. For instance, if I wanted a 20x20 pixel image to be displayed as 10x10 pixels.

Ideally, I would like to create a custom bullet style using the polygon attribute in CSS, but I'm unsure how to implement it or whether it's supported (given that the polygon attribute is relatively new).

Below is an example of what I had in mind, using a hexagon as the polygon reference:

li {
list-style-type: none;
}
li:before {
clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
-webkit-clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);

background-color:rgba(255,0,0,1.00);
width: 10px;
height: 10px;
}
<!doctype html>
<html>
<head>
</head>
<body>
  <ul>
    <li>This is a line item</li>
    <li>This is a line item</li>
  </ul>
</body>
</html>

Answer №1

Opting for background images instead of list item images can be a great alternative. Simply adjust the em width/height of the background image by 1, along with increasing the left padding of the parent <li> by 1 to ensure a uniform scaling effect.

ul { 
  padding: 0;
}

li {
  list-style: none;
  position: relative;
  padding-left: 1.25em;
}

li:after {
  position: absolute;
  left: 0;
 top: 50%;
 transform: translateY(-50%);
 content: '';
 background: transparent url(https://i.sstatic.net/gtv3o.jpg) 0 50% no-repeat;
  width: 1em;
 height: 1em;
 display: inline-block;
  background-size: cover;
}
  <ul>
    <li>This is a line item</li>
    <li>This is a line item</li>
  </ul>

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

Is there a way to permanently alter the color of a tag using jQuery?

When a button is clicked, the code inside my .Post() function looks like this: if (Comment != null && Grade > 0) { $("navigation").attr('a[data-id="' + QuestionID + '"]') .css({ "background-color": "gr ...

Adjust the width of an HTML input using the Bootstrap 5 form-control class

Is it possible to set the width of an input using Bootstrap's form-control or input-group classes? In the example below, each input should have a width based on its maxlength attribute: <link href="https://cdn.jsdelivr.net/npm/<a href="/cd ...

Leveraging MUI v5 sx Prop for Applying Various CSS Properties Simultaneously (such as margin, border-radius, and more)

Is there a more efficient way to write the following code that utilizes the sx prop's access to spacing units? <MUIComponent sx={{ borderRadius: '4px 8px 12px 16px' }} /> Could it be written like this instead? <MUIComponent sx={{ b ...

Excessive text overflowing in a chat interface can be resolved through CSS styling

After conducting a thorough search, it appears that very few individuals are taking this important element into consideration. I currently have a chat interface set up with a div element containing a ul, which then houses li elements that contain p element ...

Is there any way to remove the two default aspNetHidden Divs in asp.net web forms?

After creating an empty webform page in asp.net, the generated code looks like this: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Threetier.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org ...

I'm encountering layout issues with my table when using the repeater in Bootstrap

I am experiencing an issue with nested repeaters inside a repeater while trying to incorporate Bootstrap for layout purposes. The layout appears distorted when placed within a div with the class "row". Even when isolated, the layout remains problematic. Re ...

"Eliminated the navigation bar - looking for a way to get rid of the extra

For a recent project, I utilized this template. In this particular project, the navigation bar was unnecessary so I removed that code. Now I'm looking to relocate the carousel to the top of the page. Initially, I tried using .carousel { margin-top:0p ...

Is there a way to redirect a right click to open a link in a new tab

Is it possible to modify the image paths on a webpage using CSS? For example, when a user right-clicks and selects "open link in new tab," can we redirect them to a different URL instead? ...

Design a Fullwidth Container-Fluid with 2 Columns in Bootstrap

I'm attempting to create two columns with 100% width using Bootstrap 3 framework, but I'm experiencing some padding between the right and left positions. In my code, the left column will display a Google map, and the right side will feature a co ...

Setting the parent width to adjust dynamically with the elements inside it is a

Can anyone help me figure out why my parent div's children are breaking onto two lines instead of displaying horizontally in one line? I've been using jQuery's outerWidth(true) function to calculate the total necessary width, but something s ...

What is the method for utilizing an image saved in a Github repository as a background-image in CSS?

I am currently attempting to incorporate an image from one of my GitHub repositories as the background image for a website I am working on. Your assistance is greatly appreciated! ...

Ways to activate Bootstrap using our javascript

http://getbootstrap.com/javascript/#buttons? They have provided a demo for radio button toggling in Bootstrap. I attempted to implement it in my code, but the active state is not switching. What could be causing this issue? CDNs I am using: Code input ...

Chrome displaying elements out of alignment

Anyone have any insights into why my webpage elements are displaying differently in Chrome compared to IE? It's driving me crazy! Here's a screenshot of how it looks in Chrome: https://i.sstatic.net/xAlEi.jpg And here's how it appears in IE ...

Can you guide me on how to replicate this for an additional 16 times? Apologies for the confusion

I need help with a code that can apply to multiple names at once, rather than one by one each time. Here's the example HTML code: <div id="one" class="text-container"> <span> Campfire Cooking in Another World wi ...

What is the best way to create an Information Box that slides out from the right of a link when hovered over?

I am looking for some code to create an interactive feature on my website. Essentially, when a user hovers over a link in my navigation bar, I want a small box to slide out to the right of the link providing more information about it. If feasible, I woul ...

The height of the image remains constant when its width is decreased, causing it not to resize proportionally

I am facing an issue with displaying images in a div of various resolutions. When I have a wide image with low height, such as 730x90, it does not show properly on mobile devices. The width shrinks but the height remains the same. Below is the code snipp ...

Bootstrap resource failed to load

I successfully connected the most recent version of bootstrap.min.css to my webpage using <link rel="stylesheet" href="assets/css/bootstrap.min.css">. Initially, everything was running smoothly. However, I now encountered an issue where my browser is ...

Is it possible to tap into the stylus Abstract Syntax Tree (AST) for

Is there a way to access the abstract syntax tree (AST) of the CSS style generated by stylus without re-parsing it using css-parse? I'm curious if the AST of the generated styles can be accessed publicly. ...

I'm puzzled as to why the hidden input field consistently returns the same value every time

As a beginner in php, I am facing an issue where I cannot trace the correct value of the hidden input which represents the ID of the image in the products table. Every time I try to delete an image, it always returns the ID of the last image in the product ...

prismjs plugin for highlighting code displays code in a horizontal format

If you're looking for a way to showcase source code on your website with highlighted syntax, prismjs.com may be just what you need. It offers a similar style to monokai... However, I've encountered an issue where the plugin displays my code in a ...