簡體   English   中英

無法使用樣式組件設置圖標,但是相同的樣式在“.css”文件中工作得很好

[英]not able to set icon using style component, however same style is working perfectly fine in “.css” file

這是我正在使用的樣式組件,在 HTML 中我看不到我的圖標在.css 文件中的工作原理

// CSS
.name {
    width: 70%;
    height: 40px;
    margin-top: 20px;
    background-image: url("../../Icons/icons8-male-user-24.png");
    background-position: 2% 50%;
    background-repeat: no-repeat;
    padding-left: 30px;
    border: none;
    background-color: rgb(255, 255, 255);
}

// js
export const Username = styled.input`
    width: 70%;
    height: 40px;
    margin-top: 20px;
    background-image: url("../../Icons/icons8-male-user-24.png");
    background-position: 2% 50%;
    background-repeat: no-repeat;
    padding-left: 30px;
    border: none;
    background-color: rgb(255, 255, 255);
`;

如果您解決了路徑,它將起作用。

這告訴 webpack 將該文件包含在包中。 與 CSS 導入不同,導入文件會為您提供字符串值。 此值是您可以在代碼中引用的最終路徑。

import path from "../../Icons/icons8-male-user-24.png";

export const Username = styled.input`
  background-image: url(${path});
`;

請參閱添加圖像 Fonts 和文件

暫無
暫無

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

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