[英]Component does not see global styles
Component from globalstyle globalstyle的组件
Global styles are visible only in this component, col-lg-2,col-md-4 -> globalstyle 全局样式仅在此组件中可见,col-lg-2,col-md-4-> globalstyle
import React from 'react'
import ReactDOM from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import { BrowserRouter } from 'react-router-dom'
import App from './containers/App'
import './basestyle/flexboxgrid.min.css' //Global style
ReactDOM.render(
<AppContainer>
<BrowserRouter>
<App/>
</BrowserRouter>
</AppContainer>,
document.getElementById('root')
);
Component that should get styles 应该获得样式的组件
import React from 'react'
import { Link } from 'react-router-dom'
import styles from './Header.css'
import icon from './icon.png'
const Header = () => (
<div className="row">
<div className={`col-lg-2 col-md-4 ${styles.test}`} > //Here is not available
<Link to="/категории">
<div className={styles.logoBox}>
<img src={icon} alt="logo"/>
<h1>Белый кот</h1>
</div>
</Link>
</div>
</div>
);
export default Header;
Webpack.config https://github.com/minaev-git/TestQuestion Webpack.config https://github.com/minaev-git/TestQuestion
Try adding global to your class name. 尝试将全局名称添加到您的班级名称。 Eg
例如
:global(.yourClass) { //your css }
Those styles will only be loaded if <Header />
appears somewhere in <App />
. 仅当
<Header />
出现在<App />
某处时,才会加载这些样式。 I'm assuming that's the case, but otherwise make sure that the header component shows up in <App />
. 我以为是这种情况,但请确保标头组件显示在
<App />
。 If that's not working, try looking around your Network
tab of the web inspector and reload the page -- see if your CSS is even being loaded. 如果这不起作用,请尝试查看Web检查器的“
Network
选项卡,然后重新加载页面-看看是否甚至正在加载CSS。
EDIT: Just seeing where in the code your class isn't working. 编辑:只看到您的类在代码中不起作用。 If
.test
is a class in your global styles file, it wouldn't show up in the Header.css
file. 如果
.test
是全局样式文件中的类,则它不会显示在Header.css
文件中。 Try removing "styles" and just give it a class of test
if test
is a class in flexboxgrid.min.css
. 尝试删除“风格”,只要给它一类的
test
,如果test
是在一类flexboxgrid.min.css
。
Import for CSS is 的CSS导入为
import './Header.css'
Reference the css classes in your component then with: 然后在您的组件中引用css类:
<div className="col-lg-2 col-md-4 test" >
您将需要将引导程序导入到index.jsx中,目前您仅导入此文件,require('./ basestyle / flexboxgrid.min.css')还不够,如果不这样做,系统将如何知道是否存在boostrap进口的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.