Bootstrap 5 vertical scrollbar in column - html

Using React and Bootstrap 5 I am trying to show a list of images either right of or below a video.
For breakpoints smaller than lg the list of images should be shown below the video stacked horizontally with a horizontal scrollbar if needed (this works). For breakpoints lg and larger the image list should be shown vertically stacked (works) and with a scrollbar if needed (this doesn't work as the full site is scrollable).
Any idea?
import React from "react";
import "./style.css";
import {Card, Container, Nav, Navbar, Row, Col} from 'react-bootstrap'
import ReactPlayer from "react-player";
export default function App() {
const n = 12;
return (
<>
<Navbar bg="light" expand="lg">
<Container fluid className="">
<Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="me-auto">
<Nav.Link href="#home">Home</Nav.Link>
<Nav.Link href="#link">Link</Nav.Link>
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
<Container className="d-flex flex-lg-row flex-column" fluid>
<Row className="w-100">
<Col>
<div className='player-wrapper d-flex'>
<ReactPlayer
className='react-player'
url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
width='100%'
height='100%'
/>
</div>
</Col>
<Col lg="3">
<Card className="overflow-auto h-100">
<div className="d-flex flex-row flex-lg-column">
{
[...Array(n)].map((e, i) =>
<div className="thumbnail-container flex-grow-1" key={i}>
<img className="img-fluid" src="http://i.stack.imgur.com/yKgXQ.jpg" height="300px"/>
</div>
)
}
</div>
</Card>
</Col>
</Row>
</Container>
</>
);
}
.player-wrapper {
position: relative;
padding-top: 56.25% /* Player ratio: 100 / (1280 / 720) */
}
.react-player {
position: absolute;
top: 0;
left: 0;
}
img {
min-height: 200px;
min-width: 200px;
}
Example on Stackblitz

Related

How to make a div fill its parent div completely in React?

I am trying to create a react app using create-react-app. Following is my app function which is supposed to render a component thread inside my main app.
function App() {
return (
<div className="App">
<header className="App-header">
<div style={{ width: "280px", height: "320px", borderWidth:"5",borderColor:"white" }}>
<Thread threadId={"my-thread-id"} />
</div>
</header>
</div>
);
}
and here is the thread component
function Thread() {
return (
<div className="thread">
<h1 className="text-3xl font-bold underline ">Hello world!</h1>
</div>
);
}
export default Thread;
I just want my thread component's div with class "thread" to fill entire height and width inside the div of 280px:320px w:h in the main app. I am only getting a height of ~70px now.
I'm trying to change height, width, minHeight, minWidth parameters in the header class but to no avail. I am very bad at CSS so I would really appreciate the help. Thanks!
In order to achieve this you need to give the element with thread a class of h-full (height:100%) to fill the height of the container (which has a height of 320px).
function App() {
return (
<div className="App">
<header className="App-header">
<div style={{ width: "280px", height: "320px", borderWidth:"5",borderColor:"white" }}>
<Thread threadId={"my-thread-id"} />
</div>
</header>
</div>
);
}
function Thread() {
return (
<div className="thread h-full">
<h1 className="text-3xl font-bold underline">Hello world!</h1>
</div>
);
}
const rootElement = document.getElementById("app");
ReactDOM.render(<App />, rootElement);
<div id="app"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
give a class to Thread Component and style it
React:
<Thread className="t" />
CSS:
.t {
postion: absolute;
width: 100%;
height: 100%;
}

How to move/animate text values in navbar when I toggle the sidebar

How do I flex the contents of my navbar when I toggle the sidebar on/off in ReactJS? In my current website my sidebar overlaps the navbar so when I toggle it on, more than half of the title gets covered (sample1, sample2)
This is my Navbar.js
import React, { useState } from 'react'
import {Navbar, Container} from 'react-bootstrap'
import { Link } from 'react-router-dom';
import { useAuth } from "../contexts/AuthContext"
import './styles/styles.css';
import * as FaIcons from 'react-icons/fa';
import * as AiIcons from 'react-icons/ai';
import { IconContext } from 'react-icons';
import { SidebarItem } from './SidebarItem';
export default function Navubaru({component: Component, ...rest}) {
const { currentUser } = useAuth()
const [sidebar, setSidebar] = useState(false);
const showSidebar = () => setSidebar(!sidebar);
return (
<div>
<Navbar bg="myColor" variant="dark">
<IconContext.Provider value={{ color: '#fff' }}>
<Link to='#' className='menu-bars'>
<FaIcons.FaBars onClick={showSidebar} />
</Link>
<nav className={sidebar ? 'nav-menu active' : 'nav-menu'}>
<ul className='nav-menu-items' onClick={showSidebar}>
<li className='navbar-toggle'>
<Link to='#' className='menu-bars'>
<AiIcons.AiOutlineClose />
</Link>
</li>
{SidebarItem.map((item, index) => {
return (
<li key={index} className={item.cName}>
<Link to={item.path}>
{item.icon}
<span>{item.title}</span>
</Link>
</li>
);
})}
</ul>
</nav>
</IconContext.Provider>
<Container>
<Navbar.Brand href="/">Welcome to my Website</Navbar.Brand>
<Navbar.Toggle />
<Navbar.Collapse className="justify-content-end">
<Navbar.Text>
Signed in as: {currentUser && currentUser.email}
</Navbar.Text>
</Navbar.Collapse>
</Container>
</Navbar>
</div>
)
}
I'd also like to flex/minimize the size of the main page when I toggle the sidebar if there's not much difference in the methods of doing it. I'd appreciate any help and thoughts given. Thank you
You can set padding-left to the navbar's wrapper when sidebar is open and remove it when the sidebar close.
Here is an example navbar.

Make a sidebar from react-bootstrap

I am trying to create a Bootstrap sidebar like this picture here.
I have looked at all the code on react-bootstrap and Twitter Bootstrap and I am yet to find a how-to code this. Basically, if they are viewing on a desktop, I want the sidebar to be visible, otherwise hidden.
The sidebar should stay still while the content on the page scrolls up and down.
Ok so for people who want to make a sidebar sadly the news is you gotta make it all yourself.
What I have done is the following.
See the example at https://github.com/StartBootstrap/startbootstrap-simple-sidebar
Create sidebar.js somewhere in your app.
import React from "react";
import {Nav} from "react-bootstrap";
import { withRouter } from "react-router";
import '../pages/style/Dashboard.css'
const Side = props => {
return (
<>
<Nav className="col-md-12 d-none d-md-block bg-light sidebar"
activeKey="/home"
onSelect={selectedKey => alert(`selected ${selectedKey}`)}
>
<div className="sidebar-sticky"></div>
<Nav.Item>
<Nav.Link href="/home">Active</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="link-1">Link</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="link-2">Link</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="disabled" disabled>
Disabled
</Nav.Link>
</Nav.Item>
</Nav>
</>
);
};
const Sidebar = withRouter(Side);
export default Sidebar
My Dashboard.css has the following in it.
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
min-height: 100vh !important;
z-index: 100;
padding: 48px 0 0;
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
#sidebar-wrapper{
min-height: 100vh !important;
width: 100vw;
margin-left: -1rem;
-webkit-transition: margin .25s ease-out;
-moz-transition: margin .25s ease-out;
-o-transition: margin .25s ease-out;
transition: margin .25s ease-out;
}
#sidebar-wrapper .sidebar-heading {
padding: 0.875rem 1.25rem;
font-size: 1.2rem;
}
#page-content-wrapper {
min-width: 0;
width: 100%;
}
Then final step
In the file you want it to be show in do the following
import React from "react";
import {Container, Row, Col, Card, Form, Button } from "react-bootstrap";
import { withRouter } from "react-router";
import Sidebar from "../moduls/sidebar.js";
import './style/Dashboard.css'
const Dash = props => {
return (
<>
<Container fluid>
<Row>
<Col xs={2} id="sidebar-wrapper">
<Sidebar />
</Col>
<Col xs={10} id="page-content-wrapper">
this is a test
</Col>
</Row>
</Container>
</>
);
};
const Dashboard = withRouter(Dash);
export default Dashboard
As of 2022 there is pure react-boostrap based component called react-boostrap-sidebar-menu . It is the cleanest solution so far and quite customizable.
https://www.npmjs.com/package/react-bootstrap-sidebar-menu
https://github.com/ivp-dev/react-bootstrap-sidebar-menu
import SidebarMenu from 'react-bootstrap-sidebar-menu';
<SidebarMenu>
<SidebarMenu.Header>
<SidebarMenu.Brand>
{/* Your brand icon */}
</SidebarMenu.Brand>
<SidebarMenu.Toggle />
</SidebarMenu.Header>
<SidebarMenu.Body>
<SidebarMenu.Nav>
<SidebarMenu.Nav.Link>
<SidebarMenu.Nav.Icon>
{/* Menu item icon */}
</SidebarMenu.Nav.Icon>
<SidebarMenu.Nav.Title>
{/* Menu item title */}
</SidebarMenu.Nav.Title>
</SidebarMenu.Nav.Link>
<SidebarMenu.Nav/>
<SidebarMenu.Sub>
<SidebarMenu.Sub.Toggle>
<SidebarMenu.Nav.Icon />
<SidebarMenu.Nav.Title>
{/* Submenu title */}
</SidebarMenu.Nav.Title>
</SidebarMenu.Sub.Toggle>
<SidebarMenu.Sub.Collapse>
<SidebarMenu.Nav>
<SidebarMenu.Nav.Link>
<SidebarMenu.Nav.Icon>
{/* Submenu item icon */}
</SidebarMenu.Nav.Icon>
<SidebarMenu.Nav.Title>
{/* Submenu item title */}
</SidebarMenu.Nav.Title>
</SidebarMenu.Nav.Link>
</SidebarMenu.Nav>
</SidebarMenu.Sub.Collapse>
</SidebarMenu.Sub>
<SidebarMenu.Body/>
</SidebarMenu>
One can now use a library, react-bootstrap-drawer, which provides a sidenav / drawer which was taken directly from the react-bootstrap documentation. Oddly, this is not a component provided by the library itself so one must use a third-party library:
import 'react-bootstrap-drawer/lib/style.css';
import React, { useState } from 'react';
import {
Col,
Collapse,
Container,
Row,
} from 'react-bootstrap';
import { Drawer, } from 'react-bootstrap-drawer';
const ApplicationDrawer = (props) => {
const [open, setOpen] = useState(false);
const handleToggle = () => setOpen(!open);
return (
<Drawer { ...props }>
<Drawer.Toggle onClick={ handleToggle } />
<Collapse in={ open }>
<Drawer.Overflow>
<Drawer.ToC>
<Drawer.Header href="/">Application</Drawer.Header>
<Drawer.Nav>
<Drawer.Item href="/settings">Settings</Drawer.Item>
</Drawer.Nav>
</Drawer.ToC>
</Drawer.Overflow>
</Collapse>
</Drawer>
);
};
const Application = (props) => {
return (
<Container fluid>
<Row className="flex-xl-nowrap">
<Col as={ ApplicationDrawer } xs={ 12 } md={ 3 } lg={ 2 } />
<Col xs={ 12 } md={ 9 } lg={ 10 }>{ props.children }</Col>
</Row>
</Container>
);
};
See: https://github.com/SimpleSigner/react-bootstrap-drawer
of course, you have to make the navbar yourself and the examples above are very valid, but cdbreact speeds up the process a lot faster. just add cdbreact using
npm I cdbreact
or
yarn add cdbreact
and then import CDBSidebar, CDBSidebarContent, CDBSidebarHeader, etc. with cdbreact, you don't need to bother about installing bootsrap in your react app.
cdbreact also comes with icons, and a lot more.
import React from 'react'
import {CDBSidebar,
CDBSidebarContent,
CDBSidebarHeader,
CDBSidebarFooter, CDBSidebarMenu,
CDBSidebarMenuItem} from 'cdbreact';
import {NavLink, Link} from 'react-router-dom';
import {} from 'react-router-dom';
const Sidebar=()=>{
return (
<div style={{display:'flex', height:'100%', overflow:'scroll initial'}}>
<CDBSidebar textColer="#fff" backgroundColor="rgb(37, 90, 122)">
<CDBSidebarHeader prefix={<i className="fa fa-bars fa-large"></i>}>
<Link to="/dashboard">Dashboard</Link>
</CDBSidebarHeader>
<CDBSidebarContent className="sidebar-content">
<CDBSidebarMenu>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
</CDBSidebarMenu>
</CDBSidebarContent>
<CDBSidebarFooter style={{textAlign:'center'}}>
<div className="sidebar-btn-wrapper" style={{ padding :'20px 5px' }}>
sidebar footer
</div>
</CDBSidebarFooter>
</CDBSidebar>
</div>
)
}
export default Sidebar;
you can also follow the guide here https://dev.to/devwares/how-to-create-a-responsive-sidebar-in-react-using-bootstrap-and-contrast-5gi2 follow this link to see

Best way to modify HTML structure for different screens (possibly with media-queries)

I am building a simple page with React and Reactstrap. It is rendered in a asymmetrical way so for three Rows on the screen the scheme is 1) Img - Text 2) Text - img 3) Img - Text.
The problem is when the screen is reduced because the text wraps under the image, resulting in a double text view between the first and the second row which is bad to see. How to fix it? In CSS I think it is not possible since media queries cannot alter the HTML structure and, in this case, it is not simply to hide an element but to change its disposition.
JSX
import React, { Component } from 'react';
import { Container, Row, Col } from 'reactstrap';
import about1 from '../images/aboutstile1.jpg';
import about2 from '../images/aboutstile2.jpg';
import about3 from '../images/aboutstile3.jpg';
// import about3 from '../images';
// import about4 from '../images';
import './about.css';
import { Card, CardImg, CardText, CardBody,
CardTitle, CardSubtitle, Button, CardImgOverlay } from 'reactstrap';
export default class About extends Component {
render() {
return (
<div>
<div className="main">
</div>
<br/>
<br/>
<Container className="cont">
<Row>
<Col className="about_tile">
<img className="about_tile_img" src={about2} alt=""/>
</Col>
<Col className="about_text">
<h2>Executive Recruitment</h2>
<p>REC Consulting provides a full range of solution
to hire the most complex managerial figures a business needs. Thanks to
specific enquires on the type of leadership of the candidate we will know beforehand if
the profile is going to be the right leader in the team in the company.</p>
</Col>
</Row>
<br/>
<Row>
<Col className="about_text">
<h2>Technical Expertise</h2>
<p>REC Consulting provides a full range of solution
to hire the most complex managerial figures a business needs. Thanks to
specific enquires on the type of leadership of the candidate we will know beforehand if
the profile is going to be the right leader in the team in the company.</p>
</Col>
<Col className="about_tile">
<img className="about_tile_img" src={about3} alt=""/>
</Col>
</Row>
<br/>
<Row>
<Col className="about_tile">
<img className="about_tile_img" src={about1} alt=""/>
</Col>
<Col className="about_text">
<h2>Executive Recruitment</h2>
<p>REC Consulting provides a full range of solution
to hire the most complex managerial figures a business needs. Thanks to
specific enquires on the type of leadership of the candidate we will know beforehand if
the profile is going to be the right leader in the team in the company.</p>
</Col>
</Row>
</Container>
<br/>
<br/>
</div>
)
}
}
CSS
.main {
height: 26rem;
background-image: url('../images/abouts7.jpg');
background-size: cover;
background-position: 0 9%;
}
/* .cont {
max-width: 100rem;
} */
.about_tile {
width: 400px;
height: 320px;
}
.about_tile_img {
border-style: solid;
border-width: 1px;
border-color: turquoise;
border-radius: 25px;
position: relative;
width: 400px;
height: 320px
}
.about_text {
display: block;
justify-content: center;
}
Instead of altering the column order in the html, change the flex direction for every other row.
With bootstrap 4 you can use the helper class flex-row-reverse on every other <div class="row flex-row-reverse">...</div>.
I am not familiar with JSX so not 100% on how you would actually add the class, but the generated html should look something like this:
<div class="container">
<div class="row">
<div class="col-md-6">
image
</div>
<div class="col-md-6">
text
</div>
</div>
<div class="row flex-row-reverse">
<div class="col-md-6">
image
</div>
<div class="col-md-6">
text
</div>
</div>
</div>

Moving div relative to dynamically growing list CSS

I have one form on which all text fields are there and at the end there are 'save' and 'cancle' buttons. Between this last text field and buttons, there will be filename list that will populate dynamically as and when I will upload any file. Screenshot for the same is attached here. Size of this list is not fixed and thus, I want these buttons to shift down with every added file. I am not sure how can I adjust this movement of buttons dynamically. [see image 1]. And following is my current CSS code.
// Outermost div
.div-one {
position: absolute;
background-color: gainsboro;
height: 100%;
width: 50%;
}
// div for file list
.item-list {
width: 16em;
position: relative;
margin-left: -38px;
}
// div for buttons
.save-cancel-buttons-div{
position: relative;
top: 20%;
}
Following is my HTML code:
<div className="div-one1">
<Row>
<div className="item-list">
<Col xs={6} sm={6} md={6} lg={6}>
<If condition={this.state.files && this.state.files.length!=0}>
<ul style={{listStyle: 'None', fontSize: '16px'}}>
{this.state.files.map((value, index) => (
<li style={{paddingBottom: '5px', border:'5px'}}
key={`item-${index}`} >
<span>{value.file_name}
<span style={{paddingLeft: '20px'}}
onClick={() => this.onDeleteItem(value, index)}>
<Close size={20} paddingLeft={20}></Close>
</span>
</span>
</li>
))}
</ul>
</If>
</Col>
</div>
</Row>
<div className="save-cancel-buttons-div">
<Row>
<Col xs={3} sm={3} md={2} lg={2}>
</Col>
<Col xs={6} sm={6} md={6} lg={6}>
<Row>
<Col xs={6} sm={6} md={6} lg={6}>
<Button
value={<FormattedMessage id="saveBtn" defaultMessage="speichern" />}
fontSize={14}
minHeight={33}
minWidth={150}
backgroundColor="blue"
onClick={this.createNewDelivery}/>
</Col>
<Col xs={6} sm={6} md={6} lg={6}>
<Button
value={<FormattedMessage id="cancelBtn" defaultMessage="Zurück" />}
fontSize={14}
minHeight={33}
minWidth={150}
backgroundColor="red"
onClick={this.goBackToOfferedDeliveries}
/>
</Col>
</Row>
<Col xs={3} sm={3} md={2} lg={2}>
</Col>
<Col xs={6} sm={6} md={6} lg={6}>
</Col>
</Col>
</Row><br/>
</div>
</div>
Try to add a new container div for the save-cancel-buttons-div. Position the item-list and the container div relatively to their div-one parent container. Finally, position the save-cancel-buttons-div relatively to its container and add margin-left-right:auto so it centers inside it's parent div.
// div for file list
.item-list
{
position: relative; <--- this as first line of code
float:left; <--- add this so it takes a definite position
width: 16em;
margin-left: -38px;
}
// Put .save-cancel-buttons-div inside this div
.containerForSaveCancel
{
position:relative;
float:left;
width:100%;
text-align:center;
margin:0;
padding:0;
}
// div for buttons
.save-cancel-buttons-div
{
position: relative;
margin:5px auto 0 auto; <--- add this to center the div inside its parent
}