// jsx in React.js
<Table>
<StyledTableBody>
{tradeInData.map(dataRow => {
return (
<FlexTableRow key={dataRow.productId}>
<StyledTableCell style={{flex : "3 1 auto !important"}}>
<ProductNameDiv>
<p>{dataRow.productName} ({dataRow.quantity})</p>
{showDeleteIcon && <DeleteOutline
style={{ cursor : "pointer" }}
/>}
</ProductNameDiv>
<SecondaryText>Id: {dataRow.productId}</SecondaryText>
</StyledTableCell>
<StyledTableCell style={{flex : "1 1 auto !important"}}
>{dataRow.price}</StyledTableCell>
</FlexTableRow>
)}
)}
</StyledTableBody>
</Table>
I want the flexbox on FlexTableRow to show the 2 elements below it at a 3:1 size ratio. You can see it's about 9:1 right now.
Looks like the flexbox on ProductNameDiv is consuming all the space. I can't set it to display: inline-block since it is also a flexbox.
I tried inline-block on the SecondaryText div and that seemed to overwrite the auto margins anyways.
What is the solution to this that will 1) preserve horizontal centering of text, 2) display the 2 children of FlexTableRow at roughly 3:1 horizontally?
// styled components
const StyledTableBody = styled(TableBody)`
* {
text-align: center;
}
`;
const FlexTableRow = styled(TableRow)`
display: flex;
> * {
border: 2px solid goldenrod !important;
}
`;
const StyledTableCell = styled(TableCell)`
border: 1px solid rgba(200, 200, 200, .6);
border-radius: 4px;
padding: 0 !important;
margin: 0 !important;
`;
const ProductNameDiv = styled.div`
border: 2px dashed lightgreen;
display: flex;
justify-content: center;
align-items: center;
`;
const SecondaryText = styled.p`
display: inline-block;
border: 2px dotted lightcoral;
font-style: italic;
font-size: .9rem;
margin: -12px auto 0 auto;
`;
As I was recreating the issue in a Codepen I found that Material UI's table elements caused the issue. I simply replaced them with standard HTML elements and the inner flexbox no longer fought against its own flex-grow setting:
const ReviewTable = styled.table`
max-width: 100vw;
`;
const FlexTableRow = styled.tr`
border: 1px solid rgba(200, 200, 200, .6);
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
`;
const StyledTableCell = styled.td`
border-radius: 4px;
padding: 0 !important;
margin: 0 !important;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
`;
const ProductInfoCell = styled(StyledTableCell)`
flex-grow: 3;
`;
const ProductPriceCell = styled(StyledTableCell)`
flex-grow: 1;
margin: 0 auto;
padding: 5px 0 !important;
`;
Related
I have just made this little UI at the top of the screen but would like to know how I can prevent the marked text from overflowing. I have tried the overflow:hidden property but that hasn't helped. Any help would be appreciated. The CSS element in question is ward_caption which is in the ward_no.css file
ward_no.jsx
import React, { useState } from "react";
import './ward_no.css';
import { IoMdArrowDropdown } from 'react-icons/io';
import { GoTriangleUp } from 'react-icons/go';
import wardData from '../../../json_data/ward.json';
const WardNo = () => {
const [open, setOpen] = useState(false);
const [ward, setWard] = useState(null);
const onSelect = (value) => {
setWard(value);
setOpen(!open);
}
return (
<div className="ward_no">
<div className="ward_caption">Ward No</div>
<div className="ward_block">
<div className="ward_dropdown">
<div className="ward_box">
{ward === null ? "Enter Ward Number" : ward}
</div>
<div className="ward_dropIcon" onClick={() => setOpen(prev => !prev)}>
{open ? <GoTriangleUp size={"25px"} /> : <IoMdArrowDropdown size={"30px"} />}
</div>
</div>
<div className={open ? "ward_option" : "ward_option_block"}>
{wardData.map((number) => <div className="ward_options" onClick={() => onSelect(number?.wardNo)}>
{number.wardNo}
</div>
)}
</div>
</div>
</div>
);
}
export default WardNo;
ward_no.css
.ward_no {
display: flex;
width: 100%;
height: auto;
}
.ward_caption {
flex: 1;
font-size: 30px;
/* overflow: hidden; */
font-weight: bold;
font-family: Georgia, 'Times New Roman', Times, serif;
margin-right: 20px;
}
.ward_block {
display: block;
flex: 3;
}
.ward_dropdown {
display: flex;
background-color: white;
height: 40px;
border-radius: 10px;
border: 2px solid black;
box-shadow: 1px 2px 4px 1px gray;
}
.ward_box {
display: flex;
/* flex-wrap: nowrap; */
justify-content: flex-start;
align-items: center;
flex: 4;
margin-right: 10px;
padding-left: 10px;
border-radius: 10px;
color: gray;
}
.ward_dropIcon {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
.ward_option_block {
display: none;
}
.ward_option {
display: block;
width: 100%;
height: 200px;
overflow: hidden;
overflow-y: scroll;
background-color: white;
border-radius: 10px;
border: 2px solid gray;
padding-left: 5px;
}
This component gets rendered from the main_screen.jsx file along with two other components placed side by side.
main_screen.jsx
import React from "react";
import './main_screen.css';
// import District from "../widgets/dropdowns/district/district";
import SearchBox from "../widgets/dropdowns/district/search_box";
import WardNo from "../widgets/dropdowns/ward_no/ward_no";
import Category from "../widgets/dropdowns/category/category";
const MainScreen = () => {
return (
<div className="mainScreen">
<div className="filterSearch">
<div className="disctrictDropdown">
<SearchBox></SearchBox>
</div>
<div className="wardNoDropdown"> //This is the component
<WardNo></WardNo>
</div>
<div className="categoryDropdown">
<Category></Category>
</div>
</div>
<div className="searchButton">
Search
</div>
</div>
);
}
export default MainScreen;
main_screen.css
.mainScreen, body {
background-color: white;
}
.mainScreen {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.filterSearch {
display: flex;
width: 100%;
flex-direction: row;
margin-top: 50px;
}
.disctrictDropdown {
flex: 1;
margin-left: 20px;
}
.wardNoDropdown { //This is the wardNoDropdown component
flex: 1;
margin-left: 20px;
}
.categoryDropdown {
flex: 1;
margin-right: 20px;
margin-left: 20px;
}
.searchButton {
display: flex;
justify-content: center;
align-items: center;
width: 150px;
height: 40px;
background-color: lightskyblue;
border-radius: 20px;
box-shadow: 1px 2px 4px 1px gray;
margin-top: 10px;
}
Two ways, which I know could work:
Try to add flex-direction: column; attribute to the display: flex container
This way it will make the text with those input fields ‚listed‘ underneath each other, which looks (for my preference) better
Add white-space: nowrap; to your text div
have problem with Css. Id like to set this form symmetricaly. Buttons would be in 1 column, textfields would be in 1 column also question mark i like to have it in 1 column.
Sorry for maybe bad ticket structure here. This is the second one in my life :) Im using React.js + Styled components
Design of the form atm
const ItemText = styled.div `
padding-top: 1%;
text-align: center;
display: block;
.form-inline {
flex-flow: row wrap;
align-items: center;
}
.form-inline label {
margin: 5px 10px 5px 0;
}
.form-inline input {
vertical-align: middle;
margin: 5px 10px 5px 0;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
}
.form-inline button {
padding: 10px 20px;
background-color: dodgerblue;
border: 1px solid #ddd;
color: white;
cursor: pointer;
}
.form-inline button:hover {
background-color: royalblue;
}
#media (max-width: 800px) {
.form-inline input {
margin: 10px 0;
}
.form-inline {
flex-direction: column;
align-items: stretch;
}
}
<ItemText>
<div className="App">
{
print? <h1>{dataWhen}</h1> :null
}
<div className="form-inline">
<label className="question">WHEN?</label>
<input className="webflow-style-input" type="text" placeholder="Sem piš" onChange ={getData}/>
<button type="submit" onClick={() => setPrint(true)}> Odeslat</button>
</div>
</div>
</ItemText>
You could just wrap your label inside a div with a fixed width
Then the length of your label won't change the placement of the other elements
I'm trying to position a div with an image outside my main Card component. I have tried using margin-bottom, however, it didn't work. How can it be done using CSS styled-component?
I will attach an image here of the design that I'm trying to achieve:]
https://imgur.com/a/EUHq4eE
Card Component:
function CardComponent(props) {
return (
<>
<Card>
<CardImage>{props.img}</CardImage>
<CardName>{props.name}</CardName>
<Description>{props.description}</Description>
<Links>
<Button>{props.livePreview}</Button>
<Button>{props.github}</Button>
</Links>
</Card>
</>
);
}
export default CardComponent;
Styled Component
import styled from "styled-components";
export const Card = styled.div`
width: 25%;
height: 70vh;
border: 1px dotted black;
margin-top: 5%;
#media (max-width: 768px) {
width: 100%;
}
`;
export const CardImage = styled.div`
border: 1px solid pink;
width: 80%;
height: 50vh;
margin: auto;
`;
export const CardName = styled.div`
border: 1px solid black;
text-align: center;
`;
export const Description = styled.div`
text-align: center;
`;
export const Links = styled.div`
display: flex;
border: 1px solid pink;
justify-content: center;
`;
export const Button = styled.div`
border: 1px solid blue;
`;
You can use either position: absolute or margin-top to achieve it. Check the snippet attached:
section {
padding: 10px;
border: 1px solid #ddd;
text-align: center;
display: inline-block;
max-width: 300px;
margin-top: 50px;
}
img {
max-width: 80%;
margin-top: -30px;
}
<section>
<img src="https://media1.popsugar-assets.com/files/thumbor/_Rrjw5u5qeqlO8Zznc0TskZB_8k/fit-in/1024x1024/filters:format_auto-!!-:strip_icc-!!-/2018/04/30/868/n/1922283/1f2e59ed5ae773b06f2879.82877284_/i/Does-Iron-Man-Die-Avengers-Infinity-War.jpg" />
<h4>Hello world</h4>
</section>
position:absolute;
top: -50;
Something like this should work, you should use absolute position because elements are overlapping each other and giving margin, padding etc. won't work since they are not meant to be overlap elements.
GOAL: Remove invisible padding around the color swatch so that the color fills the entire container.
I'm trying to fill the entire wrapper with the selected color.
However, there seems to be invisible padding on the input field:
import React, { useState } from "react";
import styled from "styled-components";
import "./styles.css";
const Container = styled.span`
display: flex;
justify-content: center;
align-items: center;
width: 100%;
max-width: 400px;
border-radius: 4px;
margin: 0px;
padding: 0px;
input[type="color"] {
border: 1px solid var(--main-grey);
outline: none;
border-radius: 8px;
width: 50%;
margin-left: 5px;
font-size: 12px;
font-family: Poppins;
padding: 0px;
-webkit-appearance: none;
width: auto;
height: auto;
cursor: pointer;
background-color: white;
margin:
&::-webkit-color-swatch-wrapper {
margin:-100px;
padding: 0px;
border: none;
overflow: none;
}
&::-webkit-color-swatch {
padding: 18px;
border:none;
border-radius: 8px;
margin: 0px;
}
}
input[type="text"] {
border: 1px solid var(--main-grey);
outline: none;
border-radius: 8px;
width: 50%;
margin-left: 5px;
padding-left: 12px;
margin-top: 0px;
font-size: 14px;
font-family: Poppins;
}
`;
const ColorPicker = (props) => {
return (
<Container>
<div className="color__pickerWrapper">
<input type="color" {...props} />
<input type="text" {...props} />
</div>
</Container>
);
};
export default function Color() {
const [state, updateState] = useState("#FFFFFF");
const handleInput = (e) => {
updateState(e.target.value);
};
return (
<div className="App">
<ColorPicker onChange={handleInput} value={state} />
</div>
);
}
I think there is some invisible padding around the input. However, I tried 0px margin and 0px padding and it still didn't solve the problem. Perhaps it is an issue with styled components?
It's not an elegant solution and may bring several problems in other parts that you desire the margins to appear.
Still, if you want to brute forcefully remove them go to your index.html file, within the public folder and add the code below after your head ends , and before your body starts :
<style>
* {
margin: 0 !important;
padding: 0 !important;
}
</style>
I'm following this tutorial https://blog.campvanilla.com/reactjs-dropdown-menus-b6e06ae3a8fe to make a dropdown in my React app.
The click/open function works fine except the menu, which is inside of its own component is not going beyond the header container:
Here is the css for my Header:
#inner-header {
background-color: #f1c40f;
font-family: "Rubik", sans-serif;
font-weight: 700;
display: flex;
width: 100%;
flex-direction: space-between;
height: 60px;
align-items: center;
padding: 15px 0 15px 2.5%;
align-items: top;
}
The tutorial didn't show CSS for the dropdown so I created my own:
.drop-down {
z-index: 1000;
overflow-y: visible;
width: 300px;
background-color: white;
display: block;
box-shadow: 0 20px 30px 0 rgba(0, 0, 0, 0.1), 0 4px 4px 0 rgba(0, 0, 0, 0.15);
}
The only difference between my code and the tutorial is that I've imported the <Card /> component into my header in a React Component:
import React from 'react'
import {Link} from 'react-router-dom'
import logo from '../images/logo.svg'
import Card from '../components/Card'
export default function InnerHeader() {
return (
<>
<div id="inner-header">
<div className="logo">
<Link to="/dashboard"><img src={logo} height="50px" alt="snack-page" /></Link>
</div>
<Card />
</div>
</>
)
}
I thought that giving the dropdown a z-index would allow it to go over the header but that wasn't the case. What is the best way to display the dropdown while it's in its own component? I'm not sure what the solution would be in this case?
I was able to resolve this by making two changes to the code based on the answers here (slightly modified)
First, the flex-direction needed to be set to row.
Next, justify-content needed to be set to space-between as #JoeLloyd pointed out in my typo.
Finally, the z-index is now set to 3 and was given a position of relative
#inner-header {
background-color: #f1c40f;
font-family: "Rubik", sans-serif;
font-weight: 700;
display: flex;
width: 100%;
height: 75px;
justify-content: space-between;
flex-direction: row;
padding: 15px 0 15px 2.5%;
align-items: top;
}
.menu-button {
padding-right: 15px;
float: right;
}
.drop-down {
z-index: 3;
margin-right: 12px;
position: relative;
width: 200px;
height: 200px;
display: inline-block;
background-color: white;
box-shadow: 0 20px 30px 0 rgba(0, 0, 0, 0.1), 0 4px 4px 0 rgba(0, 0, 0, 0.15);
}
flex direction is wrong
Set it to column if you want your content to go into a column and not a row. There's no such thing as flex-direction: space-between;
flex-direction: column;