I'm using an image and trying to position some text in front of the image and center, as seen in the screenshot from my design below:
I'm using the below code and found out how to layer the text over the top with z-index, but I'm wondering how I can center the text inside the parent div as seen in the design?
Code:
<div style={{ display: `flex`, flexDirection: `column` }}>
{/* image and title */}
<div>
<StaticImage
src="../images/home.png"
width={1000}
quality={100}
formats={["auto", "webp", "avif"]}
alt="home image"
style={{ marginBottom: `1rem`, zIndex: `1` }}
/>
<div style={{
position: `absolute`,
top: `50%`,
left: `50%`,
transform: `translate(-50%, -50%)`,
zIndex: `2`,
display: `flex`,
justifyContent: `spaceBetween`,
flexDirection: `row`
}}>
<h1 style={{
color: `white`,
fontSize: `7vw`
}}>Gareth</h1>
<h1 style={{
color: `white`,
fontSize: `7vw`
}}>Veale</h1>
</div>
</div>
</div>
However, this gives me the text centered on the entire page i think? Perhaps due to the 50% top/left properties?
you should set a width to the parent div to see the difference in flex alignment.
See the code below.
<div style={{ display: `flex`, flexDirection: `column` }}>
{/* image and title */}
<div>
<StaticImage
src="../images/home.png"
width={1000}
quality={100}
formats={["auto", "webp", "avif"]}
alt="home image"
style={{ marginBottom: `1rem`, zIndex: `1` }}
/>
<div style={{
position: `absolute`,
top: `50%`,
left: `10%`,
width: `80%`,
transform: `translate(-50%, -50%)`,
zIndex: `2`,
display: `flex`,
justifyContent: `spaceBetween`,
flexDirection: `row`
}}>
<h1 style={{
color: `white`,
fontSize: `7vw`
}}>Gareth</h1>
<h1 style={{
color: `white`,
fontSize: `7vw`
}}>Veale</h1>
</div>
</div>
As you can see i just changed the left and width parameters to get the expected result. I hope this will solve your problem
Related
Hey guys,
I have this rather weird problem on a react project, where i designed a main page with a looping background mp4 and some content on top, but it will not display properly on IOS devices. I have gotten repeated feedback from friends about this, but do not own an Iphone myself, which is why it is hard to test for me. I can still provide screenshots to make the issue more obvious.
Can you spot the issue or know where the behavior differs?
Current Look:
If you want to look at the live page (that has the issue): https://scanrecs.com
Desktop:
Desktop Image (Video Running)
Mobile (Android/ Chrome):
Mobile Image (Video Running)
Mobile (IOS/ safari):
Mobile IOS Image (Still Frame)
Underlying Code:
React Homepage:
function Home() {
return (
<div className="home">
<div className="container" style={{overflow: "hidden", width: "100vw"}}>
{/*Video and transparent black gradients */}
<div className="videoWrapper" style={{
width: "100vw",
height: "100vh",
backgroundColor: "black",
}}>
<video autoPlay loop muted id="backgroundVideo" style={{
width: "100%",
height: "100%",
objectFit: "cover",
zIndex: "0",
}}>
<source src={backgroundVideo} type="video/mp4" />
</video>
</div>
<div className="videoDimmer" style={{
width: "100vw",
height: "100vh",
position: "absolute",
top: "0",
backgroundColor: "rgba(0, 0, 0, 0.4)",
}} />
<div className="topGradient" style={{
backgroundImage: "linear-gradient(black, rgba(0, 0, 0, 0))",
height: "150px",
width: "100vw",
zIndex: "1",
position: "absolute",
top: "0px",
}} />
<div className="bottomGradient" style={{
backgroundImage: "linear-gradient(rgba(0, 0, 0, 0), black)",
height: "150px",
width: "100vw",
zIndex: "1",
position: "absolute",
bottom: "0px",
}} />
{/*From here on only Page Content*/}
<NavBar />
<div className="content">
<h1>Scan Records</h1>
<p><i><b>Record & Sample Label</b> - est. 2021</i> </p>
</div>
<LinkBar />
<div className="c" style={{
position: "absolute",
bottom: "10px",
left: "10px",
margin: "0 auto",
zIndex: "1",
display: "flex",
color: "white",
}}>
<div>© Scan Records UF / {new Date().getFullYear()}</div>
</div>
<div className="trustWidget" style={{
position: "absolute",
top: "300px",
right: "0px",
margin: "0 auto",
zIndex: "1",
display: "flex",
color: "white",
transform: "translateY(-50%)",
overflow: "hidden",
visibility: "hidden"
}}>
<img width="171px" height="241px" src={trustpilotCustomWidget} alt="Link to Trustpilot rating page for Scan Records"/>
</div>
</div>
</div>
);
}
export default Home;
There are seperate style sheets that customise the page contents (align and position), but the video and dimmers only have inline Styling, so I do not think this is necessary to show.
Dimmer => Black, transparent overlay(s) to make white text more readable
Alternativly with colorcoding from VsCode:
Screenshot from vsCode
Thank you in advance and hope you have a wonderful day,
if I forgot anything please just tell me and I can provide it,
-Felix
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>;
The words, and buttons are right next to each other to the left. How can I make the words stay on the left and the buttons stay on the right?
The picture of the page is below.
This is a page written in React.
The issue is somewhere in the Accordian.Header container. If you remove it, the elements stay on opposite sides of their container as desired.
<MainScreen title='Welcome Back Anthony!'>
<Button style={{ marginLeft: 10, marginBottom: 6 }} size='lg'>
Create New Note
</Button>
{notes.map((note) => (
<Accordion>
<Accordion.Item>
<Card style={{ margin: 10 }} key={note._id}>
<Accordion.Header style={{ width: '100%'}}>
<Card.Header style={{ display: 'flex' }}>
<span
style={{
color: 'black',
textDecoration: 'none',
flex: 1,
cursor: 'pointer',
alignSelf: 'center',
fontSize: 18,
}}
>
<div as={Card.Text}
variant='link'
eventKey='0'>
{note.title}
</div>
</span>
<div>
<Button href={`/note/${note._id}`}>Edit</Button>
<Button
variant='danger'
className='mx-2'
onClick={() => deleteHandler(note._id)}
>
Delete
</Button>
</div>
</Card.Header>
</Accordion.Header>
<Card.Body>
<Accordion.Body>
<h4>
<Badge variant='success'>
Category - {note.category}
</Badge>
</h4>
<blockquote className='blockquote mb-0'>
<p>
{note.content}
</p>
<footer className='blockquote-footer'>
Created on - date
</footer>
</blockquote>
</Accordion.Body>
</Card.Body>
</Card>
</Accordion.Item>
</Accordion>
))}
</MainScreen>
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",
},
}
Since I'm learning html/css I'm working and making some examples, and I want to create a div which would look like this, but my content is 'glued' together.
I've tried varios ways and noone of them is near this, since I'm really new to html / css!
If you run code below you might see it looks bad, there is no space between texts, nothing is vertically aligned, and I don't know how to position size to the middle of div.
Here is my code :
<div style={{ background: '#e1e1e1', marginBottom: '5px' }}>
<span id="delete" style={{ float: 'right', display: 'inline-block', padding: '2px 5px' }}>
x
</span>
<i className="icon ion-md-checkmark-circle" />
TestImg1.PNG
3.98KB
</div>
Could anyone help me to achieve this with explanation how it's done so I might learn a lot from it.
Thanks and cheers!
Thanks
You could use bootstrap's grid system instead.
<div class="container">
<div class="row row-grey align-items-center">
<div class="col-2">
<i class="material-icons icon-green">
check_circle
</i>
</div>
<div class="col-3">
File.png
</div>
<div class="col-6">
52kb
</div>
<div class="col-1">
x
</div>
</div>
</div>
Here's the fiddle
You could utilize Flexbox to handle the layout and ordering of your elements. Set display: flex on the parent <div>. Define the ordering of your elements using the ordering property with one being the first and three being the last. After that, assign margin-left: auto; to the delete element to push it to the end of the parent <div>. You can see the code rendered here: Codepen example
<div style={{ display: 'flex', background: '#e1e1e1', marginBottom: '5px', padding: '2px 5px' }}>
<span id="delete" style={{ order: '3', marginLeft: 'auto' }}>
x
</span>
<i className="icon ion-md-checkmark-circle" style={{ order: '1' }} />
<span style={{ order: '2', marginRight: '10px' }}>
TestImg1.PNG 3.98KB
</span>
</div>
You can also try Flex.
<div style={{ background: '#e1e1e1', marginBottom: '5px', display:flex }}>
<I style={{flex: 0}} className="icon ion-md-checkmark-circle" />
<span style={{flex: 1, marginLeft: 8px}}>
TestImg1.PNG
</span>
<span style={{flex: 1}}>
3.98KB
</span>
<span id="delete" style={{ flex: 0, padding: '2px 5px' }}>
x
</span>
</div>
display: flex is applied to the container.
flex: 1 applied to texts and it means automatically stretch with ratio 1.
flex: 0 applied to icons and it means don't stretch.
If you want to learn more, take a look at here