簡體   English   中英

懸停時,在svg文件上更改顏色

[英]On hover change color on svg file

我有社交SVG按鈕。 我只需要更改背景,但是當我將“ f”字母懸停在facebook圖標中時,它不會更改。 問題是svg標簽內部包含兩個數字。 在這里我重新創建了我的問題https://codesandbox.io/s/smoosh-surf-bhrcu

.tours-full__content-social-links {
  svg {
    :hover {
      &:first-child {
        fill: #000000;

      }
    }
  }

}

在此處輸入圖片說明

<svg width="52" height="53" viewBox="0 0 52 53" fill="none" xmlns="http://www.w3.org/2000/svg">
              <rect width="52" height="53" rx="26" fill="white"/>
              <path fill-rule="evenodd" clip-rule="evenodd" d="M32.0986 35.5403C18.806 36.8848 20.9952 36.8848 22.3404 35.5403Z" fill="#B8B8B8"/>
            </svg>

我嘗試將類添加到路徑並使用該類將其懸停。 檢查代碼段。

 body { font-family: sans-serif; background: #d1d1d1; } .icon:hover { fill: #000; } 
 <div class="tours-full__content-sidebar-social"> <a href="#" class="tours-full__content-social-links"> <svg width="52" height="52" viewBox="0 0 52 52" fill="none" xmlns="http://www.w3.org/2000/svg"> <path class="icon" fill-rule="evenodd" clip-rule="evenodd" d="M26 52C40.3594 52 52 40.3594 52 26C52 11.6406 40.3594 0 26 0C11.6406 0 0 11.6406 0 26C0 40.3594 11.6406 52 26 52Z" fill="white"/> <path d="M32.4351 12.0054L28.8373 12C24.7953 12 22.1832 14.5115 22.1832 18.3986V21.3488H18.5657C18.2531 21.3488 18 21.5863 18 21.8793V26.1538C18 26.4467 18.2534 26.6839 18.5657 26.6839H22.1832V37.4698C22.1832 37.7628 22.4363 38 22.7489 38H27.4686C27.7812 38 28.0343 37.7625 28.0343 37.4698V26.6839H32.264C32.5766 26.6839 32.8297 26.4467 32.8297 26.1538L32.8314 21.8793C32.8314 21.7386 32.7717 21.6039 32.6658 21.5044C32.5598 21.4048 32.4155 21.3488 32.2654 21.3488H28.0343V18.8479C28.0343 17.6459 28.34 17.0357 30.0109 17.0357L32.4346 17.0348C32.7469 17.0348 33 16.7974 33 16.5047V12.5356C33 12.2432 32.7472 12.006 32.4351 12.0054Z" fill="#B8B8B8"/> </svg> </a> <a href="#" class="tours-full__content-social-links"> <svg width="52" height="52" viewBox="0 0 52 52" fill="none" xmlns="http://www.w3.org/2000/svg"> <path class="icon" fill-rule="evenodd" clip-rule="evenodd" d="M26 52C40.3594 52 52 40.3594 52 26C52 11.6406 40.3594 0 26 0C11.6406 0 0 11.6406 0 26C0 40.3594 11.6406 52 26 52Z" fill="white"/> <path d="M40 17.6045C39.0331 18.0462 38.0029 18.3389 36.9287 18.4811C38.0337 17.794 38.8771 16.7143 39.2736 15.4129C38.2434 16.0526 37.1059 16.5045 35.8936 16.7566C34.9154 15.6718 33.5211 15 32.0001 15C29.0491 15 26.6734 17.4945 26.6734 20.5525C26.6734 20.9925 26.7091 21.4155 26.7969 21.8183C22.3655 21.5932 18.4444 19.3814 15.8103 16.012C15.3504 16.8429 15.0806 17.794 15.0806 18.8178C15.0806 20.7403 16.0312 22.4445 17.4483 23.4311C16.5919 23.4142 15.7517 23.1552 15.04 22.7474C15.04 22.7643 15.04 22.7863 15.04 22.8083C15.04 25.5058 16.8876 27.7465 19.3105 28.2626C18.8766 28.3862 18.4037 28.4454 17.913 28.4454C17.5718 28.4454 17.2273 28.4251 16.9039 28.3506C17.5945 30.5489 19.5542 32.1651 21.8845 32.2175C20.071 33.6949 17.7684 34.5851 15.2756 34.5851C14.8385 34.5851 14.4193 34.5648 14 34.5089C16.3611 36.0946 19.1594 37 22.177 37C31.9855 37 37.348 28.5385 37.348 21.204C37.348 20.9586 37.3399 20.7217 37.3285 20.4865C38.3864 19.7046 39.2752 18.7282 40 17.6045Z" fill="#B8B8B8"/> </svg> </a> <a href="#" class="tours-full__content-social-links"> <svg width="52" height="52" viewBox="0 0 52 52" fill="none" xmlns="http://www.w3.org/2000/svg"> <path class="icon" fill-rule="evenodd" clip-rule="evenodd" d="M26 52C40.3594 52 52 40.3594 52 26C52 11.6406 40.3594 0 26 0C11.6406 0 0 11.6406 0 26C0 40.3594 11.6406 52 26 52Z" fill="white"/> <path d="M38.8621 33.6435C38.8306 33.5795 38.8013 33.5264 38.774 33.4838C38.3229 32.7171 37.4609 31.7759 36.1884 30.6601L36.1615 30.6346L36.1481 30.6221L36.1345 30.6092H36.1208C35.5433 30.0896 35.1776 29.7403 35.0245 29.5614C34.7442 29.2207 34.6815 28.8759 34.8346 28.5264C34.9428 28.2624 35.3492 27.7048 36.053 26.853C36.4231 26.4015 36.7163 26.0397 36.9328 25.7671C38.4942 23.808 39.1711 22.5561 38.9634 22.011L38.8828 21.8836C38.8286 21.8069 38.6887 21.7367 38.4634 21.6727C38.2375 21.6089 37.9488 21.5983 37.5967 21.6409L33.6981 21.6663C33.635 21.6452 33.5448 21.6471 33.4273 21.6727C33.31 21.6983 33.2513 21.7112 33.2513 21.7112L33.1834 21.7432L33.1295 21.7816C33.0844 21.807 33.0348 21.8517 32.9806 21.9156C32.9267 21.9793 32.8816 22.054 32.8455 22.1392C32.4211 23.1698 31.9385 24.128 31.3969 25.0137C31.063 25.5419 30.7563 25.9996 30.4762 26.3872C30.1965 26.7746 29.9619 27.06 29.7725 27.243C29.5828 27.4262 29.4117 27.5729 29.2579 27.6837C29.1045 27.7946 28.9873 27.8415 28.9062 27.8243C28.8249 27.8072 28.7483 27.7902 28.6758 27.7732C28.5495 27.6965 28.448 27.5922 28.3714 27.4602C28.2945 27.3282 28.2427 27.162 28.2156 26.9619C28.1887 26.7616 28.1728 26.5893 28.1682 26.4444C28.164 26.2998 28.1659 26.0951 28.1751 25.8311C28.1845 25.567 28.1887 25.3882 28.1887 25.2945C28.1887 24.9708 28.1954 24.6195 28.2088 24.2405C28.2225 23.8615 28.2335 23.5612 28.2428 23.3399C28.252 23.1185 28.2562 22.8842 28.2562 22.6372C28.2562 22.3902 28.2403 22.1965 28.2088 22.0559C28.1777 21.9154 28.13 21.7791 28.067 21.647C28.0037 21.515 27.9111 21.4129 27.7895 21.3404C27.6677 21.268 27.5163 21.2105 27.3361 21.1678C26.8577 21.0657 26.2486 21.0104 25.5084 21.0018C23.8299 20.9848 22.7513 21.0871 22.273 21.3086C22.0835 21.4021 21.912 21.53 21.7587 21.6917C21.5962 21.8791 21.5735 21.9814 21.6908 21.9983C22.2324 22.0748 22.6158 22.258 22.8414 22.5475L22.9227 22.701C22.986 22.8117 23.0492 23.0077 23.1124 23.2887C23.1755 23.5697 23.2162 23.8806 23.2341 24.2211C23.2792 24.843 23.2792 25.3753 23.2341 25.8181C23.1889 26.2611 23.1463 26.606 23.1055 26.853C23.0648 27.1 23.0039 27.3002 22.9227 27.4535C22.8414 27.6068 22.7873 27.7005 22.7602 27.7345C22.7331 27.7685 22.7106 27.7899 22.6926 27.7983C22.5753 27.8407 22.4533 27.8624 22.3271 27.8624C22.2006 27.8624 22.0473 27.8027 21.8668 27.6834C21.6864 27.5641 21.4992 27.4002 21.3051 27.1915C21.111 26.9827 20.8922 26.691 20.6484 26.3163C20.4049 25.9416 20.1521 25.4987 19.8904 24.9877L19.6739 24.6171C19.5385 24.3787 19.3536 24.0315 19.1189 23.5759C18.8841 23.1202 18.6766 22.6793 18.4962 22.2535C18.4241 22.0746 18.3157 21.9384 18.1714 21.8447L18.1036 21.8063C18.0586 21.7723 17.9863 21.7362 17.8871 21.6977C17.7877 21.6593 17.6841 21.6317 17.5757 21.6147L13.8665 21.6401C13.4875 21.6401 13.2303 21.7212 13.0949 21.883L13.0407 21.9596C13.0137 22.0022 13 22.0704 13 22.1641C13 22.2578 13.0271 22.3728 13.0813 22.509C13.6227 23.71 14.2116 24.8683 14.8478 25.9841C15.484 27.0998 16.0368 27.9986 16.506 28.6795C16.9753 29.361 17.4536 30.0042 17.9409 30.6087C18.4283 31.2135 18.7509 31.6011 18.9088 31.7713C19.0668 31.9419 19.1909 32.0694 19.2811 32.1546L19.6196 32.4612C19.8362 32.6656 20.1543 32.9105 20.5739 33.1957C20.9937 33.4812 21.4584 33.7622 21.9683 34.0392C22.4783 34.3158 23.0716 34.5415 23.7485 34.7161C24.4253 34.8908 25.0841 34.961 25.7249 34.9271H27.2817C27.5975 34.9014 27.8367 34.8077 27.9992 34.646L28.0531 34.5819C28.0893 34.5311 28.1232 34.4521 28.1545 34.3459C28.1862 34.2394 28.2019 34.1221 28.2019 33.9945C28.1927 33.6284 28.2222 33.2984 28.2897 33.0045C28.3572 32.7108 28.4341 32.4894 28.5201 32.3402C28.6061 32.1912 28.7031 32.0655 28.8111 31.9635C28.9193 31.8614 28.9964 31.7995 29.0416 31.7782C29.0865 31.7567 29.1224 31.7422 29.1495 31.7335C29.3661 31.6654 29.621 31.7313 29.9146 31.9317C30.2079 32.1318 30.4831 32.379 30.7404 32.6727C30.9977 32.9667 31.3067 33.2965 31.6676 33.6627C32.0288 34.029 32.3446 34.3013 32.6152 34.4804L32.8858 34.6337C33.0666 34.736 33.3012 34.8297 33.5901 34.9149C33.8784 35 34.131 35.0213 34.3479 34.9787L37.8133 34.9277C38.1561 34.9277 38.4228 34.8742 38.612 34.7679C38.8015 34.6614 38.9141 34.5441 38.9504 34.4166C38.9867 34.2888 38.9886 34.144 38.9573 33.982C38.9252 33.8204 38.8936 33.7074 38.8621 33.6435Z" fill="#B8B8B8"/> </svg> </a> <a href="#" class="tours-full__content-social-links"> <svg width="52" height="53" viewBox="0 0 52 53" fill="none" xmlns="http://www.w3.org/2000/svg"> <rect class="icon" width="52" height="53" rx="26" fill="white"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M32.0986 30.6595L36.9794 25.7802C39.6735 23.0855 39.6735 18.7159 36.9794 16.0212C34.284 13.3263 29.9151 13.3263 27.2197 16.0212L23.5224 19.7183C24.9991 19.5019 26.5161 19.6493 27.9241 20.1976L29.6591 18.4606C31.0053 17.1154 33.1938 17.1154 34.5384 18.4606C35.8847 19.8058 35.8847 21.9944 34.5384 23.3406L29.6591 28.2197C28.3146 29.5642 26.1255 29.5661 24.7802 28.2197C24.3589 27.7984 24.0852 27.2913 23.9284 26.7556C23.904 26.7697 23.8794 26.7834 23.8547 26.7971C23.751 26.8546 23.6474 26.9122 23.5603 27L21.2925 29.2677C21.584 29.7594 21.916 30.2363 22.3404 30.6595C25.0347 33.3549 29.4048 33.3549 32.0986 30.6595ZM22.3404 35.5403L24.0767 33.8033C25.4835 34.3505 27.0009 34.4992 28.4784 34.2815L24.7801 37.9795C22.0853 40.6735 17.7159 40.6735 15.021 37.9795C12.3263 35.284 12.3263 30.9157 15.021 28.22L19.9001 23.3407C22.595 20.6459 26.9654 20.6459 29.659 23.3407C30.0836 23.7644 30.4173 24.2395 30.707 24.7332L28.4393 27C28.3539 27.0855 28.2537 27.1412 28.1521 27.1976C28.1254 27.2124 28.0987 27.2272 28.0722 27.2427C27.9139 26.7077 27.6399 26.2007 27.2196 25.7803C25.8744 24.4342 23.6867 24.4342 22.3404 25.7803L17.4605 30.6595C16.1152 32.0053 16.1152 34.1939 17.4605 35.5403C18.806 36.8848 20.9952 36.8848 22.3404 35.5403Z" fill="#B8B8B8"/> </svg> </a> </div> 

你很親密

  svg {
    &:hover {
      :first-child {
        fill: #000000;

      }
    }
  }

編譯為svg:hover :first-child {fill: #000000;}

當您將SVG整體懸停時,僅更改第一條路徑的填充。

 svg:hover :first-child { fill: #000000; } 
 <svg width="52" height="52" viewBox="0 0 52 52" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M26 52C40.3594 52 52 40.3594 52 26C52 11.6406 40.3594 0 26 0C11.6406 0 0 11.6406 0 26C0 40.3594 11.6406 52 26 52Z" fill="white"/> <path d="M32.4351 12.0054L28.8373 12C24.7953 12 22.1832 14.5115 22.1832 18.3986V21.3488H18.5657C18.2531 21.3488 18 21.5863 18 21.8793V26.1538C18 26.4467 18.2534 26.6839 18.5657 26.6839H22.1832V37.4698C22.1832 37.7628 22.4363 38 22.7489 38H27.4686C27.7812 38 28.0343 37.7625 28.0343 37.4698V26.6839H32.264C32.5766 26.6839 32.8297 26.4467 32.8297 26.1538L32.8314 21.8793C32.8314 21.7386 32.7717 21.6039 32.6658 21.5044C32.5598 21.4048 32.4155 21.3488 32.2654 21.3488H28.0343V18.8479C28.0343 17.6459 28.34 17.0357 30.0109 17.0357L32.4346 17.0348C32.7469 17.0348 33 16.7974 33 16.5047V12.5356C33 12.2432 32.7472 12.006 32.4351 12.0054Z" fill="#B8B8B8"/> </svg> 

您可以對最后一個孩子而不是第一個孩子進行懸停效果

更新的鏈接-CodeSandbox

.tours-full__content-social-links {
  svg {
    :hover {
      &:last-child {
        fill: #000000;

      }
    }
  }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM