CSS: can't move the buttons - css

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; }

Related

Style elements from the same div to be on different lines in Sass

I have a div with a h3, p and button elements. I want the h3 to be on a separate line, and the p and button element on a different line. How can I implement this?
Like:
****{names}
{date} Trashicon****
<div className="nameHeader">
<h3>{names}</h3>
<p>{date}</p>
<button
className="nameHeader__icon"
onClick={deletetNames}
>
<GrTrash />
</button>
</div>
.nameHeader {
width: 100%;
height: 100%;
padding: 1rem;
h3 {
font-weight: 600;
}
p {
font-size: 20px;
}
&__icon {
color: #ccc;
}
}
You probably want something like this:
<div className="nameHeader">
<h3>{names}</h3>
<div className="whatever">
<p>{date}</p>
<button
className="nameHeader__icon"
onClick={deletetNames}
>
</div>
<GrTrash />
</button>
</div>
And for the CSS/SASS part:
.nameHeader {
width: 100%;
height: 100%;
padding: 1rem;
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
h3 {
font-weight: 600;
}
.whatever {
display: flex;
align-items: center;
flex-direction: row; // default
justify-content: space-arround;
}
p {
font-size: 20px;
}
&__icon {
color: #ccc;
}
}
Just play around with align-items and justify-content to get the result you want.
Use inline-block
p {
display: inline-block;
}

Text Overflowing

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

I need to toggle between an X button and hamburger menu with Bootstrap. I'm using React.js

I'm using the latest version of Bootstrap and want to toggle between the famous X icon and hamburger menu. I don't know if I can actually change the 3 lines of the menu since it's by default, but these 2 icons presently overlap each other.
So there are 2 questions here:
How can I toggle these two icons?
When the menu is clicked, it should have a complete white background (right now it doesn't completely cover the screen in white)
Sorry I don't have a sandbox example for you right now.
Thanks for your input!
/*JSX code*/
import React from 'react';
import { NavigationBarStyled } from './style';
import { Nav, Navbar } from 'react-bootstrap';
//IMAGES
import logo from '../../images/adyslogo.png';
import Image from 'react-bootstrap/Image';
import { GrCart } from 'react-icons/gr';
import CloseButton from '../../images/closebutton.svg';
const NavigationBar = () => {
return (
<NavigationBarStyled>
<Navbar expand='sm' fixed='top'>
<Navbar.Brand href='/'><Image src={logo} className='logo'/></Navbar.Brand>
<div className='close-button'>
<button type="button" className="x-closebutton" aria-label="Close">
<img src={CloseButton} className='x-button' alt="close configuration" draggable="false" />
</button>
<Navbar.Toggle aria-controls='basic-navbar-nav' className='hamburger-menu'/>
</div>
<Navbar.Collapse id='basic-navbar-nav'>
<Nav className='mr-auto'>
<Nav.Item><Nav.Link href='/' className="middle-menu">HOME</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/about' className="middle-menu">ABOUT</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/menu' className="middle-menu">MENU</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/gallery' className="middle-menu">GALLERY</Nav.Link></Nav.Item>
<Nav.Item><Nav.Link href='/contact' className="middle-menu">CONTACT</Nav.Link></Nav.Item>
</Nav>
<Nav className='ml-auto'>
<Nav.Item><Nav.Link href='/cart'><GrCart size='25px' className='cart'/></Nav.Link></Nav.Item>
</Nav>
</Navbar.Collapse>
</Navbar>
</NavigationBarStyled>
)
}
export default NavigationBar;
/*CSS*/
import styled from 'styled-components';
export const NavigationBarStyled = styled.nav`
.navbar {
background-color: #FFF;
height: 80px;
}
.navbar-brand, .navbar-nav .nav-link {
color: #273746 ;
font-size: 1rem;
font-weight: 600;
&:hover {
color: rgb(255, 20, 147);
}
}
.logo {
max-height: 60px;
max-width: 60px;
}
.middle-menu {
margin: 20px;
}
.cart {
margin-right: 50px;
}
.close-button {
display: flex;
align-items: flex-start;
justify-content: flex-start;
}
.x-closebutton {
display: flex;
align-items: flex-start;
justify-content: flex-start;
border: none;
background-color: #fff;
margin-right: -54px;
}
.x-button {
display: flex;
width: 45px;
height: 45px;
cursor: pointer;
}
.hamburger-menu {
border: none;
color: #000;
}
.mr-auto {
display: flex;
align-items: center;
background-color: white;
min-width: 100vw;
min-height: 100vh;
}
`;
It's actually rather easy to toggle state but, keep in mind you won't have the graceful height calculation which comes with Bootstrap.
I'll comment out what doesn't seem important to this answer...
import React, { Component } from "react";
//import { Link } from "gatsby";
//import Image from "./image";
import "../../scss/molecules/_topnav.scss";
//const helpers = require("../../helpers");
class Nav extends Component {
state = { collapse: true };
/*
componentDidMount() {
helpers.useIntersect(".navbar-collapse", "navbar-collapsed");
}
*/
constructor(props) {
super(props);
this.brandLogo = this.props.brandLogo;
this.listItems = this.props.pages
//.sort((a, b) => (a.node.navigationOrder || 100) - (b.node.navigationOrder || 100))
.map((page) => page.node.slug && page.node.pageName && !page.node.hideInNavigation && (
<li className="nav-item" key={page.node.id}>
<Link to={`${page.node.slug}`} className="nav-link" title={page.node.pageName}>{page.node.pageName}</Link>
</li>)
);
}
render() {
return (
<>
<nav className={[
"navbar",
"navbar-expand-lg",
"navbar-light",
"fixed-top",
this.state.collapse ? "" : "active"].join(" ")}
>
<a className="navbar-brand" href="/"><Image fluid={this.brandLogo} /></a>
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#topnav"
aria-controls="topnav"
aria-expanded={!this.state.collapse}
aria-label="Toggle navigation" onClick={() => {
this.setState({ collapse: !this.state.collapse });
}
}>
<span className="navbar-toggler-icon"></span>
</button>
<div
className={[
"collapse",
"navbar-collapse",
"fade",
!this.state.collapse ? "show" : "",
].join(" ")} id="topnav">
<ul className="navbar-nav ml-lg-auto">{this.listItems}</ul>
</div>
</nav>
</>
);
}
}
export default Nav;
SCSS solution to cover state and mobile -vs- desktop navigation
A simple toggle between display "none" and "block". You can transition transforms to counter the missing height calculation.
We'll use the proper content characters to cover the icons.
It's a bit too much but I'll leave this file complete.
#import "../variables";
#import "../functions";
#import "../vendor/bootstrap/functions";
#import "../vendor/bootstrap/variables";
#import "../vendor/bootstrap/mixins";
#import "../vendor/bootstrap/transitions";
.navbar {
&.navbar-light {
transition: all ease 0.2s;
.navbar-brand {
transition: all ease 0.2s;
.image {
height: auto;
width: rem-value(142);
}
}
.nav-item {
align-items: center;
display: flex;
}
.nav-link {
font-family: $font-family-monospace;
font-size: rem-value(20);
}
#include media-breakpoint-up(md) {
.navbar-collapse {
&:not(.show) {
opacity: 1;
}
}
.nav-item {
margin: auto 1rem;
}
}
#include media-breakpoint-up(lg) {
.nav-item {
&:last-child {
.nav-link {
background-color: $primary;
border-radius: rem-value(3);
color: $white;
margin-left: 1.5rem;
&:hover,
&:active,
&:focus {
background-color: $brand-primary-headings;
}
}
}
}
}
#include media-breakpoint-down(md) {
background-color: $white;
box-shadow: 0 0 1px 1px $gray-300;
padding-top: 0;
padding-bottom: 0;
.navbar-brand {
transform: scale(0.65);
transform-origin: left;
padding-top: 0;
padding-bottom: 0;
}
.navbar-collapse {
&.collapse {
background: white;
margin: 0 -1rem;
height: 0;
transform: scale(0);
transform-origin: top center;
transition: all ease 0.5s;
padding: 1rem;
position: relative;
&.show {
height: calc(100vh - 80px);
transform: scale(1);
}
}
}
.navbar-toggler {
&[aria-expanded="true"] {
.navbar-toggler-icon {
background-image: none;
position: relative;
&:before {
content: "\00d7";
font-family: sans-serif;
font-size: rem-value(40);
line-height: 0.8;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
}
}
}
.nav-item {
border-bottom: 1px solid $gray-300;
margin: 0;
position: relative;
&:before {
content: "\203A";
line-height: 1.2;
font-size: rem-value(30);
color: $brand-primary-headings;
position: absolute;
right: 0.5rem;
width: rem-value(40);
height: rem-value(40);
text-align: center;
}
}
.nav-link {
line-height: 1.8;
width: 100%;
}
}
#at-root .scrolled & {
background-color: $white;
box-shadow: 0 0 1px 1px $gray-300;
padding-top: 0;
padding-bottom: 0;
.navbar-brand {
transform: scale(0.65);
padding-top: 0;
padding-bottom: 0;
}
}
}
}
Example can be seen at devlab.career
Hopefully with this example you can implement this too.

react.js text div wont scale with my page but the image div will

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;
}

How to set the content of div to be visible inside parent div using css

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.

Resources