Structuring Sidebar in React - reactjs

Relatively new to React, and am wanting to recreate the design below
enter image description here
I have the base formatting down, but as you will notice, there are lines separating the logo blocks, from the login and signup blocks, with the signup and login buttons pushed to the bottom.
Below is my current code
CSS:
width: 100vw;
height: 100vh;
}
body {
margin: 0;
padding: 0;
}
.Sidebar {
height: 100%;
width: 20%;
background-color: white;
border-right: 1px solid #F0F4FB;
padding-left: 15px;
box-sizing: border-box;
}
.SidebarList {
height: auto;
width: 100%;
padding-left: 15px;
font-size: 18px;
border: 2px #FD954E;
box-sizing: border-box
}
.SidebarList .row {
width: 100%;
height: 50px;
background-color: white;
list-style-type: none;
margin: 0%;
padding-bottom: 15px;
display: flex;
color: #A7ACB6;
justify-content: center;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
}
.SidebarList .row:hover {
cursor: pointer;
background-color: #E7E7E7 ;
}
.SidebarList #active {
background-color: white;
color: #FD954E
}
.SidebarList .Login {
background-color: white;
color: #FD954E;
width: 279px;
height: 39px;
right: 1596px;
top: 958px;
border: 1px solid #FD954E;
box-sizing: border-box;
border-radius: 19.5px;
}
.SidebarList .SignUp {
width: 279px;
height: 39px;
right: 1596px;
top: 1011px;
background: #FD954E;
border-radius: 19.5px;
border: none;
}
.row #icon {
flex: 30%;
display: grid;
place-items: center;
transform: scale(1.2)
}
.row #title {
flex: 70%;
}
.Logo {
padding-left: 25px;
padding-top: 25px;
padding-bottom: 30px;
border-bottom: 1px solid #F0F4FB;
width: 55%;
}
Sidebar.js
import React from "react";
import "../App.css";
import { SidebarData } from './SidebarData'
import Logo from './Logo.svg'
function Sidebar() {
return (
<div className="Sidebar">
<div>
<img src = {Logo} alt='Logo’ className=‘Logo’ />
</div>
<ul className="SidebarList">
{SidebarData.map((val, key) => {
return (
<li
key={key}
className="row"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="icon">{val.icon}</div> <div id="title">{val.title}</div>
</li>
);
})}
</ul>
<div className= "SidebarList">
<button className="Login">
Login
</button>
</div>
<div className= "SidebarList">
<button className="SignUp">
Sign Up
</button>
</div>
</div>
);
}
export default Sidebar;
How should I structure my code in order to acheive my desired result? Ex: with the logo at the top with the seperator, the list of navigation elements, and then the login and signup buttons at the bottom with the seperator?
Currently, my sidebar looks as follows, with the seperator not full width between the logo and navigation elements, and the buttons extending beyond the sidebar.
enter image description here

It would be easier to simplify the problem with just HTML and CSS as that's much easier to troubleshoot. Part of your problem is that you are defining the width of the sidebar as a percentage of the screen width but elements within the sidebar are defined with a width in pixels. When the browser window is too small, your buttons will appear outside the full width of the sidebar. You could either code all your values as percentages or in pixels. Alternatively, you could use a mix and just set a min-width for the sidebar so that you don't end up with elements out of place.
The reason that your line break is not the full width of your sidebar is because you are defining it with the border-bottom property of the logo. Your logo is not 100% the width of the sidebar so your line break will only be the width of the logo. A better solution would be to define a div that is set to width: 100%. This way, you will have more control.
Here is a simplified solution to your sidebar problem using pixels to define the widths.
HTML:
<div class="sidebar">
<div class="header">
<div class="logo">Logo</div>
</div>
<div class="line-break" />
<div class="content">
<ul class="nav">
<li>Home</li>
<li>Blog</li>
</ul>
</div>
<div class="line-break" />
<div class="footer">
<button class="login">Login</button>
<button class="sign-up">Sign up</button>
</div>
</div>
CSS:
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.sidebar {
width: 300px;
height: 100%;
border-right: 1px solid grey;
}
.line-break {
height: 1px;
width: 100%;
background-color: grey;
}
.header .logo {
height: 40px;
width: 200px;
background-color: grey;
margin: 20px;
}
ul.nav {
list-style-type: none;
padding: 20px 0 0 40px;
}
ul.nav li {
margin-bottom: 14px;
}
ul.nav li:last-child {
margin-bottom: 0;
}
.footer {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px 0;
}
.footer button {
padding: 6px 0;
width: 80%;
margin-bottom: 14px;
}
.footer button:last-child {
margin-bottom: 0;
}
And here is a link to a CodePen
where you can see this in action.

Related

Unexpected gap between two columns

I'm working on a react application and one of the pages has a two column layout. When I'm using a larger screen, there is a gap in between the two columns, thats not there on a smaller screen like a laptop. When i use the chrome inspect tool on the larger screen, the gap disappears.
I know its not my CSS doing this because I've adjusted every margin and padding value and it still shows up. I've even tried the resolution and the display on the larger screen and its still there.
Any help would be greatly appreciated!
EDIT
ProjectList.js
.project-list-page {
float: right;
width: 90vw;
}
.project-top-bar {
padding: 1rem;
display: flex;
justify-content: space-between;
border-bottom: 1px solid grey;
box-shadow: var(--box-shadow);
}
.project-top-bar input {
box-shadow: var(--box-shadow);
border: none;
border-radius: var(--border-radius);
width: 25vw;
padding: 5px;
font-size: 1em;
}
.project-list {
height: 100%;
list-style-type: none;
margin: 0;
padding: 0;
height: 100%;
overflow: scroll;
}
.project-column {
float: left;
border-collapse: collapse;
height: 87vh;
}
.project-left-side {
width: 30%;
}
.project-right-side {
width: 70%;
}
.project-list-item {
padding: 2em 0.5rem;
border-collapse: collapse;
border: 1px solid lightgrey;
overflow: auto;
width: 100%;
cursor: pointer;
}
.project-list-item:hover {
background-color: #e6e6e6;
}
.project-list a {
text-decoration: none;
color: black;
}
<>
<div className='project-list-page'>
<div className='project-top-bar'>
<input type="text" className='project-search-input' placeholder='Search projects ...' />
<button className='btn new-project-btn'>New Project</button>
</div>
<div className='project-column project-left-side'>
<ul className='project-list'>
{projectList.map(project => {
return <ProjectListItem project={project}/>
})}
</ul>
</div>
<div className='project-column project-right-side'>
Preview
</div>
</div>
</>
ProjectListItem.js
<Link to={`/projects/${project.name}`}>
<li className='project-list-item'>
{project.name}
</li>
</Link>

Pushing Sign Up & Login buttons to bottom of sidebar

I am trying to recreate this design:
Click to view
However, the below is currently occurring.
Click to view
I am trying to push the SignUp and Login buttons to the bottom of the sidebar to match the first image. Am I missing a CSS class that would allow me to do so, or would this be a JS configuration? Hope I have not overlooked something basic that would allow me to achieve this state.
Sidebar.js
import React from "react";
import "../App.css";
import { SidebarData } from './SidebarData'
import Logo from './Logo.svg'
import { Login } from './Login'
import { SignUp } from './SignUp'
function Sidebar() {
return (
<div className="Sidebar">
<div className="Header">
<div><img src = {Logo} alt='Logo’ className='Logo’ /></div>
</div>
<div class="line-break" />
<ul className="SidebarList">
{SidebarData.map((val, key) => {
return (
<li
key={key}
className="row"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="icon">{val.icon}</div> <div id="title">{val.title}</div>
</li>
);
})}
</ul>
<div class="line-break" />
<div className="footer">
<ul className= "SidebarList">
{Login.map((val, key) => {
return (
<li
key={key}
className="Login"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="title">{val.title}</div>
</li>
)}
)}
</ul>
<ul className= "SidebarList">
{SignUp.map((val, key) => {
return (
<li
key={key}
className="SignUp"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="title">{val.title}</div>
</li>
)}
)}
</ul>
</div>
</div>
Here is CSS
.App {
width: 100vw;
height: 100vh;
}
body {
margin: 0;
padding: 0;
}
.Sidebar {
height: 100%;
width: 300px;
background-color: white;
border-right: 1px solid #F0F4FB;
padding-left: 15px;
box-sizing: border-box;
}
.SidebarList {
height: auto;
width: 100%;
padding-left: 15px;
font-size: 18px;
border: 2px #FD954E;
box-sizing: border-box
}
.SidebarList .row {
width: 100%;
height: 50px;
background-color: white;
list-style-type: none;
margin: 0%;
padding-bottom: 15px;
display: flex;
color: #A7ACB6;
justify-content: center;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
}
.SidebarList .row:hover {
cursor: pointer;
background-color: #E7E7E7 ;
}
.SidebarList #active {
background-color: white;
color: #FD954E
}
.SidebarList .Login {
background-color: white;
color: #FD954E;
width: 90%;
height: 5vh;
right: 1596px;
top: 958px;
border: 1px solid #FD954E;
box-sizing: border-box;
border-radius: 19.5px;
text-align: center;
font-family: Arial, Helvetica, sans-serif
}
.SidebarList .SignUp {
width: 90%;
height: 5vh;
right: 1596px;
top: 1011px;
background: #FD954E;
border-radius: 19.5px;
border: none;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
}
.row #icon {
flex: 30%;
display: grid;
place-items: center;
transform: scale(1.2)
}
.row #title {
flex: 70%;
}
.Logo {
padding-left: 25px;
padding-top: 25px;
padding-bottom: 30px;
width: 55%;
}
.line-break {
height: 1px;
width: 100%;
background-color: #F0F4FB;
}
ul.nav {
list-style-type: none;
padding: 20px 0 0 40px;
list-style-type: none;
}
ul.nav li {
margin-bottom: 14px;
list-style-type: none;
}
ul.nav li:last-child {
margin-bottom: 0;
list-style-type: none;
}
.footer {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px 0;
}
.footer button {
padding: 6px 0;
width: 80%;
margin-bottom: 14px;
}
.footer button:last-child {
margin-bottom: 0;
}
.header .Logo {
height: 40px;
width: 200px;
background-color: grey;
margin: 20px;
}
Without seeing the source for the entire page and not just a couple of the buttons, it is impossible to say for sure, but my guess would be the following is causing your problem:
.Sidebar {
height: 100%;
...
}
Setting height: 100% will only tell the sidebar to take up 100% of the space it needs for its content (or 100% of the height of its bounding container, depending on the display properties of both). I would recommend changing it to this to solve your problem:
.Sidebar {
min-height: 100vh;
...
}

How do i make my Navbar overlap the rest of the page?

I want my navbar to be fixed and stay above the rest of the page as i scroll down, but whenever i add the 'position: fixed;' function on the css page it disappears.
Here is the code for the navbar in JS and Css...
import Logo from '../../Images/mmt-white.png';
import './Navbar.css';
const Navbar = props => (
<header className="Navbar">
<nav className="Navbar__navigation">
<div></div>
<div className='Navbar__logo'><img src={Logo}/></div>
<div className='spacer '/>
<div className="Navbar_navigation-items">
<ul>
<li>Home</li>
<li>Servicos</li>
<li>Depoimentos</li>
<li>Começando</li>
<li>Contacte-nos</li>
</ul>
</div>
<div className="Navbar_navigation_items_acessar">
<ul>
<li>Acessar</li>
</ul>
</div>
</nav>
</header>
);
export default Navbar;
And here is my app.js where i import all the pages and the navbar on top off them...
import Navbar from './components/NavBar/Navbar';
import Home from "./components/pages/HomePage/Home";
import Comecando from "./components/pages/Comecando/Comecando";
import Depoimentos from "./components/pages/Depoimentos/Depoimentos";
import Sac from "./components/pages/SAC/Sac";
import Servicos from "./components/pages/Servicos/Servicos";
import './App.css';
function App () {
return(
<div className='App'>
<div>
<Navbar/>
</div>
<Home/>
<Servicos/>
<Comecando/>
<Depoimentos/>
<Sac/>
</div>
);
}
export default App;
and here is the css
.NavbarItems {
background: linear-gradient(90deg,rgb(49,56,64)0%,rgba(49, 56, 64, 1) 100%);
height: 10vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 1,2rem;
left: 0;
position: fixed;
top: 0;
z-index: 1;
position: relative;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.navbar-logo{
position: absolute;
top: 0;
left: 0;
transform: translate(15%, 10%);
}
.fa-react{
margin-left: 0.5rem;
font-size: 1,6rem;
}
.nav-menu {
display: grid;
grid-template-columns: repeat(6, auto);
grid-gap: 10px;
transform: translate(8%, 0%);
list-style: none;
margin-left: 10vh;
text-align: center;
width: 80vw;
justify-content: end;
padding-left: 10vh;
margin-right: 1rem;
font-size: 10px;
}
.nav-links {
color:#edf0f1;
margin-top: 2rem;
padding-right: 2rem;
padding: 0;
text-decoration: none;
font-size: 22px;
font-family: monospace;
text-transform: uppercase;
}
.nav-links:hover{
border-radius: 4px;
transition: all 0.2s ease0;
color: #0088a9;
}
.fa-bars{
color: #ffffff;
}
button{
margin-left: 10vh;
right: 0;
padding: 9px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
font-family: "Montserrat", sans-serif;
font-weight: 500;
color: #edf0f1;
font-size: 17px;
text-decoration: none;
}
.menu-icon{
display: none;
}
.nav-links-mobile{
color: transparent;
}
You may want to add the following to your NavBar class in your NavBar.css file to add the positional properties like so:
left: 0;
position: fixed;
top: 0;
z-index: 1; // increase this value if you have other elements at varying levels of elevation
Or you may want to add the following to your NavBar class in your NavBar.css file instead of position: fixed (it depends on the behavior you're looking for):
position: sticky;
top: 0; // vertical position you'd like the element to stick to
z-index: 1; // increase this value if you have other elements at varying levels of elevation

css grid + react component challenge

Working on a css grid challenge with React in codepen.
This is the original codepen: https://codepen.io/tallys/pen/bvwZee/
What I have so far: https://codepen.io/al2613/pen/QmOyKo
.grid-container {
border: 2px dashed goldenrod;
display: inline-grid;
padding: 10px;
grid-template-columns: auto auto;
height: 100vh;
grid-gap: 30px;
}
So I got main content area to span across the grid container. However, I'm stuck as to how I can make the aside always 150px and the grid container align nicely with the div at the top?
I'm new to grid very nice first try. I think this is a little bit hacky, but...it does the job (I guess)
I don't think the CSS on this snippet will work, but nevertheless, here's the Pen...
//Don't edit the JS for the CSS Grid challenge!
class App extends React.Component {
state = {
sidebarActive: false,
}
toggleSidebar() {
this.setState({sidebarActive: !this.state.sidebarActive})
}
render() {
const buttonText = this.state.sidebarActive ? 'Toggle Sidebar Off' : 'Toggle Sidebar On';
const {sidebarActive} = this.state
return (
<div>
<h1 className="heading">CSS Grid when some sections don't render!</h1>
<div className="instructions">
<p>The challenge: Fix the CSS Grid so that the main area takes up all of the available space when the sidebar react component does not render. </p>
<button onClick={this.toggleSidebar.bind(this)}>{buttonText}</button>
</div>
<div className="grid-container">
{sidebarActive && <aside className="sidebar">Sometimes renders!</aside>}
<main className="main">Main content area that should always take up the rest of the space in the container. </main>
</div>
</div>
);
}
}
ReactDOM.render(<App/>, document.getElementById('app'));
// Variables
$brand-color: darkblue;
$brand-section-color: white;
$brand-text-color: #222;
$react-accent: #61dafb;
$react-background: #292c34;
$breakpoint: 768px;
$font-heading: 'Permanent Marker', sans-serif;
$font-default: 'Oswald', sans-serif;
// Styles
body {
font-family: $font-default;
margin: 10vh 10vw;
color: $react-accent;
background: $react-background;
}
.heading {
font-family: $font-heading;
}
.instructions {
padding: 5px 12px 20px 12px;
margin-bottom: 20px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
background: lighten(adjust-hue($react-background, 30), 7);
font-size: 1.15rem;
button {
border: none;
background: $react-accent;
font-family: $font-default;
padding: 20px;
border-radius: 0;
cursor: pointer;
transition: .4s ease;
&:hover, &:active, &:focus {
background: adjust-hue($react-accent, 210);
}
}
}
.grid-container {
border: 2px dashed goldenrod;
display: inline-grid;
grid-template-columns: 150px repeat(1, 1fr);
height: 100vh;
width: 100%;
grid-gap: 30px;
}
.sidebar {
background: lighten($react-background, 7);
padding: 10px;
& ~ .main{
grid-column: auto !important;
}
}
.main {
background: darken($react-background, 7);
display: grid;
grid-column: span 2;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<main id="app"></main>
I know it's a really late response, but I remembered this challenge... and I couldn't resist.
My approach is fixing the main to the second column, while setting the sidebar width on the item itself (and a margin-right to fake the grid-gap), allowing for the first column to be declared as minmax(0, auto).
.grid-container {
grid-template-columns: minmax(0, auto) 1fr;
/*grid-gap: 30px;*/
}
.main {
grid-column: 2;
}
.sidebar {
margin-right: 30px;
width: 150px;
}
https://codepen.io/facundocorradini/pen/eKgVzP
That way the first column will have a zero width if the sidebar is not loaded, and get to the 150px sidebar with when it loads.

CSS 3rd div height based on 1st

I'm trying to find a right solution for stacking different height divs. Tried grid, flex and lastly inline-block.
From what i understand 3rd div(button) is attatched to the bottom of a 2nd div(image). I'm trying to make so it would be attatched to the bottom of a 1st div(text).
Button is being drawn as 3rd div is because button has to go under an image when window size gets too small. Can you even achive this with inline-block?
My current code:
https://jsfiddle.net/mep2x67L/16/
#container {
padding-top: 50px;
padding-bottom: 50px;
display: inline-block;
position: relative;
width: 100%;
height: 100%;
}
#desccription {
width: calc(50% - 20px);
margin-left: 20px;
display: inline-block;
vertical-align: top;
}
#desccription_Container {
margin: 0 auto;
justify-content: left;
text-align: left;
max-width: 560px;
margin-right: 10px;
}
#half_img {
width: 100%;
}
#img_container {
width: 49%;
display: inline-block;
}
.btnWrap {
display: inline-block;
width: 355px;
vertical-align: top;
text-align: center;
}
#normal_text {
font-size: 36px;
line-height: 42px;
color: #F1ECE3;
}
#btnWrap {
display: inline-block;
width: 355px;
vertical-align: top;
text-align: center;
}
<div id="container">
<div id="desccription">
<div id="desccription_Container">
<div id="normal_text"> hello hello </div>
</div>
</div>
<div id="img_container">
<img id="half_img" src="https://wallpapercave.com/wp/6K44j5E.jpg">
</div>
<div id="btnWrap">
<button type="button">Button!</button>
</div>
</div>
All you need to do is float your image div right - below I have commented the line I added. I have also added a clear fix and changed the width of the button wrap so it works on smaller screen sizes.
#container {
padding-top: 50px;
padding-bottom: 50px;
position: relative;
width: 100%;
height: 100%;
}
#container:after { /* clear fix */
content: '';
display: block;
height: 0;
overflow: hidden;
clear: both;
}
#desccription {
width: calc(50% - 20px);
margin-left: 20px;
display: inline-block;
vertical-align: top;
}
#desccription_Container {
margin: 0 auto;
justify-content: left;
text-align: left;
max-width: 560px;
margin-right: 10px;
}
#half_img {
width: 100%;
}
#img_container {
width: 49%;
display: inline-block;
float:right; /* add this */
}
#normal_text {
font-size: 36px;
line-height: 42px;
color: #F1ECE3;
}
#btnWrap {
width: calc(50% - 20px); /* I would make this the same size as desccription */
vertical-align: top;
text-align: center;
}
<div id="container">
<div id="desccription">
<div id="desccription_Container">
<div id="normal_text"> hello hello </div>
</div>
</div>
<div id="img_container">
<img id="half_img" src="https://wallpapercave.com/wp/6K44j5E.jpg">
</div>
<div id="btnWrap">
<button type="button">Button!</button>
</div>
</div>
You can use Grid - it's super easy, and you can control the position and grid layout with just media queries, etc. And it requires much less CSS when you learn how to use grid properly.
To learn about flexbox, I'd recommend this source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Similarly, to learn CSS grids, there is: https://css-tricks.com/snippets/css/complete-guide-grid/
It'll take about a day of your time, and you'll get a great grasp of how grids and flexbox work, helping you create better designs in the future.
For the current example, see the fiddle with CSS-grids:
https://jsfiddle.net/5u69aaun/
#container {
padding-top: 50px;
padding-bottom: 50px;
display: grid;
grid-template-rows: auto 1fr;
grid-template-columns: 1fr 1fr;
width: 100%;
height: 100%;
}
#description{
padding-left: 20px;
padding-right: 10px;
grid-row: 1;
grid-column: 1;
text-align: left;
}
#description_Container{
max-width: 560px;
}
#half_img {
width: 100%;
}
#img_container {
grid-row: 1 / 3;
grid-column: 2;
}
.btnWrap{
grid-row: 2;
grid-column: 1;
}
#normal_text{
font-size: 36px;
line-height: 42px;
color: red;
}
#btnWrap{
text-align: center;
}
<div id="container">
<div id="description">
<div id="description_Container">
<div id="normal_text"> hello hello </div>
</div>
</div>
<div id="img_container">
<img id="half_img" src="https://wallpapercave.com/wp/6K44j5E.jpg" >
</div>
<div id="btnWrap">
<button type="button">Button!</button>
</div>
</div>

Resources