can someone help me with a React / css / media query problem? I'm trying to create a frontpage that has a full width and height background image. When I create the styling in the react file with const = bg {..} it works for the desktop-width. But I can't get it to work when using the css file. The media query should switch the image url for smaller screen sizes.
import React from "react";
import { connectContext } from "react-connect-context";
import { Context } from "../context";
import Menu from "./Menu";
import Footer from "./Footer";
import { Header } from "semantic-ui-react";
import "./Frontpage.css";
const textStyle = {
width: 220,
height: 50,
position: "absolute",
top: 0,
bottom: 0,
left: 0,
right: 0,
margin: "auto"
};
class Frontpage extends React.PureComponent {
render() {
return (
<React.Fragment>
<Menu {...this.props} />
<div className="bg">
<Header
as="h1"
content="Evolve App"
textAlign="center"
inverted
style={textStyle}
/>
</div>
<Footer />
</React.Fragment>
);
}
}
export default connectContext(Context)(Frontpage);
and the Frontpage.css file looks like this:
bg {
background-image: url(../img/Frontpage_desktop.jpeg);
background-position: "center";
background-repeat: "no-repeat";
opacity: 0.6;
height: "100vh";
}
@media only screen and (min-width: 768px) and (max-width: 991px) {
bg {
background-image: url(../img/Frontpage_tablet.jpg);
background-position: "center";
background-repeat: "no-repeat";
opacity: 0.6;
height: "100vh";
}
}
@media only screen and (max-width: 767px) {
bg {
background-image: url(../img/Frontpage_mobile.jpg);
background-position: "center";
background-repeat: "no-repeat";
opacity: 0.6;
height: "100vh";
}
}