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
Related
I have a pretty simple website, which renders a background image, a header, a footer, and some body text.
When I view the site from Google Dev Tools mobile inspector. The text sits above the footer as expected. When I view the site from an actual iphone the text is shown at the very bottom of the page (behind the footer).
App.js
return (
<div className={style.app}>
<Header setNav={setNav} nav={nav} />
<Routes>
<Route
exact
path="/"
element={
<Mobile
setNav={setNav}
nav={nav}
menuList={menuList}
setFilter={setFilter}
/>
}
/>
<Route
exact
path="/directions"
element={
<Directions
setNav={setNav}
nav={nav}
filter={filter}
setFilter={setFilter}
menuList={menuList}
/>
}
/>
</Routes>
<MobileNavOneButton setNav={setNav} setFilter={setFilter} />
</div>
);
the css for style.app is:
.app {
background-image: url("../CompanyImages/Port507BackgroundImage.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
position: fixed;
height: 100vh;
width: 100vw;
max-height: 100vh;
max-width: 100vw;
background-size: cover;
z-index: -999;
}
Mobile.js
import React from "react";
import style from "./Mobile.module.css";
const Mobile = () => {
return (
<div className={style.app}>
<div className={style.mainContent}>
<div className={style.address}>128 W 2nd St, Winona, MN 55987</div>
</div>
</div>
);
};
export default Mobile;
css for mobile.js
html,
body {
margin: 0;
/* height: 100% */
}
.app {
height: calc(100vh - 8rem);
width: 100vw;
background-size: cover;
display: flex;
justify-content: center;
margin-top: 5rem;
}
.mainContent {
text-align: center;
color: white;
width: 100%;
display: flex;
align-self: flex-end;
margin-bottom: 1.5rem;
margin-left: 1rem;
}
Footer.js
import React from "react";
import { useNavigate } from "react-router-dom";
import style from "./MobileNavOneButton.module.css";
import HomeIcon from "#mui/icons-material/Home";
import ExploreIcon from "#mui/icons-material/Explore";
const MobileNavOneButton = ({ setNav }) => {
const navigate = useNavigate();
return (
<div className={style.NavBar}>
<div
className={style.NavButton}
onClick={() => {
navigate("../directions", { replace: true });
setNav(false);
}}
>
<ExploreIcon style={{ fontSize: "1.25rem", color: "#000000" }} />
<div className={style.buttonText}>Directions</div>
</div>
</div>
);
};
export default MobileNavOneButton;
css for the footer
.buttonText {
font-size: 0.75rem;
font-family: Montserrat-Light;
text-decoration: none;
color: black;
}
.NavBar {
width: 100%;
float: none;
display: flex;
height: 3rem;
overflow: hidden;
position: fixed;
bottom: 0;
z-index: 999;
background-color: rgba(150, 150, 150, 0.8);
}
.NavButton {
align-items: center;
justify-content: center;
/* border: 1px solid black; */
/* background-color: rgba(150, 150, 150, 0.8); */
border-radius: 0;
float: left;
display: flex;
flex-direction: column;
font-size: 1rem;
font-family: Montserrat-Light;
text-align: center;
width: 100%;
text-decoration: none;
color: #222222;
}
.NavButton:focus {
outline: none !important;
outline-offset: none !important;
}
The website can be seen here. Note: you will be redirected if viewing from a browser (need to be in Dev Tools mobile)
Website
I'm designing a To Do List, and because I'm new to this type of coding I'm struggling with the CSS, I'm trying to put the 2 buttons on the right but they are staying next to the task text.
* {
font-family: Arial, Helvetica, sans-serif;
}
.App {
display: block;
text-align: center;
align-items: center;
}
.App input {
margin-bottom: 10px;
height: 20px;
}
.done {
text-decoration: line-through;
color:rgb(118, 118, 118)
}
.task {
align-items: center;
display: flex;
margin: auto;
width: 50%;
padding: 10px;
border: 1px solid green;
}
.task .task-text {
font-size: 20px;
}
.task .task-btn {
cursor: pointer;
}
.task .delete {
color: red;
}
.task .check {
color: green;
}
import React, { Component } from "react";
class Task extends Component {
render() {
return (
<div className={`task ${this.getClass()}`}>
<div className="task-text">{this.props.task.text}</div>
<span
className="task-btn check material-symbols-outlined"
onClick={() => this.props.onDone(this.props.task.id)}
>
check_box
</span>
<span
className="task-btn delete material-symbols-outlined"
onClick={() => this.props.onDelete(this.props.task.id)}
>
delete
</span>
</div>
);
}
getClass() {
return this.props.task.isDone ? "done" : "notDone";
}
}
export default Task;
What can I add to do what I want? The Output
....................................................................................
Wrap your 2 buttons with single div:
<div className="btns-parent">
<span
className="task-btn check material-symbols-outlined"
onClick={() => this.props.onDone(this.props.task.id)}
>
check_box
</span>
<span
className="task-btn delete material-symbols-outlined"
onClick={() => this.props.onDelete(this.props.task.id)}
>
delete
</span>
</div>
Then, on the task class, insert this:
.task {
display:flex;
align-items: center;
justify-content: space-between;
}
Simply modify your css .task{} as follows:
.task {
align-items: center;
display: flex;
justify-content: space-between;
margin: auto;
width: 50%;
padding: 10px;
border: 1px solid green;
}
add flex: 1 to
.task .task-text { font-size: 20px; }
I am doing this website for my full stack web development course but I am having a bit of trouble with my css. I am wondering how I can get the text Div to scale with the page.
the div looks like this zoomed in,
and it looks like this zoomed out,
the text div always wants to stay the same size.
the css is
.waitingMainDiv {
width: 70%;
display: flex;
justify-content: center;
align-items: center;
margin: auto;
padding-top: 80px;
padding-bottom: 80px;
}
.waitingLeftDiv {
width: 100%;
height: auto;
}
.waitingLeftDivImage {
width: 100%;
height: auto;
}
.waitingRightDiv {
width: 100%;
height: auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.waitingTextDiv {
width: 85%;
color: grey;
}
.waitingTextDiv h2 {
font-family: nunito;
font-weight: 700;
font-size: 2.3em;
margin: 4%;
}
.waitingTextDiv h3 {
font-family: nunito;
margin: 30px;
}
.waitingTextDiv p {
font-family: nunito;
margin: 30px;
font-size: 1.2em;
}
.waitingButtonDiv {
display: flex;
justify-content: flex-start;
width: 85%;
margin-left: 50px;
}
.waitingButtonDiv button {
width: 180px;
border-radius: 8px;
box-shadow: 0px 2px 5px rgb(0, 0, 0, 0.4);
font-family: nunito;
font-weight: 800;
}
.waitingEnquireButton {
border: 2px solid #43c0f6;
background-color: white;
color: #707070;
margin-right: 100px;
}
.waitingSignUpButton {
border: 2px solid #f91c85;
background-color: #f91c85;
color: white;
}
and the react.js is
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js">
import teacherPicture from "../../../../img/teacherPicture.png";
import React, { useState } from "react";
import "./Waiting.css";
import NavModal from "../../../Nav/NavModal";
export default function Waiting() {
const [open, setOpen] = useState(false);
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div className="waitingMainContainer">
<div className="waitingMainDiv">
<div className="waitingLeftDiv">
<img className="waitingLeftDivImage" src={teacherPicture} alt="" />
</div>
<div className="waitingRightDiv">
<div className="waitingTextDiv">
<h2>What are you waiting for?</h2>
<h3>Start teaching Digital Technologies today.</h3>
<p>
If you need more information, we are happy to answer any questions
you may have.
</p>
</div>
<div className="waitingButtonDiv">
<button className="waitingEnquireButton">ENQUIRE NOW</button>
<button
onClick={() => handleOpen()}
className="waitingSignUpButton"
>
SIGN UP
</button>
<NavModal open={open} handleClose={handleClose} />
</div>
</div>
</div>
</div>
);
}
</script>
Thankyou to those who review my code, its definitely a simple fix but im driving myself crazy over it.
Give your main div a width, not %;
.waitingMainDiv {
width: 70vw; //changed
display: flex;
justify-content: center;
align-items: center;
margin: auto;
padding-top: 80px;
padding-bottom: 80px;
}
i want the content inside the expandable_container div to be visible.
Now it moves up while adding align-items: center to the expandable div.
I have a side panel which contains list items. when the list item overflows i add a expand button. clicking that button should show the full content of list item. It works but then. when the content in list item overflows then the content in list item is half seen. like in below image
i want that content to properly placed. I tried adding padding-top to expandable class. However this will affect other list items that doesnt have expandable component. How can i fix this. Below is the code,
export default class Expandable extends React.PureComponent{
constructor(props) {
super(props);
this.expandable_ref = React.createRef();
this.state = {
expanded: false,
overflow: false,
};
}
componentDidMount () {
if (this.expandable_ref.current.offsetHeight <
this.expandable_ref.current.scrollHeight) {
this.setState({overflow: true});
}
}
on_expand = () => {
this.setState({expanded: true});
console.log("in expnad");
};
on_collapse = () => {
this.setState({expanded: false});
};
render () {
return (
<div className={(this.state.overflow ?
this.props.container_classname : '')}>
<div className={(this.state.overflow ?
this.props.classname : '')} style={{overflow: 'hidden',
display: 'flex', height: (this.state.expanded ? null :
this.props.base_height)}}
ref={this.expandable_ref}>
{this.props.children}
</div>
{this.state.overflow && this.state.expanded &&
<div className={this.props.expand}>
<button onClick={this.on_collapse}>
{this.props.arrow_up}</button>
</div>}
{this.state.overflow && !this.state.expanded &&
<div className={this.props.expand}>
<button onClick={this.on_expand}>
{this.props.arrow_down}</button>
</div>}
</div>
);
}
}
Class SidePanel extends React.purecomponent {
switch (notification.type) {
case 'new_model_uploaded':
return (
<Expandable
base_height={42}
arrow_down={<SvgAccDown className='grey' width="10"
height="10"/>}
arrow_up={<SvgAccUp className='grey' width="26"
height="26"/>}
container_classname='expandable_container'
classname='expandable'
expand='expand'>
<ListItem
icon={<SvgProject width="26" height="26"/>}
text={<Text
name={notification.initiator.name}
text=' created model '
model_name={notification.attributes.modelname}/>}
timestamp={notification.timestamp}>
<div className="additional_details">
<PreviewImage
width={70}
height={70}
model_id={filtered_model.id}
/>
</div>
</ListItem>
</Expandable>
);
case 'deleted':
return (
<ListItem
icon={<Svg width="20" height="22"/>}
text={<Text
name={notification.initiator.name}
text=' deleted model '
model_name={notification.attributes.modelname}/>}
timestamp={notification.timestamp}/>
);}
}
function ListItem(props) {
return (
<li className="notification">
<div className="details_container">
<div className="details">
{props.icon}
{props.text}
<Timestamp>{props.timestamp}</Timestamp>
</div>
{props.children}
</div>
</li>
);
}
.notification {
display: flex;
flex-direction: row;
font-size: 12px;
padding: 8px;
min-height: 49px;
flex-grow: 1;
li {
list-style: none;
}
.details_container {
display: flex;
flex-direction: column;
flex-grow: 1;
margin-right: 8px;
.details {
display: flex;
color: #333;
align-items: center;
flex-grow: 1;
svg {
margin-right: 8px;
margin-left: 7px;
flex: 0 0 auto;
align-self: center;
flex-shrink: 0;
}
span {
flex-grow: 5;
text-align: left;
}
time {
flex: 0 0 auto;
margin-left: 8px;
padding-top: 2px;
color: #CCCCCC;
}
}
.additional_details {
flex-basis: 100%;
width: 226px;
margin-left: 11%;
span {
display: block;
word-break: break-all;
margin-left: 2px;
}
}
}
}
.expandable_container {
display: flex;
margin-top: 8px;
flex-direction: column;
border-bottom: 1px solid #CCCCCC;
.expandable {
align-items: center;
padding-top: 35px;
}
}
.expand {
display: flex;
align-items: center;
position: relative;
top: 10px;
border: 1px solid #CCCCCC;
width: 150px;
height: 20px;
left: 30%;
background-color: $white;
justify-content: center;
}
Could someone help me solve this thanks.
Here is my problem:
I need rounded border only for first and last element? How can I accomplish that?
This is my css:
.root {
display: flex;
width: 100%;
height: 56px;
align-items: center;
border-radius: var(--radius-medium)px;
border: 1px solid var(--color-gray2);
}
.icon {
display: flex;
align-items: center;
padding: 0 15px;
}
.text {
color: #000;
font-size: calc(var(--font-size-body) / 10)rem;
}
This is from React:
//<ListElementRoot> === .root
//<ListElementIcon> === .icon
//<ListElementText> === .text
return (
<ListElementRoot>
<ListElementIcon>
<Icon name={icon} color={color} />
</ListElementIcon>
<ListElementText>
{children}
</ListElementText>
</ListElementRoot>
)
}
That is all, I know I should do something with first and last element, but how to do it in my case? Any ideas?
Borders are generated by root...
I suppose you mean that the first and last one should still have non-rounded edges at the inner sides:
.root {
width: 200px;
height: 80px;
border: 1px solid black;
}
.root:first-of-type {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.root:last-of-type {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
<div>
<div class="root">1
</div>
<div class="root">2
</div>
<div class="root">3
</div>
<div class="root">4
</div>
</div>
You can use :first-child and :last-child for this:
.root { /* all .root */
display: flex;
width: 100%;
height: 56px;
align-items: center;
border: 1px solid var(--color-gray2);
}
.root:first-child, .root:last-child { /* first or last .root only */
border-radius: var(--radius-medium)px;
}