Question related to how to center align via flex attribute - reactjs

I want to make a page like this picture. To do this, I want to center the part drawn in blue, but my code doesn't work properly. What's wrong? Any advice would be appreciated.
import {
Col, Row,
} from 'react-bootstrap';
const content=css`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`;
const imageContianer=css`
width: 100%;
height: 60%;
`;
const About =()=>{
return (
<div css={content}>
<p>Who am I ?</p>
<div css={imageContianer}>
<Row>
<Col>
<img
src={ Icon }
width='200'
height='180'
alt='Icon' />
</Col>
<Col>
<p>First</p>
<p>Second</p>
<p>Third</p>
</Col>
</Row>
</div>
</div>
);
}
This is the result. The "Who am i" part even appears in the container above. What's the problem?

import {
Col, Row,
} from 'react-bootstrap';
const content=css`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`;
const imageContianer=css`
width: 100%;
height: 60%;
display: flex;
align-items: center;
justify-content: center;
`;
const rowContainer=css`
flex: 0 0 60% !important;
align-items: center;
justify-content: center;
`;
const About =()=>{
return (
<div css={content}>
<p>Who am I ?</p>
<div css={imageContianer}>
<Row css={rowContainer}>
<Col>
<img
src={ Icon }
width='200'
height='180'
alt='Icon' />
</Col>
<Col>
<p>First</p>
<p>Second</p>
<p>Third</p>
</Col>
</Row>
</div>
</div>
);
}
Hopfully code above can solve your problem. basicly you need to know how flex work, it's just like how grid on bootstrap css framwork does.
note: i haven't use styled-components like you do using css but i just follow your code example.
Playground
Leave a comment if my answer didn't working out the way want

Related

Nav bar is showing up overlapped with bullet points and 'HiOutlineMenuAlt4' icon is not appearing either

My nav bar is showing up overlapped with bullet points and 'HiOutlineMenuAlt4' icon is not appearing either. I am not sure what to do, I can't identify where the issue actually lies? Is it in the css?
Navbar.js
import React from 'react'
import {BiSearch} from 'react-icons/bi'
import {BsPerson} from 'react-icons/bs'
import {HiOutlineMenuAlt4} from 'react-icons/hi'
import './NavbarStyles.css'
function Navbar() {
return (
<div className='navbar'>
<div className='logo'>
<h2>BEACHES. </h2>
</div>
<ul className='nav-menu'>
<li>Home</li>
<li>Destinations</li>
<li>Travel</li>
<li>Book</li>
<li>Views</li>
</ul>
<div className='nav-icons'>
<BiSearch className='icon'/>
<BsPerson className='icon'/>
</div>
<div className='hamburger'>
< className='icon' />
</div>
</div>
)
}
export default Navbar
NavbarStyles.css
.navbar{
width: 100%;
height: 80px;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 1rem;
z-index: 2;
}
.nav-menu {
display: flex;
}
.hamburger{
display: none;
padding: 1rem;
}
No problems are listed so hard to decipher what to do next
Hi #Steph G,
About your icons HiOutlineMenuAlt4.
You are not using the imported HiOutlineMenuAlt4 icon in the hamburger div
<div className='hamburger'>
<HiOutlineMenuAlt4 className='icon' />
</div>
And about your CSS, that code is enough.
.navbar {
display: flex;
justify-content: center;
align-items: center;
}

React. Two buttons in a component but only one button works

I am practicing React basics.
I have a component mapped from an array of objects and it shows twice in my website but only on the second time the button works. the first button does not seem to be recognised.
Can someone explain why please? I can't find a reason for this but I am sure it is something obvious I am missing
A link to sandbox
App.js
import MainComponent from "./components/MainComponent";
function App() {
return (
<div>
<MainComponent />
</div>
);
}
export default App;
MainComponent.js
import React from "react";
import TextItem from "./TextItem";
const text = [
{
image:
"https://pbs.twimg.com/profile_images/626298192418607105/4KBKHQWi_400x400.jpg",
title: "This is a whale",
subtitle: "It is a large mammal",
price: "£ 167.87 + VAT",
uom: "per Unit",
},
{
image:
"https://news.artnet.com/app/news-upload/2019/01/Cat-Photog-Feat-256x256.jpg",
title: "This is a cat",
subtitle: "It is a small mammal",
price: "£ 17.87 + VAT",
uom: "per Unit",
},
];
const MainComponent = () => {
return (
<div>
{text.map((eachText, i) => (
<TextItem
key={i}
image={eachText.image}
title={eachText.title}
subtitle={eachText.subtitle}
price={eachText.price}
uom={eachText.uom}
/>
))}
</div>
);
};
export default MainComponent;
TextItem.js
import React from "react";
import styled from "styled-components";
import Card from "../UI/Card";
const TextItem = (props) => {
const onClickHandler = () => {
console.log("clicked");
};
return (
<Card>
<DivFlex>
<ImgDiv>
<img src={props.image} alt={"a whale"} />
</ImgDiv>
<TitleDiv>
<h1>{props.title}</h1>
<h3>{props.subtitle}</h3>
</TitleDiv>
<PriceDiv>
<h2>{props.price}</h2>
<h2>{props.uom}</h2>
</PriceDiv>
<EditDiv>
<Button onClick={onClickHandler}>Edit this</Button>
</EditDiv>
</DivFlex>
</Card>
);
};
const DivFlex = styled.div`
display: flex;
justify-content: center;
align-items: center;
width: 800px;
height: 600px;
`;
const ImgDiv = styled.div`
width: 90px;
height: 90px;
margin-right: 3%;
img {
max-width: 100%;
height: 100%;
border-radius: 6px;
}
`;
const TitleDiv = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
width: 30%;
margin-right: 3%;
`;
const PriceDiv = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-end;
width: 20%;
margin-right: 3%;
`;
const EditDiv = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
width: auto;
margin-left: 3%;
`;
const Button = styled.div`
outline: none;
border: none;
background: maroon;
color: white;
padding: 1.2rem 1.8rem;
font-size: 22px;
border-radius: 8px;
cursor: pointer;
`;
export default TextItem;
This is happening due to the conflicting heights of Card and DivFlex. The Card has an height of 140px but its child DivFlex has a height of 600px. So, the next item is basically overlapping the previous item and hence you are not able to click the first button. You can observe the same behaviour if you had any number of items. Only the last item would be clickable due to it overlapping on top of previous item.
One way to fix this is to remove the height from Card component and change the height of DivFlex to 140px instead.
PS: It didn't happen in the replica sandbox because you didn't use the Card component there and used a regular div which by default has a height of auto

React(Styled Components)Navbar link not working

I am trying to allow the navbar to take you to each part of the website but it isnt working for some reason. It is only a one page website and I have another up & running website with the same Example it takes me right to the section, but on this website it just doesnt seem to work does anyone have a clue? Heres my code from navbar.jsx and a link to the github
https://github.com/Justin7933/chidgo
import React from 'react';
import styled from 'styled-components';
const Container = styled.div`
height: 50px;
`;
const Wrapper = styled.div`
padding: 10px 20px;
display: flex;
align-items: center;
justify-content: space-between;
`;
const Left = styled.div`
width: 60%;
display: flex;
align-content: center;
justify-content: space-between;
`;
const Logo = styled.h1`
font-weight: bold;
text-decoration: underline crimson;
`;
const Menu = styled.nav`
display: flex;
list-style: none;
cursor: pointer;
#media only screen and (max-width: 480px) {
display: none;
}
`;
const MenuItem = styled.a`
margin-right: 30px;
font-size: 20px;
font-weight: bold;
color: gray;
text-decoration: none;
`;
const Button = styled.button`
border:2px solid white;
padding: 10px 15px;
background-color: crimson;
color: white;
font-weight: bold;
border-radius: 10px;
cursor: pointer;
`;
const Navbar = () => {
return (
<Container>
<Wrapper>
<Left>
<Logo>chidgo</Logo>
<Menu>
<MenuItem href="#intro">Home</MenuItem>
<MenuItem href="feature">Features</MenuItem>
<MenuItem href="#service">Services</MenuItem>
<MenuItem href="#price">Pricing</MenuItem>
<MenuItem href="#contact">Contact</MenuItem>
</Menu>
</Left>
<Button>JOIN TODAY</Button>
</Wrapper>
</Container>
)
}
export default Navbar
To be honest, I dont master the way that you coded yet, so I might embarrass mysef for lack of knowledge, but, have being said that:
Are you not forgeting to wrapp the proprer places with a < section id="">? Like is show here in the code of your contact componet:
<Container>
==>>>> <section id="contact">
<Wrapper>
<FormContainer>
<Title>
Questions? <br /> Let's Get In Touch
</Title>
<Form onSubmit={onSubmit}>
<LeftForm>
<Input name="from_name" value={toSend.from_name}
onChange={handleChange} placeholder="Your Name" />
<Input name="reply_to" value={toSend.reply_to}
onChange={handleChange} placeholder="Your Email" />
<Input placeholder="Subject" />
</LeftForm>
<RightForm>
<textarea name="message" className="TextArea" maxLength="100" value={toSend.message}
onChange={handleChange} placeholder="Your Message"/>
<Button type="submit">Send</Button>
</RightForm>
</Form>
</FormContainer>
<AddressContainer>
<AddressItem>
<Icon src={Map} />
<Text>Plymouth County, Hanson, Massachusetts</Text>
</AddressItem>
<AddressItem>
<Icon src={Phone} />
<Text>+7812175728</Text>
</AddressItem>
<AddressItem>
<Icon src={Send} />
<Text>damon.justin#outlook.com</Text>
</AddressItem>
</AddressContainer>
</Wrapper>
===>>> </section>
</Container>
At least, I had looked for thoose "targets" from your navebar and I have not found them in any file.

#media query display block not working in #emotion/react

I have a style like this
//inside page.jsx
export function Page() {
return (
<div css={container}>
<div css={header}>
<div css={horizontal}>
<Menu
mode="horizontal"
>
<Menu.Item>
<Link href="#>
<a>Menu A</a>
</Link>
</Menu.Item>
</Menu >
</div>
</div>
</div>
)
}
//inside styles.js
export const horizontal = css`
display: none;
#media (min-width: 720px) {
display:block;
}
`
export const header= css`
height: 10%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 20px;
background-color: white;
position: sticky;
top: 0;
z-index: 1;
`
When testing the browser with a size less than 720px its works as intended the content is invisible because of display none, but when the browser size is back to more than 720px it's not working at all (not going back to visible).
if I replace the Menu component with another component the style is working properly (when less than 720px = invisible and when more than 720px = visible). Also, it can work with the Menu component if removing display flex in the header style.
I'm a bit confused about what going on here.

Can't line up the item list horizontally using flex-box & styled-components

I want line up items in item-list.
This is item-list block and css
const ItemListBlock = styled.div`
display: flex;
width: 90%;
flex-direction: row;
margin-top: 3rem;
flex-wrap: wrap;
`;
<ItemListBlock>
<div>
{items.map(item => (
<Item className="item" item={item} key={item.id} />
))}
</div>
</ItemListBlock>
and This is item block and css (It's a little abbreviated.)
const PostItemBlock = styled.div`
display: flex;
width: 352px;
flex-direction: column;
padding-top: 0;
padding-bottom: 3rem;
p {
margin-top: 2rem;
}
h3 {
width: 352px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.subdesc {
align-self: flex-end;
}
`;
const Item = ({ item }) => {
return (
<ItemBlock>
<h3>
title.
</h3>
<p1 className="subdesc">subdesc.</p1>
</ItemBlock>
);
};
I want display item list like this :
But It actually display like this :
I wrote flex-direction:row. But It still line up vertically. How can I line up items horizontally??
PostItemBlock should be inline currently it is block: Change it to display: inline-flex

Resources