CSS list-style-image size

后端 未结 11 1383
离开以前
离开以前 2020-12-02 10:24

I\'m trying to set custom SVG icons with CSS on a

    \'s list items. Example:

相关标签:
11条回答
  • 2020-12-02 10:55

    I'm using:

    li {
    	margin: 0;
    	padding: 36px 0 36px 84px;
    	list-style: none;
    	background-image: url("../../images/checked_red.svg");
    	background-repeat: no-repeat;
    	background-position: left center;
    	background-size: 40px;
    }

    where background-size set the background image size.

    0 讨论(0)
  • 2020-12-02 10:56

    I did a kind of terminal emulator with Bootstrap and Javascript because I needed some dynamic to add easily new items, and I put the prompt from Javascript.

    HTML:

      <div class="panel panel-default">
          <div class="panel-heading">Comandos SQL ejecutados</div>
          <div class="panel-body panel-terminal-body">
              <ul id="ulCommand"></ul>
          </div>
     </div>
    

    Javascript:

    function addCommand(command){
        //Creating the li tag   
        var li = document.createElement('li');
        //Creating  the img tag
        var prompt = document.createElement('img');
        //Setting the image 
        prompt.setAttribute('src','./lib/custom/img/terminal-prompt-white.png');
        //Setting the width (like the font)
        prompt.setAttribute('width','15px');
        //Setting height as auto
        prompt.setAttribute('height','auto');
        //Adding the prompt to the list item
        li.appendChild(prompt);
        //Creating a span tag to add the command
        //li.appendChild('el comando');   por que no es un nodo
        var span = document.createElement('span');
        //Adding the text to the span tag
        span.innerHTML = command;
        //Adding the span to the list item
        li.appendChild(span);
        //At the end, adding the list item to the list (ul)
        document.getElementById('ulCommand').appendChild(li);
    }
    

    CSS:

    .panel-terminal-body {
      background-color: #423F3F;
      color: #EDEDED;
      padding-left: 50px;
      padding-right: 50px;
      padding-top: 15px;
      padding-bottom: 15px;
      height: 300px;
    }
    
    .panel-terminal-body ul {
      list-style: none;
    }
    

    I hope this help you.

    0 讨论(0)
  • 2020-12-02 10:56

    I achieved it by placing the image tag before the li's:


    HTML

    <img src="https://www.pinclipart.com/picdir/big/1-17498_plain-right-white-arrow-clip-art-at-clipart.png" class="listImage">
    

    CSS

         .listImage{
          float:left;
          margin:2px;
          width:25px
         }
         .li{
          margin-left:29px;
         }
    
    0 讨论(0)
  • 2020-12-02 11:03

    Almost like cheating, I just went into an image editor and resized the image by half. Works like a charm for me.

    0 讨论(0)
  • 2020-12-02 11:04

    Here is an example to play with Inline SVG for a list bullet (2020 Browsers)

    list-style-image: url("data:image/svg+xml,
                          <svg width='50' height='50'
                               xmlns='http://www.w3.org/2000/svg' 
                               viewBox='0 0 72 72'>
                            <rect width='100%' height='100%' fill='pink'/>
                            <path d='M70 42a3 3 90 0 1 3 3a3 3 90 0 1-3 3h-12l-3 3l-6 15l-3
                                     l-6-3v-21v-3l15-15a3 3 90 0 1 0 0c3 0 3 0 3 3l-6 12h30
                                     m-54 24v-24h9v24z'/></svg>")
    
    • Play with SVG width & height to set the size
    • Play with M70 42 to position the hand
    • different behaviour on FireFox or Chromium!
    • remove the rect

    li{
      font-size:2em;
      list-style-image: url("data:image/svg+xml,<svg width='3em' height='3em'                          xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 72'><rect width='100%' height='100%' fill='pink'/><path d='M70 42a3 3 90 0 1 3 3a3 3 90 0 1-3 3h-12l-3 3l-6 15l-3 3h-12l-6-3v-21v-3l15-15a3 3 90 0 1 0 0c3 0 3 0 3 3l-6 12h30m-54 24v-24h9v24z'/></svg>");
    }
    
    span{
      display:inline-block;
      vertical-align:top;
      margin-top:-10px;
      margin-left:-5px;
    }
    <ul>
      <li><span>Apples</span></li>
      <li><span>Bananas</span></li>
      <li>Oranges</li>
    </ul>

    0 讨论(0)
提交回复
热议问题