[英]Cannot use two CSS styles for 2 different components
So i have a problem with the css. I have one login page which has css with styles in it.所以我对 css 有疑问。我有一个登录页面,其中包含 css 和 styles。 One of them is for span:
其中之一是跨度:
login.css:登录.css:
span {
font-size: 12px;
padding: 3px;
color: red;
display: none;
}
and works fine on the login page, but now i have "my profile page " and im using a function from a library (react-drag-drop-files), which makes me a component which has a span element in it并且在登录页面上工作正常,但现在我有“我的个人资料页面”并且我正在使用库中的 function (react-drag-drop-files),这使我成为一个包含 span 元素的组件
and as i can see here it is using the login.css file which i have not imported into my React function. So i cant style only the span in the "my profile" page simply because i have no access to it.
正如我在这里看到的那样,它正在使用我尚未导入到我的 React function 中的 login.css 文件。所以我不能仅在“我的个人资料”页面中设置跨度样式,因为我无权访问它。 I have also tried to make new span style in the myprofile.css but that messed up the span on the login page.
我还尝试在 myprofile.css 中创建新的跨度样式,但这弄乱了登录页面上的跨度。 So I think I'm trying to find a way how to separate the two files even though they are not connected.
所以我想我正在尝试找到一种方法来分离这两个文件,即使它们没有连接。
I am not sure I understand your problem.我不确定我理解你的问题。
Have you tried using a className for the spans in your login page and create a class in css?您是否尝试过在登录页面中使用 className 作为 span 并在 css 中创建一个类? By doing this you should be able to modify only the login page spans.
通过这样做,您应该只能修改登录页面跨度。
You could also create different css files for each page.您还可以为每个页面创建不同的 css 文件。
Hope this helps you希望这对你有帮助
This is how I found out that your span styling applies to both the login page and the profile page.这就是我发现您的 span 样式同时适用于登录页面和个人资料页面的方式。 This is because you have globally targeted the span for styling in css, don't target the span globally, add a class for your span on the login page and style them
这是因为你已经全局定位了 css 样式的范围,不要全局定位范围,在登录页面上为你的范围添加一个类并设置它们的样式
From my understanding of your question, I think you can try these.根据我对您问题的理解,我认为您可以尝试这些。
Add parent class to your login.css file:将父 class 添加到您的 login.css 文件中:
.parentClass span {
font-size: 12px;
padding: 3px;
color: red;
display: none;
}
Or add a class name to your span in login.js.或者在 login.js 中将 class 名称添加到您的跨度中。
<span className="spanClass">
// your style here
</span>
login.css file登录.css 文件
.spanClass {
font-size: 12px;
padding: 3px;
color: red;
display: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.