Modal window that does not appear after the click - javascript

I'm new to React js and i'm trying to integrate a modal window in my electron software. I tried the following link example: https://medium.com/tinyso/how-to-create-a-modal-component-in-react-from-basic-to-advanced-a3357a2a716a and it worked at first except that when I clicked on the box, the modal window was displayed underneath the whole page when it should be displayed on top. I had to modify the code but now when I click on the box where I put the onClick() nothing happens anymore. I would like to know where my error comes from ? and how to make the modal window display on top of the other elements of the page ?
Here are the code :
Modal.js :
import React from "react";
import "./Modal.css";
const Modal = props => {
if(!props.show){
return null
}
return (
<div className="modal">
<div className="modal-content">
<div className="modal-header">
<h4 className="modal-title">Modal title</h4>
</div>
<div className="modal-body">This is modal content</div>
<div className="modal-footer">
<button onClick={props.onClose} className="button">
Close
</button>
</div>
</div>
</div>
)
}
export default Modal;
Modal.css :
.modal {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: all 0.3s ease-in-out;
pointer-events: none;
}
.modal-content {
width: 500px;
background-color: #fff;
transition: all 0.3s ease-in-out;
transform: translateY(-200px);
}
.modal-header,
.modal-footer {
padding: 10px;
}
.modal-title {
margin: 0;
}
.modal-body {
padding: 10px;
border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
}
App.js :
import React, { useState, useEffect } from 'react';
import Home from './pages/home';
import Modal from './Modal/Modal'
export default function App() {
const [data, setData] = useState(null);
const [show,setShow] = useState(false);
useEffect(() => {
const socket = new WebSocket('ws://localhost:8000');
socket.addEventListener('message', (event) => {
setData(JSON.parse(event.data));
});
}, []);
return (
<div className="home">
<div className="template-1" id="temp1">
<div className="panel-1">
<div className="panel-header">
<h1>Panel 1</h1>
<i className='bx bx-cog modal-trigger-panel'></i>
</div>
<div className="panel-body">
<div className="sec-5 modal-trigger-data" id="hs-sec-5" onClick={()=>setShow(true)}>
{data ? <span class="h1" id="h1-fs-s5">{data[0]}</span> : <p>Loading...</p>}
<h2>TWIST</h2>
<h3>s5</h3>
</div>
<div className="sec-4 modal-trigger-data" id="hs-sec-4">
{data ? <span class="h1" id="h1-fs-s5">{data[1]}</span> : <p>Loading...</p>}
<h2>TWIST</h2>
<h3>s4</h3>
</div>
<div className="sec-3 modal-trigger-data" id="hs-sec-3">
{data ? <span class="h1" id="h1-fs-s5">{data[2]}</span> : <p>Loading...</p>}
<h2>TWIST</h2>
<h3>s3</h3>
</div>
<div className="sec-2 modal-trigger-data" id="hs-sec-2">
{data ? <span class="h1" id="h1-fs-s5">{data[3]}</span> : <p>Loading...</p>}
<h2>TWIST</h2>
<h3>s2</h3>
</div>
<div className="sec-1 modal-trigger-data" id="hs-sec-1">
{data ? <span class="h1" id="h1-fs-s5">{data[4]}</span> : <p>Loading...</p>}
<h2>TWIST</h2>
<h3>s1</h3>
</div>
</div>
</div>
</div>
<Modal onClose={() => setShow(false)} show={show} />
</div>
);
}
style.css :
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
*{
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box
}
:root{
/* ===== Colors ===== */
--body-color: #E4E9F7;
--sidebar-color: #FFF;
--primary-color: #1c1a1a;
--primary-color-light: #F6F5FF;
--toggle-color: #DDD;
--text-color: #707070;
/* ===== Transition ===== */
--tran-02: all 0.2s ease;
--tran-03: all 0.3s ease;
--tran-04: all 0.4s ease;
--tran-05: all 0.5s ease;
}
body{
height: 100vh;
background: var(--body-color);
}
/*Paramètres de la page des templates*/
.home{
position: relative;
height: 100vh;
left: 78px;
width: calc(100% - 78px);
background: var(--body-color);
transition: var(--tran-05);
}
/*--------------------- TEMPLATE 1 ---------------------*/
.template-1{
display: block;
position: relative;
top: 0;
width: 100%;
height: 100%;
}
/* PANNEAU N°1*/
/*Paramètres de la fenêtre modal*/
.panel-1{
position: absolute;
width: 10%;
height: 100%;
padding: 5px;
}
/*Paramétre titre du panneau*/
.panel-1 .panel-header h1{
font-size: 1.5vh;
margin-left: 5px;
font-family: Montserrat, sans-serif;
font-weight: 500;
}
/*Paramétre panel header*/
.panel-1 .panel-header{
display: flex;
height: 3%;
border-radius: 5px 5px 0px 0px;
align-items: center;
justify-content: space-between;
padding: 0.1% 0.1%;
background-color: rgb(91, 91, 91);
color: rgb(255, 255, 255);
box-shadow: 0 0 7px rgba(18,18,18,0.5);
}
/*Paramètres panel body*/
.panel-1 .panel-body{
height: 97%;
background-color: #ffffff;
box-shadow: 0 0 7px rgba(18,18,18,0.5);
}
/*----- Sections -----*/
.panel-body .sec-5{
position: relative;
width: 100%;
height: 20%;
cursor: pointer;
border: 1px solid #000000;
}
.panel-body .sec-5:hover{
background-color: #707070;
color: #E4E9F7;
}
.panel-body .h1{
position: absolute;
top: 58%;
left: 50%;
transform: translate(-50%,-50%);
font-size: 9vh;
}
.panel-body h1{
position: absolute;
top: 58%;
left: 50%;
transform: translate(-50%,-50%);
font-size: 4vh;
}
.panel-body h2{
position: absolute;
left: 50%;
transform: translateX(-50%);
font-size: 3vh;
}
.panel-body h3{
position: absolute;
margin-left: 2%;
font-size: 1.5vh;
}
.panel-body .sec-4{
position: relative;
width: 100%;
height: 20%;
cursor: pointer;
border: 1px solid #000000;
}
.panel-body .sec-4:hover{
background-color: #707070;
color: #E4E9F7;
}
.panel-body .sec-3{
position: relative;
width: 100%;
height: 20%;
cursor: pointer;
border: 1px solid #000000;
}
.panel-body .sec-3:hover{
background-color: #707070;
color: #E4E9F7;
}
.panel-body .sec-2{
position: relative;
width: 100%;
height: 20%;
cursor: pointer;
border: 1px solid #000000;
}
.panel-body .sec-2:hover{
background-color: #707070;
color: #E4E9F7;
}
.panel-body .sec-1{
position: relative;
width: 100%;
height: 20%;
cursor: pointer;
border: 1px solid #000000;
}
.panel-body .sec-1:hover{
background-color: #707070;
color: #E4E9F7;
}
Regards,

There might be other issues, but it seems that the modal is not showing because it was hidden by opacity: 0, and it might not be able to close because of pointer-events: none prevents clicking on button.
Perhaps these properties can be edited to see if it improves.
Below example tested in a simplified demo: stackblitz (omitted the useEffect for simplicity, the modal should show on click of the first cell and closes by the "close" button).
.modal {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
/* 👇 Replaced opacity: 0; */
opacity: 1;
transition: all 0.3s ease-in-out;
/* 👇 Remvoed */
/* pointer-events: none; */
}

Related

(active) hamburger menu not sticky

I have a problem making the hamburger menu sticky. So the hamburger icon is in the corner when i scroll down, but the menu stays in the same position(at the top of the page), so I have to scroll back up again to look at it. I got the code from codepen, i tried adjusting the code, but didnt figure out how.
If you want to view where i got the code from here is the link, but it is not necessary in my opinion for i only removed code that wasnt related to the hamburger menu: https://codepen.io/CopyPasteLtd/pen/BaxQeGw
See the snippet below.
const toggleButton = document.querySelector('.toggle-menu');
const navBar = document.querySelector('.nav-bar');
toggleButton.addEventListener('click', () => {
navBar.classList.toggle('toggle');
});
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#200;300;400&display=swap');
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
font-size: 10px;
}
.container {
width: 100%;
height: 100vh;
/* background: linear-gradient(-45deg, #ee7752, #e73c7e);
background-size: 400% 400%; */
position: relative;
}
.nav-bar {
position: absolute;
background-color: #122;
top: 0;
left: -25rem;
height: 100vh;
width: 25rem;
display: flex;
justify-content: center;
align-items: center;
transition: 0.5s ease-out;
}
.toggle {
left: 0;
box-shadow: 1px 0 15px 2px rgba(0, 0, 0, 0.4);
}
.toggle-menu {
background-color: rgba(0, 0, 0, 0.2);
position: fixed;
top: 2rem;
left: 2rem;
width: 4rem;
height: 3rem;
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 0.2rem 0.5rem;
border-radius: 0.5rem;
}
.line {
width: 100%;
height: 4px;
border-radius: 5px;
background-color: #fff;
transition: 0.4s ease-out;
}
.toggle .line1 {
background-color: #c91919;
transform: scale(0.9) rotateZ(-45deg) translate(-6px, 4px);
}
.toggle .line2 {
display: none;
}
.toggle .line3 {
background-color: #c91919;
transform: scale(0.9) rotateZ(45deg) translate(-6px, -4px);
}
.toggle .toggle-menu {
background-color: white;
}
.nav-list {
list-style: none;
}
.nav-list-item {
text-align: center;
padding: 1rem 0;
}
.nav-link {
color: #fff;
font-size: 2.2rem;
text-decoration: none;
position: relative;
padding-bottom: 0.4rem;
}
.nav-link::before {
position: absolute;
content: '';
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #fff;
transform: scaleX(0);
transition: 0.4s ease-in-out;
transform-origin: left;
}
.nav-link:hover::before {
transform: scaleX(1);
}
<div class="container">
<nav class="nav-bar">
<div class="toggle-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="nav-list">
<li class="nav-list-item">Home</li>
<li class="nav-list-item">About</li>
<li class="nav-list-item">
Projects
</li>
<li class="nav-list-item">Clients</li>
<li class="nav-list-item">
Contact Me
</li>
</ul>
</nav>
</div>
Change .nav-bar { position: absolute; } to .nav-bar { position: fixed; }.
See the snippet below.
const toggleButton = document.querySelector('.toggle-menu');
const navBar = document.querySelector('.nav-bar');
toggleButton.addEventListener('click', () => {
navBar.classList.toggle('toggle');
});
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#200;300;400&display=swap');
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
font-size: 10px;
}
.container {
width: 100%;
height: 100vh;
/* background: linear-gradient(-45deg, #ee7752, #e73c7e);
background-size: 400% 400%; */
position: relative;
}
.nav-bar {
position: fixed;
background-color: #122;
left: -25rem;
height: 100vh;
width: 25rem;
display: flex;
justify-content: center;
align-items: center;
transition: 0.5s ease-out;
}
.toggle {
left: 0;
box-shadow: 1px 0 15px 2px rgba(0, 0, 0, 0.4);
}
.toggle-menu {
background-color: rgba(0, 0, 0, 0.2);
position: fixed;
top: 2rem;
left: 2rem;
width: 4rem;
height: 3rem;
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 0.2rem 0.5rem;
border-radius: 0.5rem;
}
.line {
width: 100%;
height: 4px;
border-radius: 5px;
background-color: #fff;
transition: 0.4s ease-out;
}
.toggle .line1 {
background-color: #c91919;
transform: scale(0.9) rotateZ(-45deg) translate(-6px, 4px);
}
.toggle .line2 {
display: none;
}
.toggle .line3 {
background-color: #c91919;
transform: scale(0.9) rotateZ(45deg) translate(-6px, -4px);
}
.toggle .toggle-menu {
background-color: white;
}
.nav-list {
list-style: none;
}
.nav-list-item {
text-align: center;
padding: 1rem 0;
}
.nav-link {
color: #fff;
font-size: 2.2rem;
text-decoration: none;
position: relative;
padding-bottom: 0.4rem;
}
.nav-link::before {
position: absolute;
content: '';
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #fff;
transform: scaleX(0);
transition: 0.4s ease-in-out;
transform-origin: left;
}
.nav-link:hover::before {
transform: scaleX(1);
}
<div class="container">
<nav class="nav-bar">
<div class="toggle-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="nav-list">
<li class="nav-list-item">Home</li>
<li class="nav-list-item">About</li>
<li class="nav-list-item">
Projects
</li>
<li class="nav-list-item">Clients</li>
<li class="nav-list-item">
Contact Me
</li>
</ul>
</nav>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

Element goes above other element - CSS

I have a hamburger menu inside my website and if I go inside a specific which I have a card with some other elements inside. But if I open the menu while I'm inside the page with this card element the card goes above the menu for some reason. I tried almost everything but I can't get it right. I can't see where is my mistake with the CSS code...
My react component (html):
import TopNavBarMobileComponent from "../TopNavMobileComponent";
import github_icon from '../../assets/github_icon.png'
import instagram_icon from '../../assets/instagram_icon.png'
import my_picture from '../../assets/my_picture.jpg'
import '../../css-mobile/AboutMeStyle.css'
function AboutMeMobile() {
return (
<div>
<TopNavBarMobileComponent />
<div className="info-card-container">
<aside class="profile-card">
<div class="mask-shadow"></div>
<header>
<a href="https://github.com/georgesepetadelis/">
<img src={my_picture} />
</a>
<h1 className="name">GEORGE SEPETADELIS</h1>
<h2>Software engineer</h2>
</header>
<div class="profile-bio">
<p>16 y/o and I'm from Greece. I have experience with many programming languages and Frameworks for all mobile platforms like Flutter, React-Native and also native Android and iOS development with Java and Swift. Also I am currently working on Unreal engine and Unity for some big projects. </p>
</div>
<ul class="profile-social-links">
<li>
<a href="https://github.com/georgesepetadelis/">
<img src={github_icon} />
</a>
</li>
<li>
<a href="https://www.instagram.com/sepetadelhsss/">
<img src={instagram_icon} />
</a>
</li>
<li>
<a href="https://twitter.com/gsepetadelis">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/social-twitter.svg" />
</a>
</li>
</ul>
</aside>
</div>
</div>
)
}
export default AboutMeMobile;
My css file:
#import url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,700italic,800italic,400,600,700,800);
img {
max-width: 100%;
}
.name {
margin-top: 7%;
}
.info-card-container {
z-index: 1;
margin-top: 15%;
width: 100%;
position: absolute;
display: inline-flex;
flex-direction: column;
align-items: center;
}
.profile-card {
position: relative;
width: 90%;
margin-top: 8%;
padding: 40px 30px 30px;
background: #fff;
border: 5px solid rgba(255,255,255,.7);
text-align: center;
border-radius: 8px;
transition: all 200ms ease;
}
.mask-shadow {
z-index: -1 !important;
width: 95%;
height: 12px;
background: #000;
bottom: 0;
left: 0;
right: 0;
margin: 0 auto;
position: absolute;
border-radius: 4px;
opacity: 0;
border-radius: 80px;
transition: all 400ms ease-in;
}
.mask-shadow {
opacity: 1;
box-shadow: 0px 30px 60px -5px rgba(55,55,71,0.3);
position: absolute;
}
.profile-card header {
display: block;
margin-bottom: 10px;
}
.profile-card header a {
width: 150px;
height: 150px;
display: block;
border-radius: 100%;
margin: -120px auto 0;
box-shadow: 0 0 0 5px #3300ff;
}
.profile-card header a img {
border-radius: 50%;
width: 150px;
height: 150px;
}
.profile-card header h1 {
font-size: 20px;
color: #444;
text-transform: uppercase;
margin-bottom: 5px;
}
.profile-card header h2 {
font-size: 14px;
color: #acacac;
text-transform: uppercase;
margin: 0;
}
.profile-bio {
font-size: 14px;
color:#a5a5a5;
line-height: 1.7;
font-style: italic;
margin-bottom: 30px;
}
.profile-social-links {
margin:0;
padding:0;
list-style: none;
}
.profile-social-links li {
display: inline-block;
margin: 0 10px;
}
.profile-social-links li a {
width: 55px;
height:55px;
display:block;
background:#f1f1f1;
border-radius:50%;
-webkit-transition: all 2.75s cubic-bezier(0,.83,.17,1);
-moz-transition: all 2.75s cubic-bezier(0,.83,.17,1);
-o-transition: all 2.75s cubic-bezier(0,.83,.17,1);
transition: all 2.75s cubic-bezier(0,.83,.17,1);
transform-style: preserve-3d;
}
.profile-social-links li a img {
width: 35px;
height: 35px;
margin: 10px auto 0;
}
.profile-social-links li a:hover {
background: #ddd;
transform: scale(1.2);
-webkit-transform: scale(1.2);
}
CSS has a 3d object location - the obvious x and y, but there is also a z element. This Z element determines which elements display over others, and which go behind. To set the z element (or index), use the z-index property.

Modal is not responsive for mobile, How to make it responsive on mobile?

My modal floats on the center of a desktop screen but on a mobile screen it floats on the top. When I keep reducing my screen size, it keeps holding its upper side, I want to show my modal content in the center of my phone screen. How can I make it float on the center of my phone's screen? I am attaching my code below. Thank you in advance.
const modals = document.querySelectorAll(".modal");
const modalBtns = document.querySelectorAll(".button");
const closeBtns = document.querySelectorAll(".close");
// Events
modalBtns.forEach((btn, index) =>
btn.addEventListener("click", () => openModal(index))
);
closeBtns.forEach((btn, index) =>
btn.addEventListener("click", () => closeModal(index))
);
// for closing when you click outside
modals.forEach((modal, index) =>
modal.addEventListener("click", (e) => {
if(e.target === e.currentTarget){
closeModal(index);
}
})
);
// Open
function openModal(index) {
modals[index].style.display = "block";
}
// Close
function closeModal(index) {
modals[index].style.display = "none";
}
/* Modal section styling */
:root {
--modal-duration: 1s;
--modal-color: crimson;
}
.button {
font-family: 'poppins', sans-serif;
display: inline-block;
background: crimson;
color: #fff;
font-size: 18px;
font-weight: 500;
padding: 8px 16px;
margin-top: 20px;
border-radius: 6px;
border: 2px solid crimson;
transition: all 0.3s ease;
}
.button:hover {
color: crimson;
background: none;
}
.modal {
font-family: 'Poppins', sans-serif;
display: none;
position: fixed;
z-index: 99999;
left: 0;
top: 0;
height: 100%;
width: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
margin: 51px auto;
width: 60%;
box-shadow: 0 5px 8px 0 rgba(0, 0, 0, 0.2), 0 7px 20px 0 rgba(0, 0, 0, 0.17);
animation-name: modalopen;
animation-duration: var(--modal-duration);
}
.modal-header h2,
.modal-footer h3 {
margin: 0;
}
.modal-header {
background: var(--modal-color);
font-size: 20px;
text-align: center;
padding: 10px;
color: #fff;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.modal-body {
background:crimson;
}
.modal-footer {
background: var(--modal-color);
padding: 10px;
font-size: 15px;
color: #fff;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
.close {
float: right;
font-size: 30px;
color: #fff;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.responsive {
width: 100%;
height: auto;
}
#keyframes modalopen {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<button id="modal-btn" class="button">Modal</button>
<div id="my-modal" class="modal">
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h3 style="font-weight: 400">On Going Project</h3>
</div>
<!-- Modal Body -->
<div class="modal-body">
<img src="#" alt="" style="width:100%;height:100%;">
</div>
<div class="modal-footer">
</div>
</div>
</div>
You can try with add some CSS code and this code for desktop and mobile both of screen in center position. i am sure this code helpful for you.
jsfiddle link
.modal-content { margin: 0;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);}

Why my overlay container is not moving left when I click SIGN UP button?

this is my codepan link:https://codepen.io/xaviour1504/pen/zYEzGLJ
when I am trying to click the sign up button only the sign-in part is moving to right but the overlay-container part is not moving to left. Here is my code for
/* move overlay to left */
.container.right-panel-active.overlay-container {
transform: translateX(-100%);
}
You are not selecting the overlay correctly.
Use:
.container.right-panel-active .overlay-container
That is, when right-panel-active class is set a child with overlay-container class is to be selected (that's what the space is for).
Try using these values:
/* move sign in to the right */
.container.right-panel-active .sign-in-container {
transform: translateX(-100%);
}
/* move overlay to left */
.container.right-panel-active.overlay-container {
transform: translateX(100%);
}
See here:
const signUpButton = document.getElementById('signUp');
const signInButton = document.getElementById('signIn');
const content = document.getElementById('container');
signUpButton.addEventListener('click', () =>
content.classList.add('right-panel-active')
);
signInButton.addEventListener('click', () =>
content.classList.remove('right-panel-active')
);
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#600&display=swap');
* {
box-sizing: border-box;
}
body {
font-family: 'Montserrat', sans-serif;
background-color: rgb(238, 229, 229);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: -20px 0 50px;
overflow: hidden;
}
h1 {
font-weight: bolder;
margin: 0;
}
p {
font-size: 15px;
font-weight: 100;
letter-spacing: 0.5px;
line-height: 20px;
margin: 20px 0 30px;
}
span {
font-size: 15px;
line-height: 20px;
letter-spacing: 0.5px;
font-weight: 100;
}
a {
color: #333;
text-decoration: none;
font-size: 15px;
margin: 15px 0;
}
.container {
background-color: white;
border-radius: 10px;
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
position: relative;
overflow: hidden;
width: 800px;
max-width: 100%;
min-height: 490px;
}
.form-container form {
background: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
padding: 0 50px;
text-align: center;
}
.social-container {
margin: 20px 0;
}
.social-container a {
border: solid 2px #ddd;
border-radius: 50%;
display: inline-flex;
justify-content: center;
align-items: center;
margin: 0 5px;
width: 40px;
height: 40px;
}
.form-container input {
background: #eee;
border: none;
padding: 12px 15px;
margin: 8px 0;
width: 100%;
}
button {
border: 1px solid orangered;
border-radius: 20px;
background: orangered;
color: white;
font-size: 15px;
font-weight: 100;
padding: 10px 40px;
letter-spacing: 1px;
transition: transform 80ms ease-in;
}
button:active {
transform: scale(0.95);
}
button:focus {
outline: none;
}
button.ghost {
background: transparent;
border-color: white;
}
.form-container {
position: absolute;
top: 0;
height: 100%;
transition: all 0.6s ease-in-out;
}
.sign-in-container {
left: 0;
width: 50%;
z-index: 1;
}
.sign-up-container {
opacity: 0;
width: 50%;
z-index: 1;
}
.overlay-container {
position: absolute;
top: 0;
left: 50%;
width: 50%;
height: 100%;
overflow: hidden;
transition: transform 0.6s ease-in-out;
z-index: 100;
}
.overlay {
background: #ff416c;
background: linear-gradient(to right, #ff4b2b, #ff416c) no-repeat 0 0 / cover;
color: white;
position: relative;
left: -100%;
height: 100%;
width: 200%;
transform: translateX(0);
transition: transform 0.6s ease-in-out;
}
.overlay-panel {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0 40px;
height: 100%;
width: 50%;
text-align: center;
transform: translateX(0);
transition: transform 0.6s ease-in-out;
}
.overlay-right {
right: 0;
transform: translateX(0);
}
.overlay-left {
transform: translateX(-20%);
}
/* animation */
/* move sign in to the right */
.container.right-panel-active .sign-in-container {
transform: translateX(-100%);
}
/* move overlay to left */
.container.right-panel-active.overlay-container {
transform: translateX(100%);
}
<div class="container" id="container">
<div class="form-container sign-up-container">
<form action="#">
<h1>Create Account</h1>
<div class="social-container">
<i class="fab fa-facebook"></i>
<i class="fab fa-google-plus-g"></i>
<i class="fab fa-linkedin"></i>
</div>
<span>or use your email for registration </span>
<input type="text" placeholder="Name" />
<input type="email" placeholder="Email" />
<input type="Password" placeholder="Password" />
<button>SIGN UP</button>
</form>
</div>
<div class="form-container sign-in-container">
<form action="#">
<h1>Sign in</h1>
<div class="social-container">
<i class="fab fa-facebook"></i>
<i class="fab fa-google-plus-g"></i>
<i class="fab fa-linkedin"></i>
</div>
<span>or use your account </span>
<input type="email" placeholder="Email" />
<input type="Password" placeholder="Password" />
Forgot your password?
<button>SIGN IN</button>
</form>
</div>
<div class="overlay-container">
<div class="overlay">
<div class="overlay-panel overlay-left">
<h1>Welcome Back!</h1>
<p>
To keep connected with us please login with your personal info
</p>
<button class="ghost" id="signIn">SIGN IN</button>
</div>
<div class="overlay-panel overlay-right">
<h1>Hello, Friend!</h1>
<p>Enter your personal details and start journey with us</p>
<button class="ghost" id="signUp">SIGN UP</button>
</div>
</div>
</div>
</div>

how do i show a div on clicking another div and hide it on clicking that same div?

i have a div with 7 children, on hover an item changes background and text pads left from center. I've done that with CSS.
now i want when the user clicks on an item it shows another div (.wrapper) with JavaScript. if the user click again it hides the particular div.
how can i achieve this logic with JavaScript?
here is my html snippet
<div class="category">
<div class="furniture">Furniture</div>
<div class="tableware">Tableware</div>
<div class="jewellery">Jewellery</div>
<div class="shoes">Shoes</div>
<div class="water_bottles">Water Bottles</div>
<div class="clothes">Clothes</div>
<div class="textiles">Fabric Patterns</div>
</div>
<div class="upload">
<div class="wrapper">
<div class="control"><img src="back.png"></div>
<div class="content"></div>
<div class="content_desc"></div>
<div class="control"><img src="forward.png"></div>
</div>
</div>
CSS code
/*styles individual divs in the category class*/
.category > div:hover {
cursor: pointer;
transform-style: flat;
animation-delay: 0.1s;
display: flex;
border: 1px 1px 1px 1px solid;
background-color: #898488;
color: #7AC4EE;
border-left-color: yellow;
box-sizing: border-box;
}
/*class that i want to display on click*/
.wrapper {
display: none;
flex-wrap: wrap;
justify-content: space-between;
background-color: white;
box-sizing: border-box;
width: 623px;
padding: 0;
align-self: center;
height: 100%;
margin-bottom: auto;
box-shadow: 0px 3px 7px 0px rgba(0,0,0,0.3);
}
/*the classes below are in .wrapper*/
.control {
flex: 1;
background:white;
position: relative;
}
.content {
flex: 4;
height: 92%;
width: 415px;
margin-top: 5px;
margin-bottom: 5px;
background: lightblue;
position: relative;
}
.content_desc {
flex: 2;
height: 22px;
width: 415px;
margin-top: 370px ;
margin-left: 104px;
margin-right: 98.5px;
background-color: white;
border: 0.3px solid;
position: absolute;
}
.control img {
position: absolute;
left: 50%;
top: 50%;
height: 40px;
width: 40px;
background: white;
box-sizing: border-box;
transform: translate(-50%, -50%);
}
.control img:hover {
cursor: pointer;
background-color: yellow;
transition-delay: 0.2s;
animation: 0.1s ease-in;
}
JavaScript
$(document).ready(function() {
$('.category' > div ).on('click', function(){
$('.wrapper').show();
})
});
I am not sure about the term particular div here. May be you can try with toggle(). You also have syntax error in wrapping the selector:
$(document).ready(function() {
$('.category > div').on('click', function(){
$('.wrapper').toggle();
})
});
/*styles individual divs in the category class*/
.category > div:hover {
cursor: pointer;
transform-style: flat;
animation-delay: 0.1s;
display: flex;
border: 1px 1px 1px 1px solid;
background-color: #898488;
color: #7AC4EE;
border-left-color: yellow;
box-sizing: border-box;
}
/*class that i want to display on click*/
.wrapper {
display: none;
flex-wrap: wrap;
justify-content: space-between;
background-color: white;
box-sizing: border-box;
width: 623px;
padding: 0;
align-self: center;
height: 100%;
margin-bottom: auto;
box-shadow: 0px 3px 7px 0px rgba(0,0,0,0.3);
}
/*the classes below are in .wrapper*/
.control {
flex: 1;
background:white;
position: relative;
}
.content {
flex: 4;
height: 92%;
width: 415px;
margin-top: 5px;
margin-bottom: 5px;
background: lightblue;
position: relative;
}
.content_desc {
flex: 2;
height: 22px;
width: 415px;
margin-top: 370px ;
margin-left: 104px;
margin-right: 98.5px;
background-color: white;
border: 0.3px solid;
position: absolute;
}
.control img {
position: absolute;
left: 50%;
top: 50%;
height: 40px;
width: 40px;
background: white;
box-sizing: border-box;
transform: translate(-50%, -50%);
}
.control img:hover {
cursor: pointer;
background-color: yellow;
transition-delay: 0.2s;
animation: 0.1s ease-in;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="category">
<div class="furniture">Furniture</div>
<div class="tableware">Tableware</div>
<div class="jewellery">Jewellery</div>
<div class="shoes">Shoes</div>
<div class="water_bottles">Water Bottles</div>
<div class="clothes">Clothes</div>
<div class="textiles">Fabric Patterns</div>
</div>
<div class="upload">
<div class="wrapper">
<div class="control"><img src="back.png"></div>
<div class="content"></div>
<div class="content_desc"></div>
<div class="control"><img src="forward.png"></div>
</div>
</div>
You made a mistake in your css selector, it's not '.category' > div, it should be '.category > div'
$(document).ready(function() {
$('.category > div').on('click', function(){
$('.wrapper').toggle();
})
});
use this code
$(document).ready(function() {
$('.category>div' ).on('click', function(){
$('.wrapper').toggle();
})
});
and add this css to hide div in starting
.wrapper{
display:none
}

Categories