img src SVG changing the styles with CSS

后端 未结 22 1998
予麋鹿
予麋鹿 2020-11-22 01:16

html

\"Logo\"

css

.logo-img path {
           


        
22条回答
  •  长发绾君心
    2020-11-22 01:48

    The main problem in your case is that you are importing the svg from an tag which will hide the SVG structure.

    You need to use the tag in conjunction with the to get the desired effect. To make it work, you need to give an id to the path you want to use in the SVG file to then be able to retrieve them from the tag. Try the snipped below.

    .icon {
      display: inline-block;
      width: 2em;
      height: 2em;
      transition: .5s;
      fill: currentColor;
      stroke-width: 5;
      }
      .icon:hover {
        fill: rgba(255,255,255,0);
        stroke: black;
        stroke-width: 2;
        }
    
    .red {
      color: red;
      }
    
    .blue {
      color: blue;
      }
    
      
        
    
    
      
      
              
                
              
            
      
        
              
                
              
            

    Note that you can put any URL before the fragment # if you want to load the SVG from an external source (and not embed it into your HTML). Also, usually you do not specify the fill into the CSS. It's better to consider using fill:"currentColor" within the SVG itself. The corresponding element's CSS color value will then be used in place.

提交回复
热议问题