I'm designing a product detail page with React and Material UI. I tried to make the page responsive. But the description section keeps overlapping over the image until the screen is reduced to the mobile size. The content gets stacked at that point, but the images and text are not adjusting to the screen size.
I feel like it's something wrong with the image styling. How do I get the images to be responsive?
Here's my code
styling section
const useStyles = makeStyles((theme) => ({
content: {
flexGrow: 1,
padding: theme.spacing(3),
},
toolbar: {
display: "flex",
alignItems: "center",
justifyContent: "flex-end",
padding: theme.spacing(0, 1),
// necessary for content to be below app bar
...theme.mixins.toolbar,
},
}));
function
export default function ProductDetails() {
const classes = useStyles();
return (
<main className={classes.content}>
<div className={classes.toolbar} />
<Grid container spacing={3}> {/* image and description container */}
<Grid item xs={12} sm={6}> {/* image container */}
<Grid> {/* preview image */}
<img src="luxury-watch.jpg" width="600" id="preview" alt="" />
</Grid>
<Grid> {/* sub images */}
<img src="luxury-watch.jpg" width="140" id="img1" alt="" />
<img src="luxury-watch.jpg" width="140" id="img2" alt="" />
<img src="luxury-watch.jpg" width="140" id="img3" alt="" />
<img src="luxury-watch.jpg" width="140" id="img4" alt="" />
</Grid>
</Grid>
<Grid item xs={12} sm={6}> {/* description container */}
<div>
<h1>ROLEX</h1>
<p> .... </p>
<h2><span><sup>$</sup></span>1250</h2>
<Button variant="contained" color="secondary">ADD TO CART</Button>
</div>
</Grid>
</Grid>
</main>
);
}
I think you've missed a few props on your Grid elements. Try this:
export default function ProductDetails() {
const classes = useStyles();
return (
<main className={classes.content}>
<div className={classes.toolbar} />
<Grid container spacing={3}> {/* image and description container */}
<Grid item container xs={12} sm={6}> {/* image container */}
<Grid item> {/* preview image */}
<img src="luxury-watch.jpg" width="600" id="preview" alt="" />
</Grid>
<Grid item> {/* sub images */}
<img src="luxury-watch.jpg" width="140" id="img1" alt="" />
<img src="luxury-watch.jpg" width="140" id="img2" alt="" />
<img src="luxury-watch.jpg" width="140" id="img3" alt="" />
<img src="luxury-watch.jpg" width="140" id="img4" alt="" />
</Grid>
</Grid>
<Grid item container xs={12} sm={6}> {/* description container */}
<div>
<h1>ROLEX</h1>
<p> .... </p>
<h2><span><sup>$</sup></span>1250</h2>
<Button variant="contained" color="secondary">ADD TO CART</Button>
</div>
</Grid>
</Grid>
</main>
);
}
You can't apply xs attribute if your Grid items isn't a container and you console should be warning you about that too
You can use material ui breakpoints for responsiveness
const useStyles = makeStyles((theme) => ({
content: {
flexGrow: 1,
padding: theme.spacing(3),
},
toolbar: {
display: "flex",
alignItems: "center",
justifyContent: "flex-end",
padding: theme.spacing(0, 1),
// necessary for content to be below app bar
...theme.mixins.toolbar,
[theme.breakpoints.down('lg')]:{
width:'60%',
},
[theme.breakpoints.up('lg')]:{
width:'60%',
}
}
}));
Related
I have a problem with setting video like a background. As you can see on picture, when I scroll at the bottom, my video is not ending before footer. It's displaying also after the footer. Image
Here is the part of code were I placed my video and btw, this video like a background needs to be only on this page.
return (
<>
<video src={videoBackground} autoPlay muted></video>
<Container style={{ padding: 0, margin: 0 }}>
<WrapperPage>
<WrapperContainer>
<Container maxWidth="sm">
<Box
sx={{
maxWidth: "100%",
my: 3,
textAlign: "center",
}}
>
<h1>
<div
className="wordSize animate__animated animate__bounceInDown"
style={{ fontSize: "6rem" }}
>
Blokaria
</div>
<div
className="animate__animated animate__bounceInUp wordSize"
style={{ fontSize: "2.5rem" }}
>
<div>Where we create unique value</div>
</div>
</h1>
<Typography></Typography>
</Box>
</Container>
{staniIbarVodo ? showData : ""}
<Container maxWidth="sm" sx={{ mt: 5, mb: 5, textAlign: "center" }}>
<Grid container spacing={4} direction="row" sx={{ my: 3 }}>
<Grid item xs={12} md={6}>
<Typography variant="h6" align="center" sx={{ mb: 2 }}>
{t("how-to-create-qr-code")}
</Typography>
<YoutubeEmbed embedId="1cz9q9OQ6Kg" />
<Typography component="legend">User reviews</Typography>
<Rating name="read-only" value={5} readOnly />
</Grid>
<Grid item xs={12} md={6}>
<Typography variant="h6" align="center" sx={{ mb: 2 }}>
{t("howToCreateNft")}
</Typography>
<YoutubeEmbed embedId="aYuXCImLVPQ" />
<Typography component="legend">User reviews</Typography>
<Rating name="read-only" value={4} readOnly />
</Grid>
</Grid>
</Container>
</WrapperContainer>
</WrapperPage>
</Container>
<video src={videoBackground} autoPlay muted></video>
</>
);
Here is the CSS:
video {
width: 100vw;
height: 100vh;
object-fit: cover;
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: -1;
}
I really don't know what is the problem and if someone knows the solution, please help. Thank you!
Also I tried to set some static picture for background and everything is okay but this video makes me problem.
im trying to put an element Badge to the right of header menu in my page, but I don't know how do that, currently de Menu element of ant design push to another position the badge (bell icon):
The code:
const HeaderComp = (props) => {
let navigation = useNavigate()
const root= AppConfig.BucciaratiRoot.length>0 ? "/"+AppConfig.BucciaratiRoot:"/"
return (
<Layout>
<Header className="header" style={{position:'fixed', zIndex: 1, width: '100%'}}>
<div style={{float:'left', marginRight:'5%'}}>
<img style={{width: 120, height:31}} src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"/>
</div>
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']} >
<Menu.Item key="1" onClick={()=>navigation(root)}>Home</Menu.Item>
<Menu.Item key="3">About</Menu.Item>
</Menu>
<div style={{float:'right', marginLeft:'5%'}}>
<Badge dot>
<BellOutlined />
</Badge>
</div>
</Header>
</Layout>
)
}
How cain I put the badge to the right of the header menu ?
You can use flex instead of float, and then but every element you want to be at the right in a div and every element to the left in another div, and using some justify-content:"space-between" property in flex you can make the space left in the navbar to be in between those to divs.
See more on FlexBox
your code should look like:
return (
<Layout>
<Header
className='header'
style={{
position: "fixed",
zIndex: 1,
width: "100%",
display: "flex", // make the header flex
justifyContent: "space-between", // put all the space between the left and right sections of the menu
}}
>
<div className='header-left'>
{/* The left side of the menu */}
<div style={{ /* remove float */ marginRight: "5%" }}>
<img
style={{ width: 120, height: 31 }}
src='https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png'
/>
</div>
<Menu
theme='dark'
mode='horizontal'
defaultSelectedKeys={["1"]}
>
<Menu.Item key='1' onClick={() => navigation(root)}>
Home
</Menu.Item>
<Menu.Item key='3'>About</Menu.Item>
</Menu>
</div>
<div className='header-right'>
{/* The right side of the menu */}
<div style={{ /* remove float */ marginLeft: "5%" }}>
<Badge dot>
<BellOutlined />
</Badge>
</div>
</div>
</Header>
</Layout>
);
<Layout>
<Header
className="header"
style={{
position: 'fixed',
zIndex: 1,
width: '100%',
display: 'flex',
justifyContent: 'space-between',
}}
>
<div>
<div style={{ marginRight: '5%' }}>
<img
style={{ width: 120, height: 31 }}
src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Suzuki_Motor_Corporation_logo.svg/2560px-Suzuki_Motor_Corporation_logo.svg.png"
/>
</div>
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']}>
<Menu.Item key="1" onClick={() => navigation(root)}>
Home
</Menu.Item>
<Menu.Item key="3">About</Menu.Item>
</Menu>
</div>
<div style={{ marginLeft: '5%' }}>
<Badge dot>
<BellOutlined />
</Badge>
</div>
</Header>
</Layout>;
I am working on page layout using react-bootstrap. Along with that, I am using pure CSS for it. I have an alignment issue for Navbar on desktop view and mobile view. The components in the top bar should align with the components in the bottom bar in medium & large devices. The layout is different on the mobile device. In large devices Nav toggle bar expands and shrinks in the mobile devices when the user clicks on the toggle bar in the mobile screen, it expands down as shown in the figure. I hope the problem is clear. I have added the code and sample of the layout. Can someone help me to solve this issue?
CODE
<Container noGutters>
<Row className='main-nav d-flex' style={{ alignItems: 'center', justifyContent: 'flex-start' }}>
<Col sm={12} md={4} style={{ textAlign: 'center' }}>
<a href='/'>
visit mysite.com
</a>
</Col>
<Col sm={12} md={4} style={{ textAlign: 'center' }}>
<a href='#about-us'>
<picture>
<source srcSet={require('../public/assets/_logo.png?webp')} type='image/webp' />
<img className='cure-top-logo' src={'/assets/logo.png'} />
</picture>
</a>
</Col>
<Col sm={12} md={4}>
<Dropdown className='top-dropdown-container'>
<Dropdown.Toggle variant='success' id='dropdown'>
Choose an Item
</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item href='/'>ITEM 1</Dropdown.Item>
<Dropdown.Item href='/'>ITEM 2</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Col>
</Row>
</Container>
<Navbar style={{ maxHeight: '90px' }} className='sole-bottom-nav' expand={'lg'}>
<Container>
<div className='bottom-nav-logo-container'>
<a href='/cure-adventures/sole2soul'>
<div className='bottom-logo'>
<img alt='' src='assets/header.png' />
</div>
</a>
</div>
<Navbar.Toggle aria-controls='navlinks' />
<Navbar.Collapse id='navlinks'>
<Nav>
<Nav.Link className={activePage === 'about-us' ? ' active' : ''} href='/about-us'>
About Us
</Nav.Link>
<Nav.Link className={activePage === 'treks' ? ' active' : ''} href='/news'>
News
</Nav.Link>
<Nav.Link className={activePage === 'news' ? ' active' : ''} href='/contact'>
Contact us
</Nav.Link>
</Nav>
<div>
<a rel='noopener nofollow' target='_blank' href='https://twitter.com'>
<img src='/assets/twitter.png' width='25px' />
</a>
<a rel='noopener nofollow' target='_blank' href='https://facebook.com'>
<img src='/assets/facebook.png' width='25px' />
</a>
<a rel='noopener nofollow' target='_blank' href='https://instagram.com'>
<img src='/assets/instagram.png' width='25px' />
</a>
<a rel='noopener nofollow' target='_blank' href='/'>
<img src='/assets/linkdin.png' width='25px' />
</a>
</div>
<div>
<Button size={'lg'}>
button
</Button>
</div>
</Navbar.Collapse>
</Container>
</Navbar>
</div>
I have a problem building an UI.
I'm trying to copy this mockup found on dribbble.
I'm using React with Material UI and this is why I'm stuck:
I should have a kind of card with defined height (because there is another card of same height aside) with a first section of icon, title and a subtitle. Under this line it should be a grid layout with 2 rows and 3 columns that should define 6 equal containers with undefined and variable height and width and that's it
this is how my layout is shown at this point.
Now I should add the images of payment methods and I would like that it will behave like container remain of it's width and height and the image resizes and scale to fill the container (keeping its ratio) but when I try to add the images the MUI item grow to fit the content (image) growing its height. If you look at the last image you can see that the 1st row of the items is higher than the 2nd one. How can I fix that keeping the responsive layout?
Thank you all folks in advance.
Here is my code:
<Grid container md={5} xs={12} lg={6}
style={{
backgroundColor: "purple",
padding: 20,
display: "flex",
justifyContent: "center",
alignItems: "center"
}}>
<Grid container xs={12} md={10} lg={10}
style={{
backgroundColor: "grey",
padding: 20
}}>
<Grid item xs={3} lg={3}
style={{
height: 120,
padding: 10,
backgroundColor: "black"
}}>
<div style={{ height: "100%", backgroundColor: "grey" }} />
{/* today I'm so beautiful (: */}
</Grid>
<Grid item xs={9} lg={9}
style={{
height: 120,
padding: 10,
backgroundColor: "black"
}}>
<div style={{ height: "100%", backgroundColor: "red" }} />
</Grid>
</Grid>
<Grid container xs={12} lg={10}
style={{
height: 200,
backgroundColor: "green",
padding: 5,
}}>
<Grid item xs={6} lg={4} style={styles.paymentCardContainer}>
<div style={styles.paymentCard}>
<img src={paypal} style={styles.imgResponsive2} />
</div>
</Grid>
<Grid item xs={6} lg={4} style={styles.paymentCardContainer}>
<div style={styles.paymentCard}>
<img src={visa} style={styles.imgResponsive2} />
</div>
</Grid>
<Grid item xs={6} lg={4} style={styles.paymentCardContainer}>
<div style={styles.paymentCard} >
<img src={mastercard} style={styles.imgResponsive2} />
</div>
</Grid>
<Grid item xs={6} lg={4} style={styles.paymentCardContainer}>
<div style={styles.paymentCard} >
<img src={wise} style={styles.imgResponsive2} />
</div>
</Grid>
<Grid item xs={6} lg={4} style={styles.paymentCardContainer}>
<div style={styles.paymentCard}>
<img src={stripe} style={styles.imgResponsive2} />
</div>
</Grid>
<Grid item xs={6} lg={4} style={styles.paymentCardContainer}>
<div style={styles.paymentCard} >
<img src={payoneer} style={styles.imgResponsive2} />
</div>
</Grid>
</Grid>
</Grid>
And here's the style:
const styles = {
imgResponsive1: {
display: "flex",
justifyContent: "center",
alignItems: "center",
backgroundColor: "red",
padding: 20,
overflow: "hidden",
},
imgResponsive2: {
width: "100%",
height: "auto",
},
imgResponsive3: {
width: "100%",
height: "auto",
display: "flex",
justifyContent: "center",
alignItems: "center",
},
center: {
display: "flex",
justifyContent: "center",
alignItems: "center",
},
paymentCardContainer: {
padding: 10,
backgroundColor: "blue"
},
paymentCard: {
height: "100%",
backgroundColor: "red",
display: "flex",
justifyContent: "center",
alignItems: "center",
},
}
I have a main element which is divided into a grid of 3 columns.
in the middle column I am displaying some listings.
each listing is a div element and has a react bootstrap card inside it.
I am trying to get the card to span 100% of the parent but that doesn't seem to be working for me.
React component
<div className="backfill">
<Row key={Listing_Id}>
<Card style={{ cursor: 'pointer' }} border="light" className="text-center fullCard" >
<Card.Body>
<Card.Title className="Title">
{Listing_Name}
<hr />
<Button className="Button" variant="outline-success" onClick={() => props.handleLikeDisLike(Listing_Id, 'Listing_Likes', Listing_Location)}> <Twemoji options={options} text=":+1:" /></Button>
<Badge className="Badge" variant="light">{Listing_Likes}</Badge>
<Button className="Button" variant="outline-danger" onClick={() => props.handleLikeDisLike(Listing_Id, 'Listing_DisLikes', Listing_Location)}><Twemoji options={options} text=":-1:" /></Button>
<Badge className="Badge" variant="light">{Listing_DisLikes}</Badge>
<hr />
<Button className="Button" variant="outline-info" ><Twemoji text=":pushpin:" /></Button>
<Badge className="Badge" variant="light">{Listing_Location}</Badge>
</Card.Title>
<Card.Text className="Listing" onClick={() => handleClick(Listing_Id)} >
<hr />
{ListingBody}
<ModalLayout
Listing_Location={Listing_Location}
Listing_Likes={Listing_Likes}
Listing_DisLikes={Listing_DisLikes}
Listing_Name={Listing_Name}
Listing_Id={Listing_Id}
handleLikeDisLike={props.handleLikeDisLike}
handleClose={closeModal}
show={showModal} />
</Card.Text>
</Card.Body>
</Card>
</Row>
<br />
</div >
CSS for div and Card elements
.backfill {
background-color: aqua;
}
.fullCard {
width:'100%';
}
I currently end up with the UI looking like this. Please can you help me sort this out. I want to get the card to be 100% of its parent div.
Just had to remove the single quotes from the CSS
.fullCard {
width:'100%';
}
had to become
.fullCard {
width:100%;
}