[image 1[image 2]
Image 1: Normal View,
Image 2: When keyboard is enabled the card jumps up and when I close its normal
Is this behavior normal? or there's some fault in my CSS. I used styled-components for writing the CSS.
CSS
export const Container = styled.section`
height: 92vh;
display: flex;
justify-content: center;
align-items: center;
background: #f5f5f5;
`;
export const Form = styled.form`
display: flex;
flex-direction: column;
align-items: center;
`;
export const Card = styled.section`
width: ${(props) => props.Width || '22rem'};
height: fit-content;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 1rem;
border-radius: 5px;
box-shadow: 0px 2px 4px rgba(68, 47, 47, 0.5);
background: white;
`;
export const Header = styled.header`
min-height: 7vh;
background: rgb(0, 5, 36);
`
Login.js
import React from 'react';
import {
Card,
Container,
Form,
} from '../Styles/StyledProfile';
import TopHeader from '../Dashboard/Header';
function Login() {
return (
<>
<TopHeader />
<Container>
<Card>
<Form>
.....
</Form>
</Card>
</Container>
</>
)
}
I think this is normal behavior but if you want to prevent login box to be on the top of the header, you could add this CSS:
export const Container = styled.section`
min-height: 92vh;
height: 100%;
`;
export const Card = styled.section`
margin: 40px 0;
`;
Related
I am trying to align Text on the left and button controls on right in display: flex div.
<CustomFieldContainer>
<StyledWellContainer>
<FieldDetails key={id}>
<H4 bold>{label}</H4>
<StyledBody>({capitalizeFirst(type)}) {required && <StyledSpan>REQUIRED</StyledSpan>} </StyledBody>
</FieldDetails>
<DeleteAction {...props} />
</StyledWellContainer>
</CustomFieldContainer>
this to what I got so far.
below is the CSS for all the above reactjs elements.
const CustomFieldContainer = styled.div`
display: flex;
flex-direction: row;
`;
const FieldDetails = styled.div`
display: flex;
flex-direction: column;
border: none;
`;
const DeleteButton = styled(Button)`
flex-basis:33.33%;
margin-right: 0;
margin-left:auto;
display:block;
`;
this makes
what I am trying to achieve is very simple, as below
any help would be tremendous, the basic idea is to main a container to have texts on the left and controls on the right. thank you.
Update:
const StyledWellContainer = styled(WellContainer)`
margin-right: 1rem;
width: 100%;
padding-bottom: 2px;
padding-top: 0;
`;
import styled from 'styled-components';
const WellContainer = styled.div`
display: flex;
flex-direction: column;
padding: 1rem;
border: ${({ theme, borderType }) => (borderType === 'attention' ? theme.color.border.negative : theme.color.border.light)};
border-radius: 12px;
& > * {
padding-bottom: 1rem;
margin-bottom: 1rem;
border-bottom: ${({ theme, disableDivider }) => (disableDivider ? 'none' : theme.color.border.light)};
}
& > :last-child {
padding-bottom: 0;
margin-bottom: 0;
border-bottom: none;
}
`;
export default WellContainer;
Update after changes, advised by adam.
Your StyledWellContainer styles need changing such that:
flex: 1 0;
display: flex;
flex-direction: row;
align-items: flex-start;
Currently it is a column, which is why the button appears below rather than by the side.
By adding row, this fixes that. flex: 1 0 tells it to stretch to fit the parent, and align-items: flex-start; will prevent the content of the button being stretched to height.
You also need to let the button be its base size and not tell it to grow:
const DeleteButton = styled(Button)`
flex: 0 0 auto;
margin-right: 0;
margin-left: auto;
`;
StyledWellContainer needs to be the flex container, not CustomFieldContainer
const StyledWellContainer = styled.div`
align-items: center;
display: flex;
flex-direction: row;
`;
const FieldDetails = styled.div`
display: flex;
flex: 2;
flex-direction: column;
height: 100%;
border: none;
`;
const DeleteButton = styled(Button)`
flex: 1;
margin-right: 0;
margin-left:auto;
display:block;
`;
I used ANTD and React and I want to customize the component step style, and I got this:
from the following CSS code:
/* step connector */
.ant-steps-item-title:after {
border: solid rgba(65, 64, 66, 0.1) !important;
}
/* step */
.ant-steps-item-icon{
width: 3em;
height: 3em;
display: flex; // ==> when i add this
justify-content: center; // ==> when i add this
align-items: center; // ==> when i add this
}
.ant-steps-item-process > .ant-steps-item-container > .ant-steps-item-icon {
background-color: #21D47E;
border-color: #21D47E;
}
/* size of step container */
.ant-steps{
width: 50%;
}
.ant-steps-horizontal .ant-steps-label-horizontal{
display: flex;
justify-content: center;
align-items: center;
}
When I add this to centering the number:
.ant-steps-item-icon{
width: 3em;
height: 3em;
display: flex; *
justify-content: center; *
align-items: center; *
}
the steps connector is missing like this:
and this is my react component calling Steps:
import { Steps } from 'antd'
import React from 'react'
import './index.css'
const { Step } = Steps
export const Tahap: React.FC = () => {
return (
<div style={{ padding: '50px' }}>
<Steps>
<Step />
<Step />
<Step />
<Step />
<Step />
<Step />
</Steps>
</div>
)
}
can anyone tell me how to re-display the connector? Thanks
To achieve the desired result, you need to use the display property with the inline-flex value instead of flex:
.ant-steps-item-icon {
width: 3em;
height: 3em;
display: inline-flex;
justify-content: center;
align-items: center;
}
It makes the flex container display inline.
[I created a card component which has wrapper div to wrap cards in it, the cards are display fine 1 in a row, however I want to display 3 in a row and unable to do it. I have tried display flex to show 1 in a row.
Cards component
import React from "react";
import "../index.css";
const Card = (props) => {
return (
<>
<div className="cards">
<div className="card">
<img src={props.imgSrc} alt="Dark" className="card-img" />
<div className="card-info">
<span className="card-category">{props.cat}</span>
<h3 className="card-title">{props.title}</h3>
<a href={props.link}>
<button>watch now</button>
</a>
</div>
</div>
</div>
</>
);
};
export { Card };
Index
import react from "react";
import ReactDOM from "react-dom";
import { Whole } from "./Whole";
import { Cards } from "./learningReact/Cards";
ReactDOM.render(
<>
<Cards />
</>,
document.getElementById("root")
);
css
cards {
display: flex;
justify-content: center;
align-content: center;
margin: 100px auto;
}
.card {
width: 250px;
height: 300px;
border: none;
background: rgb(248, 239, 248);
border-radius: 10px;
}
.card img {
width: 250px;
height: 200px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.card:hover {
transform: scale(1.1);
}
you should use flex-basis:33%; for .card div tag and flex-wrap:no-wrap; & justify-content: space-between; for .cards div tag:
.cards {
display: flex;
justify-content: space-between;
align-content: center;
margin: 100px auto;
flex-wrap:nowrap;
}
.card {
flex-basis:33%;
height: 300px;
border: none;
background: rgb(248, 239, 248);
}
<style>
.card-data {
display: flex;
flex-wrap: nowrap;
background-color: #000;
}
.card-data div {
background-color: #f1f1f1;
width: 33%;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
</style>
<div class="card-data">
<div>Hello..</div>
<div>Test...</div>
<div>Content..</div>
</div>
Replace the justify-content: center with justify-content: space-between inside .cards block and it will be displayed in a single row.
output here
I have 4 boxes which I'm using them as component , when I'm applying justify-content:center it is centering my items in terms of with , but when I'm trying to use align-items:center , it's not working , and the more confusing thing that I made body color teal and the whole page turned teal but in developer tools it shows that I only have small amount of height, so why the whole page turned to teal ?
import React from 'react';
import "./App.css"
function Myfunc(props){
return(
<div className="holder">
<h1>{props.text}</h1>
</div>
);
}
export default Myfunc;
import React from "react";
import Myfunc from "./CSSexample";
function App(){
return(
<div className="container">
<Myfunc text=""/>
<Myfunc text=""/>
<Myfunc text= ""/>
<Myfunc text=""/>
</div>
);
}
export default App;
*,
*::before,
*::after{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.holder{
background-color: crimson;
width: 10rem;
height: 10rem;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid white;
}
body{
display: flex;
justify-content: center;
align-items: center;
background-color: teal;
}
.container{
display: flex;
justify-content: center;
align-items: center;
color: white;
}
Try setting the width/height of container
.container {
display: flex;
justify-content: center;
align-items: center;
color: white;
height: 100vh;
width: 100vw
}
i have div wrapper with header and container divs and i want to place these in the center of the page.
below is the code,
return (
<Wrapper>
<Header><svg/></Header>
<Content>
<span>first</span>
<span> second</span>
<Actions>
<button> cancel</button>
</Actions>
</Content>
</wrapper>
);
const Wrapper = styled.div`
width: 100vw;
background-color: white;
height: calc(100vh - 20px);
position: relative;
`;
const Content = styled.div`
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
`;
const Actions = styled.div`
display: flex;
flex-direction: row;
justify-content: space-between;
`;
const Header = styled.div`
position: absolute;
width: 100%;
display: flex;
justify-content: center;
`;
how can i make the header and content divs to be in the center of the page using css. could someone help me with this. thanks.