React material ui appbar made responsive - css

I am trying to use material ui's appbar and code in some custom responsiveness to it. I am creating a personal project that will be accessed from a Galaxy s8 smartphone. Ultimately I would like the nav-links and logout button on the navbar to consolidate into a hamburger button when the viewport is small. I am not quite sure how to achieve this however as I am using flexbox on the webpage when it is at full size and it keeps messing me up.
Here is the appbar at full size:
Here is the appbar at phone size with the hamburger button:
Here is the desired effect I would like with items, posts, groups, and the log out button being pushed to an accordion like menu on mobile:
Here is my navbar component code:
import { withStyles } from "#material-ui/core/styles";
import styles from "./styles/NavBarStyles";
import { LoggedInContext } from "./contexts/LoggedIn";
import { ThemeContext } from "./contexts/ThemeContext";
function Navbar(props) {
const { isDarkMode, toggleTheme } = useContext(ThemeContext);
const { loggedIn, changeLogIn, token, setToken } = useContext(
LoggedInContext
);
const { classes } = props;
const [mobileHamburgerOpen, setMobileHamburger] = useState(false);
const handleMobileClick = () => {
setMobileHamburger(!mobileHamburgerOpen);
console.log(mobileHamburgerOpen);
};
return (
<div className={classes.root}>
<AppBar
position="static"
style={{ background: isDarkMode ? "#2E3B55" : "#715AFF" }}
>
<Toolbar>
<Typography className={classes.title} variant="h6" color="inherit">
{isDarkMode ? "🌚" : "🌞"}
</Typography>
<Switch onChange={toggleTheme} />
<div className={classes.grow} />
{loggedIn && (
<div className={classes.loggedIn}>
<div className={classes.navlinks}>
<NavLink
to="/items"
activeStyle={{ background: "rgba(0, 0, 0, 0.5)" }}
>
Items
</NavLink>
<NavLink
to="/facebookitems"
activeStyle={{ background: "rgba(0, 0, 0, 0.5)" }}
>
<i className="fab fa-facebook-square"></i> Posts
</NavLink>
<NavLink
to="/groups"
activeStyle={{ background: "rgba(0, 0, 0, 0.5)" }}
>
<i className="fab fa-facebook-square"></i> Groups
</NavLink>
</div>
<Button
className={classes.logOutButton}
variant="contained"
color="secondary"
onClick={handleClick}
>
Log Out
</Button>
<Button
className={classes.hamburgerMenu}
variant="contained"
color="primary"
onClick={handleMobileClick}
>
<i className="fas fa-bars"></i>
</Button>
</div>
)}
</Toolbar>
</AppBar>
</div>
);
}
export default withStyles(styles)(Navbar);
Here is my style sheet code:
import { fade } from "#material-ui/core/styles/colorManipulator";
const styles = theme => ({
root: {
width: "100%",
marginBottom: 0
},
grow: {
flexGrow: 1
},
menuButton: {
marginLeft: -12,
marginRight: 20
},
title: {
display: 'block'
},
search: {
position: "relative",
borderRadius: theme.shape.borderRadius,
backgroundColor: fade(theme.palette.common.white, 0.15),
"&:hover": {
backgroundColor: fade(theme.palette.common.white, 0.25)
},
marginLeft: 0,
width: "100%",
[theme.breakpoints.up("sm")]: {
marginLeft: theme.spacing(1),
width: "auto"
}
},
searchIcon: {
width: theme.spacing(9),
height: "100%",
position: "absolute",
display: "flex",
alignItems: "center",
justifyContent: "center"
},
inputRoot: {
color: "inherit",
width: "100%"
},
inputInput: {
paddingTop: theme.spacing(1),
paddingRight: theme.spacing(1),
paddingBottom: theme.spacing(1),
paddingLeft: theme.spacing(10),
transition: theme.transitions.create("width"),
width: "100%",
[theme.breakpoints.up("sm")]: {
width: 120,
"&:focus": {
width: 200
}
}
},
loggedIn: {
width: "100%",
display: "flex",
justifyContent: "space-between",
alignItems: "center",
paddingLeft: "2rem"
},
navlinks: {
// [theme.breakpoints.down("sm")]: {
// position: 'absolute',
// backgroundColor: "rgba(0,0,0,.7)",
// top: '0%',
// right: '0%',
// width: '100vw',
// height: '100vh'
// },
"& a": {
color: "white",
fontWeight: "bold",
fontSize: "1.5rem",
textDecoration: "none",
marginRight: '1rem',
padding: ".5rem",
borderRadius: "15px"
},
"& a:active": {
backgroundColor: "rgba(0, 0, 0, 0.5)"
}
},
hamburgerMenu: {
display: 'none',
[theme.breakpoints.down("sm")]: {
display: 'block',
marginLeft: "auto",
backgroundColor: "white",
color: "#715AFF"
}
},
logOutButton: {
// [theme.breakpoints.down("sm")]: {
// display: 'none'
// }
}
});
export default styles;

Related

Material UI Advanced Button - Text Alignment for Small Screensizes

React / Material-UI Novice here. I am trying to configure a set of buttons inside my app Bar that have a background picture to make it look a little cleaner. I have used a lot of code from examples online (shock) and got it to a place where i am happy with how it has formatted on a full size view (md++). However, when i downsize it to a small breakpoint though, the button image then stack instead (which is what i want) but i lose my text to the left. I have tried shifting to the right in many different ways but i dont think thats the right way to do it, is there something i am missing in making the text flex, i want the text to be in the middle?
import React from 'react'
import { AppBar, Toolbar } from "#mui/material";
import { makeStyles } from '#mui/styles'
import Button from '#mui/material/Button'
import Stack from '#mui/material/Stack'
import ButtonBase from '#mui/material/ButtonBase';
import { styled } from '#mui/material/styles';
import Typography from '#mui/material/Typography';
import Box from '#mui/material/Box';
const useStyles = makeStyles(theme => ({
button: {
...theme.typography.mainmenu,
borderRadius: "40px",
marginLeft: "1px",
height: "45px",
"&:hover": {
backgroundColor: theme.palette.secondary
}
},
}))
const images = [
{
url: '/assets/breakfastMenu.jpg',
title: 'Breakfast',
width: '33.33%',
},
{
url: '/assets/steak.jpg',
title: 'Mains',
width: '33.33%',
},
{
url: '/assets/desserts.jpg',
title: 'Desserts',
width: '33.33%',
},
];
const Image = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
color: theme.palette.common.primary,
}));
const ImageButton = styled(ButtonBase)(({ theme }) => ({
position: 'relative',
height: 150,
[theme.breakpoints.down('sm')]: {
width: '100% !important', // Overrides inline-style
height: 100,
},
'&:hover, &.Mui-focusVisible': {
zIndex: 1,
'& .MuiImageBackdrop-root': {
opacity: 0.15,
},
'& .MuiImageMarked-root': {
opacity: 0,
},
'& .MuiTypography-root': {
border: '4px solid currentColor',
},
},
}));
const ImageSrc = styled('span')({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundSize: 'cover',
backgroundPosition: 'center 40%',
});
const ImageBackdrop = styled('span')(({ theme }) => ({
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundColor: theme.palette.common.black,
opacity: 0.4,
transition: theme.transitions.create('opacity'),
}));
const ImageMarked = styled('span')(({ theme }) => ({
height: 3,
width: 18,
backgroundColor: theme.palette.common.white,
position: 'absolute',
bottom: -2,
left: 'calc(50% - 9px)',
transition: theme.transitions.create('opacity'),
}));
const Header = () => {
const classes = useStyles();
return (<React.Fragment><AppBar position="sticky" className={classes.appBar}>
<Toolbar disableGutters className={classes.mainToolbar} sx={{ justifyContent: "center" }}>
<Stack direction="row" justifyContent="space-between" alignItems="center" spacing={10}>
{/* <Button variant="contained" color="secondary" className={classes.button}>Breakfast</Button>
<Button variant="contained" color="secondary" className={classes.button}>Mains</Button>
<Button variant="contained" color="secondary" className={classes.button}>Desserts</Button> */}
<Box sx={{ display: 'flex', flexWrap: 'wrap', minWidth: 900, width: '100%' }}>
{images.map((image) => (
<ImageButton
focusRipple
key={image.title}
style={{
width: image.width,
}}
>
<ImageSrc style={{
backgroundImage: `url(${image.url})`
}} />
<ImageBackdrop className="MuiImageBackdrop-root" />
<Image>
<Typography
component="span"
variant="subtitle1"
color="white"
fontWeight="bold"
sx={{
position: 'relative',
p: "7em",
pt: "2em",
pb: (theme) => `calc(${theme.spacing(1)} + 6px)`,
}}
>
{image.title}
<ImageMarked className="MuiImageMarked-root" />
</Typography>
</Image>
</ImageButton>
))}
</Box>
</Stack>
</Toolbar>
</AppBar>
</React.Fragment >
)
}
export default Header
I have moved on from this, but in case anybody finds it, using MUI i completely adapted my application by using:
import useMediaQuery from '#mui/material/useMediaQuery'
and some example like:
const matches = useMediaQuery(theme.breakpoints.down("md"))
to control when the application changes its styles

Icon button with InputBase

I'm a newbie to MUI/react and I've been trying to place an Icon button beside my input base form, however I'm struggling to make it so that the input form consumes all the available space in my search div. Instead my search icon wrapper is the one that takes majority of the space. I'm really confused what I'm doing wrong, Can someone please shed some light on me?
Here's my code:
import * as React from "react";
import { styled } from "#mui/material/styles";
import Box from "#mui/material/Box";
import InputBase from "#mui/material/InputBase";
import SearchIcon from "#mui/icons-material/Search";
import IconButton from "#mui/material/IconButton";
const Search = styled("div")(({ theme }) => ({
display: "flex",
position: "relative",
borderRadius: 30,
backgroundColor: "#ffffff",
border: "1px",
borderStyle: "solid",
borderColor: "#55597d",
// marginLeft: 10,
width: "auto",
".MuiInputBase-root": {
width: "100%",
},
}));
const SearchIconWrapper = styled("div")(({ theme }) => ({
padding: theme.spacing(0, 2),
height: "100%",
// position: 'absolute',
// pointerEvents: 'none',
display: "flex",
alignItems: "center",
justifyContent: "flex-end",
// backgroundColor: 'black',
width: "100%",
}));
const StyledInputBase = styled(InputBase)(({ theme }) => ({
color: "inherit",
"& .MuiInputBase-input": {
padding: theme.spacing(1, 1, 1, 0),
// vertical padding + font size from searchIcon
paddingLeft: `calc(1em + ${theme.spacing(0)})`,
paddingRight: `calc(1em + ${theme.spacing(4)})`,
transition: theme.transitions.create("width"),
width: "100%",
},
}));
export default function SearchAppBar({
searchQuery,
setSearchQuery,
clearGenre,
onDropDownChange,
}) {
return (
<Box sx={{ flexGrow: 1 }}>
<Search
sx={{
width: { xs: "90vw", md: "50vw", lg: "30vw" },
margin: "auto",
marginBottom: "20px",
}}
>
<form action="/" method="get">
<StyledInputBase
defaultValue={searchQuery}
// placeholder="Search All Games…"
inputProps={{ "aria-label": "search" }}
type="search"
name="s"
id="site-search"
/>
</form>
<SearchIconWrapper>
<IconButton>
<SearchIcon style={{ color: "#55597d" }} />
</IconButton>
</SearchIconWrapper>
</Search>
</Box>
);
}
You need to remove the width: 100% in the SearchIconWrapper on the right first. And because the Search component is a flex container, you also need to add flexGrow: 1 to the first child (the form) so it can expand to fit the parent and push the icon to the far right:
const Search = styled("div")(({ theme }) => ({
display: "flex",
position: "relative",
borderRadius: 30,
backgroundColor: "#ffffff",
border: "1px",
borderStyle: "solid",
borderColor: "#55597d",
// marginLeft: 10,
// ---------------------------------- add the following styles
"& :first-child": {
flexGrow: 1
}
width: "auto",
".MuiInputBase-root": {
width: "100%"
}
}));
const SearchIconWrapper = styled("div")(({ theme }) => ({
padding: theme.spacing(0, 2),
height: "100%",
// position: 'absolute',
// pointerEvents: 'none',
display: "flex",
alignItems: "center",
justifyContent: "flex-end"
// backgroundColor: 'black',
// -----------------------------------> comment this line: width: "100%"
}));

How can I scroll on my Page when my Dialog Component has been opened

I want to scroll on the background, when my dialog component opens up. By default, you cannot scroll when the dialog appears. How can I scroll in the background ?
Following is the Code:-
import React, { useState } from 'react';
import {
makeStyles,
Grid,
Button,
Dialog,
DialogActions,
DialogTitle,
} from '#material-ui/core';
import ShoppingCartIcon from '#material-ui/icons/ShoppingCart';
import CloseIcon from '#material-ui/icons/Close';
const styles = makeStyles((theme) => ({
root: {
position: 'fixed',
bottom: '0 ',
left: '0',
right: '0',
boxShadow: '0 0 6px rgb(0 0 0 / 70%)',
backgroundColor: 'white',
height: '63px',
},
textStyle: {
fontFamily: 'Comfortaa',
},
icon: {
color: theme.palette.primary.dark,
},
btn: {
backgroundColor: theme.palette.primary.dark,
color: 'white',
fontFamily: 'Comfortaa',
'&:hover': {
backgroundColor: theme.palette.primary.dark,
},
},
title: {
display: 'flex',
justifyContent: 'flex-end',
borderBottom: '1px solid #e5e5e5',
},
closeIcon: {
color: theme.palette.primary.light,
'&:hover': {
color: 'black',
},
},
dialogStyle: {
backgroundColor: 'white',
position: 'absolute',
top: 0,
},
dialogContainer: {
opacity: 0,
},
dialogTitle: {
display: 'flex',
justifyContent: 'flex-end',
borderBottom: '1px solid #e5e5e5',
},
}));
const CartAppBar: React.FC = () => {
const classes = styles();
const [open, setOpen] = useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<>
<Grid
item
container
direction='row'
justify='space-around'
alignItems='center'
className={classes.root}
xs={12}
>
<div>
<ShoppingCartIcon
fontSize='large'
classes={{ root: classes.icon }}
onClick={handleClickOpen}
/>
</div>
<div>
<Button
className={classes.btn}
type='submit'
onClick={() => {
return (window.location.href = '/checkout');
}}
>
Checkout
</Button>
</div>
</Grid>
<Dialog
open={open}
onClose={handleClose}
aria-labelledby='alert-dialog-title'
aria-describedby='alert-dialog-description'
maxWidth='md'
fullWidth
classes={{
paper: classes.dialogStyle,
container: classes.dialogContainer,
}}
scroll='paper'
>
<DialogTitle className={classes.dialogTitle}>
<CloseIcon
onClick={handleClose}
classes={{ root: classes.closeIcon }}
/>
</DialogTitle>
{/* Footer */}
{/* <DialogActions className={classes.footer}>
<Button classes={{ root: classes.btn }}>Add To Cart</Button>
</DialogActions> */}
</Dialog>
</>
);
};
export default CartAppBar;
As you can see in the photo, there's opacity in the background and you cannot scroll. I want to override this and make the background scrollable
use disableScrollLock as prop will help

div alignment is not properly working on the header with menu [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Closed 2 years ago.
I try to align my menu properly but it's not working properly. So the way it's done is that when you arrive on my website and not logged in, the header below is displayed:
When the user is loggedin, the login/register is replaced by a scrolldown menu which is triggered by the click of an avatar. The scroll down works fine but the render of the menu is not aligned as you see below:
I am not able to make the avatar and the menu properly aligned as it's done at first.
below is code:
const fakeName = "First Last";
const isGuest = false;
const StyledProfileMenu = withStyles({
paper: {
border: '1px none',
borderRadius: "21px",
boxShadow: "0px 8px 18px 0 rgba(0,0,0,0.14)",
},
})((props) => (
<Menu
elevation={0}
getContentAnchorEl={null}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'center',
}}
{...props}
/>
));
const StyledProfileMenuItem = withStyles((theme) => ({
root: {
margin: "2px 30px 1px 10px",
fontFamily: "Source Sans Pro",
fontSize: "",
'&:hover': {
backgroundColor: "#ffffff",
color: '#ff7255'},
'&:focus': {
backgroundColor: "#ffffff",
color: '#ff7255'},
},
}))(MenuItem);
const useStyles = makeStyles(theme => ({
root: {
boxShadow: "none",
backgroundColor: "#ffffff",
marginTop: theme.spacing(3)
},
logo: {
width:"214px",
height:"28px",
marginLeft: theme.spacing(20),
marginRight: theme.spacing(3)
},
search: {
position: 'relative',
borderRadius: "21px",
backgroundColor: "#f4f7f8",
marginRight: theme.spacing(2),
marginLeft: theme.spacing(3),
width: "467px",
height: "40px",
// [theme.breakpoints.up('sm')]: {
// marginLeft: theme.spacing(3),
// width: 'auto',
// },
},
searchIcon: {
padding: theme.spacing(1, 2),
height: '18px',
width: '18px',
position: 'absolute',
pointerEvents: 'none',
alignItems: 'center',
justifyContent: 'center',
color: "#cecece"
},
inputRoot: {
color: "#cecece",
fontFamily: "Source Sans Pro",
fontSize: "18px"
},
inputInput: {
paddingLeft: `calc(1em + ${theme.spacing(4)}px)`,
width: "467px",
// [theme.breakpoints.up('md')]: {
// width: '20ch',
// },
},
menu: {
display: "flex",
marginLeft: theme.spacing(2),
margin: "auto",
},
menuItem: {
color: "#cecece",
fontSize: "20px",
fontFamily: "Fredoka One",
fontWeight: "bold",
'&:hover': {
backgroundColor: "#ffffff",
color: '#ff7255'},
'&:focus': {
backgroundColor: "#ffffff",
color: '#ff7255'},
marginRight: theme.spacing(3),
marginLeft: theme.spacing(3),
},
userName: {
fontFamily: "Source Sans Pro",
fontWeight: "Bold",
borderBottom: '3px solid #ff7255',
textAlign: "center",
margin: "2px 10px 2px 10px",
paddingBottom: "2px"
}
}));
function Header(){
let loginOrProfile;
const styles = useStyles();
const [anchorEl, setAnchorEl] = React.useState(null);
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const profileMenu =
<div>
<IconButton
aria-controls="customized-menu"
aria-haspopup="true"
variant="contained"
color="primary"
onClick={handleClick}>
<Avatar alt="Avatar" src={DefaultAvatar} />
<ArrowDropDownIcon style={{ color: "#ff7255" }}/>
</IconButton>
<StyledProfileMenu
id="customized-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}>
<p className={styles.userName}> {fakeName} </p>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuProfile} />
</StyledProfileMenuItem>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuMessages} />
</StyledProfileMenuItem>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuSettings} />
</StyledProfileMenuItem>
<StyledProfileMenuItem>
<ListItemText primary={TextContents.MenuLogout} />
</StyledProfileMenuItem>
</StyledProfileMenu>
</div>;
const loginMenu =
<Typography className={styles.menuItem}> {TextContents.MenuLoginRegister} </Typography>;
if(isGuest){
loginOrProfile = loginMenu;
} else {
loginOrProfile = profileMenu;
}
return (
<div className={styles.root}>
<AppBar position="static" className={styles.root}>
<Toolbar>
<img src={VillageLogo} alt="logo" className={styles.logo}/>
<div className={styles.search}>
<div className={styles.searchIcon}>
<SearchIcon />
</div>
<InputBase
placeholder={TextContents.SearchPlaceHolder}
classes={{
root: styles.inputRoot,
input: styles.inputInput,
}}
inputProps={{ 'aria-label': 'search' }}
/>
</div>
<div className={styles.menu}>
<Typography className={styles.menuItem}> {TextContents.MenuDiscover} </Typography>
<Typography className={styles.menuItem}> {TextContents.MenuCreate} </Typography>
<Typography className={styles.menuItem}> {TextContents.MenuHiW} </Typography>
{isGuest && loginMenu}
{!isGuest && profileMenu}
</div>
</Toolbar>
</AppBar>
</div>
);
}
export default Header
If someone may have any idea how to make the alignment proper, I would be super happy
try this:
display: flex;
align-items: center;

Background image refusing to cover full page

This is the page component itself, it was working fine before but somewhy it started acting like this.
I didn't update any packages it just broke i think the problem is the parent component height is not defined so the child component sets the height to fit content only.
import React, { Component } from 'react';
import Navbar from './navbar';
import { withStyles } from '#material-ui/core/styles';
import Avatar from '#material-ui/core/Avatar';
import Grid from '#material-ui/core/Grid';
import Chip from '#material-ui/core/Chip';
import amumu from '../Images/amumusad.png';
import Modal from 'react-responsive-modal';
import fortniteDab from '../Images/fortnitedab.png';
import compose from 'recompose/compose';
import { withNamespaces } from 'react-i18next';
import {connect} from 'react-redux';
import ListItem from '#material-ui/core/ListItem';
import ListItemText from '#material-ui/core/ListItemText';
import {CopyToClipboard} from 'react-copy-to-clipboard';
import Snackbar from '#material-ui/core/Snackbar';
import Tooltip from '#material-ui/core/Tooltip';
import {Helmet} from "react-helmet";
const styles = theme => ({
chip: {
minWidth: 350,
margin: theme.spacing.unit,
fontSize: 14,
[theme.breakpoints.up('sm')]: {
fontSize: 20,
}
},
fab: {
margin: theme.spacing.unit,
fontSize: 10,
minWidth: 250,
maxWidth: 250,
[theme.breakpoints.up('lg')]: {
fontSize: 12,
minWidth: 250,
maxWidth: 250,
}
},
fbAvatar: {
margin: 10,
width: 50,
height: 50,
fontSize: 20,
color: '#fff',
fontWeight: 'bold',
backgroundColor: '#3F51B5',
},
emailAvatar: {
margin: 10,
width: 50,
height: 50,
fontSize: 20,
color: '#fff',
fontWeight: 'bold',
backgroundColor: '#f50057',
},
container: {
display: 'flex',
flexWrap: 'wrap',
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
backgroundColor: '#fff',
width: 240
},
resize:{
fontSize:17
},
extendedIcon: {
marginRight: theme.spacing.unit * 3,
},
descStyle: {
fontSize: 12,
color: 'white',
textAlign: 'center',
[theme.breakpoints.up('sm')]: {
fontSize: 15,
}
},
});
const ErrorStyle = {
overlay: {
background: "transparent"
},
modal: {
backgroundColor: 'rgba(219, 105, 105, 0.9)',
color: "white",
borderRadius: '10px',
},
}
const SuccessStyle = {
overlay: {
background: "transparent"
},
modal: {
backgroundColor: 'rgba(124, 214, 105, 0.9)',
color: "white",
borderRadius: '10px',
width: 400
},
}
class Contact extends Component {
state = {
Url: this.props.server.main,
name: "",
email: "",
subject: "",
body: "",
payload: "",
ErrorModal: false,
ErrorMsg: '',
SuccessModal: false,
SuccessMsg: '',
copied: false
}
updateInput(key, value) {
this.setState({ [key]: value });
}
onChange = (value) => {
this.setState({captcha: value})
}
onOpenModal = (type) => {
this.setState({[type]: true });
};
onCloseModal = (type) => {
this.setState({[type]: false });
};
render() {
const { classes } = this.props;
const { t } = this.props;
return (
<div className="GG-BG-INVERSE">
<Helmet>
<title>{t('contactTitle')}</title>
<meta name="description" content={t('contactTitle')} />
</Helmet>
<Navbar page={2}/>
<div className="container">
<div className="BlackBG">
<div style={{height: 70, margin: 10}}>
<Grid container justify="center" alignItems="center">
<Chip
icon={<Avatar className={classes.fbAvatar}>F</Avatar>}
label={t('contactFBTitle')}
className={classes.chip}
color="default"
/>
</Grid>
</div>
<div style={{height: 50}}>
<Grid container justify="center" alignItems="center">
</Grid>
</div>
<Grid container justify="center" alignItems="center">
<Chip
icon={<Avatar className={classes.emailAvatar}>#</Avatar>}
label={t('contactEmailTitle')}
className={classes.chip}
color="default"
/>
</Grid>
<ListItem className={classes.descStyle}>
<ListItemText disableTypography primary={t('contactRule1')} />
</ListItem>
<ListItem className={classes.descStyle}>
<ListItemText disableTypography primary={t('contactRule2')} />
</ListItem>
<Snackbar
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
open={this.state.copied}
onClose={()=>{this.setState({ copied: false })}}
transitionDuration={500}
autoHideDuration={1000}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<h4 id="message-id">{t('copiedEmail')}</h4>}
/>
</div>
</div>
<Modal open={this.state.ErrorModal} onClose={this.onCloseModal.bind(this,'ErrorModal')} center
styles={ErrorStyle}>
<h3 className="col-xs-6">{this.state.ErrorMsg}</h3>
<img style ={{width: 150, height: 120}} className="col-xs-6" src={amumu} alt=""></img>
</Modal>
<Modal open={this.state.SuccessModal} onClose={this.onCloseModal.bind(this,'SuccessModal')} center
styles={SuccessStyle}>
<h3 className="col-xs-6">{this.state.SuccessMsg}</h3>
<img style ={{width: 150, height: 120}} className="col-xs-6" src={fortniteDab} alt=""></img>
</Modal>
</div>
);
}
}
function mapStateToProps(state){
return {
server: state.server
}
}
export default compose(
withStyles(styles),
withNamespaces(),
connect(mapStateToProps),
)(Contact);
The background image only covers the content and then breaks after leaving the left space on the screen blank, as shown in this picture:
Here's my css code for the background image:
.blackBackground {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: #121212;
}
I would say the div containing the background image is the issue here. Make sure that the div expands the full width and height so then the background image will follow.
Try adding width: 100%; to
.blackBackground {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: #121212;
width: 100%
}
After your question edit:
Your container is wrapping the black background. You can try container-fluid or rework your code like this:
<Navbar page={2}/>
<div className="BlackBG">
<div className="container">
...
This way the black background is not being constrained by the width of the container.

Resources