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;
}
CodePudding user response:
Two ways, which I know could work:
- Try to add
flex-direction: column;
attribute to thedisplay: flex
container This way it will make the text with thoseinput fields
‚listed‘ underneath each other, which looks (for my preference) better - Add
white-space: nowrap;
to your text div