The concept is simple, when the text gets too long for the container, it would infinitely animate (scroll) from left to right, and repeat this processes after it reaches the end.
How should I go about making this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div class="auto-scroll">
<p>
This text should scroll. Lorem ipsum dolor sit amet consectetur adipisicing elit. Excepturi commodi magni quo officia error ab veniam aspernatur. Quos ducimus, hic, maxime dicta optio quidem
nostrum sint commodi velit, ut distinctio. And return to beginning.
</p>
</div>
<style>
.auto-scroll {
background: black;
padding: 18px;
}
.auto-scroll p {
font-family: monospace;
font-size: 18px;
color: white;
margin: 0;
white-space: nowrap;
overflow: auto;
}
.auto-scroll ::-webkit-scrollbar {
height: 10px; /* will be 0px */
}
.auto-scroll ::-webkit-scrollbar-track {
background: #000;
}
.auto-scroll ::-webkit-scrollbar-thumb {
background: #fff;
}
</style>
</body>
</html>
You don't need javascript you can make it in css like this following code
div{
width: 100%;
background-color: black;
white-space: nowrap;
overflow: hidden;
box-sizing: border-box;
}
p{
display: inline-block;
color: #FFF;
padding-left: 100%;
animation: move 25s linear infinite;
}
#keyframes move {
0% { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}
<div>
<p>This text should scroll. Lorem ipsum dolor sit amet consectetur adipisicing elit. Excepturi commodi magni quo officia error ab veniam aspernatur. Quos ducimus, hic, maxime dicta optio quidem nostrum sint commodi velit, ut distinctio. And return to beginning.</p>
</div>
Related
I am not very well versed in HTML and CSS. I am currently building a website and I integrated a sidebar into my web application using Bootstrap, but it has messed my layouts, and I can't seem to figure out how to move the content in a block to the left of side of my sidebar.
Please view the image on this link
[1]: https://i.stack.imgur.com/XFaVv.png
As seen in the picture above, my sidebar is located at the right and my content is located at the below of my sidebar. Below are my codes for my sidebar and the base template.
// Not bringing sidebar when active
const menu_toggle = document.querySelector('.menu-toggle');
const sidebar = document.querySelector('.sidebar');
// When the button is clicked the sidebar will be active in the following code
menu_toggle.addEventListener('click', () => {
menu_toggle.classList.toggle('is-active');
sidebar.classList.toggle('is-active');
})
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
/* Sidebar Section */
.app {
display: flex;
min-height: 100vh;
}
.sidebar {
flex: 1 1 0;
max-width: 300px;
padding: 20px;
background: linear-gradient(#ed7014, #fa5b3d);
/* With Scrollbar */
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 1000;
display: block;
overflow-x: hidden;
overflow-y: auto;
/* Scrollable contents if viewport is shorter than content. */
border-right: 1px solid #eee;
}
.sidebar h3 {
font-family: 'Bungee', cursive;
color: #fff;
}
.sidebar .menu {
margin: 0 -1rem;
}
.sidebar .menu .menu-item {
display: block;
padding: 1em;
color: #fff;
text-decoration: none;
transition: 0.2s linear;
}
.sidebar .menu .menu-item:hover,
.sidebar .menu .menu-item.is-active {
color: rgb(255, 238, 151);
;
border-right: 5px solid rgb(255, 238, 151);
}
/* Content Scrollbar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
border-radius: 5px;
}
::-webkit-scrollbar-thumb {
border-radius: 5px;
background-color: #ffa500;
}
::-webkit-scrollbar-thumb:hover {
background-color: #d67229;
}
/* Content Section */
.content {
flex: 1 1 0;
padding: 2rem;
background: linear-gradient(#dd5713, #d67229);
}
.content img {
width: 100%;
max-width: 300px;
display: block;
margin: auto;
}
.content h1 {
font-family: 'Bungee', cursive;
color: #fff;
margin-bottom: 1rem;
}
.content strong {
font-family: 'Bungee', cursive;
color: #fff;
}
.content p {
text-align: justify;
color: #fff;
}
/* Sample Code Content */
.sample-code {
width: 65%;
background: rgb(255, 238, 151);
padding: 1em;
margin-bottom: 2em;
border-radius: 10px;
box-shadow: 15px 15px;
}
.sample-code p {
color: #000;
}
/* Button Sidebar section */
.menu-toggle {
display: none;
position: fixed;
top: 2rem;
right: 2rem;
width: 60px;
height: 60px;
border-radius: 99px;
background-color: #ed7014;
cursor: pointer;
}
.button {
position: relative;
top: calc(50% - 2px);
left: 50%;
transform: translate(-50%, -50%);
width: 32px;
}
.button>span,
.button>span::before,
.button>span::after {
display: block;
position: absolute;
width: 100%;
height: 4px;
border-radius: 99px;
background-color: #fff;
transition-duration: .25s;
}
.button>span::before {
content: '';
top: -8px;
}
.button>span::after {
content: '';
top: 8px;
}
/* Button Animation */
.menu-toggle.is-active .button>span {
transform: rotate(45deg);
}
.menu-toggle.is-active .button>span::before {
top: 0;
transform: rotate(0deg);
}
.menu-toggle.menu-toggle.is-active .button>span::after {
top: 0;
transform: rotate(90deg);
}
/* Sidebar Footer */
.white-section {
text-align: center;
}
.p-white-sec {
color: #fff;
}
.container-fluid {
padding: 7px 15px;
}
.footer-icon {
margin: 20px 10px;
color: #fff;
}
.footer-icon:hover {
color: #ffa500;
transition: 0.2s linear;
}
/* Mobile Size */
#media (max-width: 1024px) {
/* Sidebar Section */
.sidebar {
max-width: 200px;
}
.sidebar img {
height: 6.5rem;
width: 10rem;
}
}
#media (max-width: 768px) {
/* Sidebar Section */
.menu-toggle {
display: block;
}
.sidebar {
position: fixed;
top: 0;
left: -300px;
height: 100vh;
width: 100%;
max-width: 300px;
transition: 0.2s linear;
}
.sidebar.is-active {
left: 0;
}
.sidebar img {
height: 6.5rem;
width: 10rem;
}
/* Content */
.content {
padding-top: 8rem;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Codin'up | HTML Course</title>
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght#100;400;900&family=Ubuntu:ital,wght#0,300;1,400;1,700&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Bungee&family=Poppins&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<!-- Favicon -->
<link rel="shortcut icon" href="/favicon.png">
<!-- CSS Stylesheet -->
<link rel="stylesheet" href="/CSS/List of Course/HTML Course.css">
</head>
<body>
<section class="app">
<!-- Button for Sidebar -->
<div class="menu-toggle">
<div class="button">
<span></span>
</div>
</div>
<!-- Sidebar Section -->
<aside class="sidebar">
<a href="/HTML/List of Course/HTML Course.html">
<img src="/Logo/Codin'up Logo (1) White.png" alt="Codin'up">
</a>
<h3>HTML Course</h3>
<nav class="menu">
Home
Courses
</nav>
<hr>
<nav class="menu">
HTML Introduction
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
</nav>
<hr>
<!-- Sidebar Footer -->
<footer class="white-section" id="footer">
<div class="container-fluid">
<i class="fa-brands fa-twitter footer-icon"></i>
<i class="fa-brands fa-facebook-f footer-icon"></i>
<i class="fa-brands fa-instagram footer-icon"></i>
<i class="fa-solid fa-envelope footer-icon"></i>
<p class="p-white-sec">© 2022 ITMAWD21 Group 3</p>
</div>
</footer>
</aside>
<!-- Content Section -->
<main class="content">
<h1>Introduction To HTML</h1>
<img src="/Logo/HTML Logo.png" alt="Codin'up Logo">
<strong>Description</strong>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium ipsa, quod, placeat cupiditate enim hic natus maiores nobis sequi nisi odit voluptas earum quas perspiciatis qui explicabo recusandae ullam quibusdam? Lorem ipsum dolor sit amet
consectetur, adipisicing elit. Dignissimos obcaecati exercitationem voluptatem accusamus, beatae sunt voluptatibus quam odio magnam, mollitia minima dicta distinctio, amet accusantium! Dolore debitis qui quis iusto. Lorem, ipsum dolor sit amet
consectetur adipisicing elit. Accusantium harum corrupti nisi ratione aperiam commodi rerum. Delectus illum suscipit distinctio unde iste veritatis voluptate nulla, enim rem harum ullam rerum. Lorem ipsum dolor sit amet consectetur adipisicing
elit. Ut cumque totam ipsum, quia voluptate quam esse reprehenderit explicabo atque, molestiae doloribus earum repellendus architecto aperiam minima impedit dicta autem laboriosam! Lorem ipsum dolor sit amet consectetur adipisicing elit. Similique,
corrupti adipisci. Itaque sint, nemo laborum a ratione corrupti laboriosam tenetur soluta pariatur nostrum fuga, earum voluptate ducimus iure ipsum saepe? Lorem, ipsum dolor sit amet consectetur adipisicing elit. Commodi repudiandae recusandae
iste, molestiae modi ea numquam vero repellat. Doloremque iusto labore nobis placeat perspiciatis optio repellendus eius adipisci voluptas expedita. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dolor doloremque rem debitis? Sed quod
eligendi inventore deleniti aliquid velit, magni perferendis, quaerat officiis in consequuntur tenetur ipsum animi tempore asperiores.</p>
<!-- Sample Code Content -->
<div class="sample-code">
<p><html></p>
<p><span style="padding-left: 20px;"><head></span></p>
<p><span style="padding-left: 40px;"><title>HTML Course</title></span></p>
<p><span style="padding-left: 20px;"></head></span></p>
<p><span style="padding-left: 20px;"><body></span></p>
<p><span style="padding-left: 40px;"><p>Hello World<p></span></p>
<p><span style="padding-left: 20px;"></body></span></p>
<p></html></p>
</div>
<strong>Code Description</strong>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Qui iusto, eveniet repudiandae ratione sint harum pariatur id numquam doloremque sequi eaque quo accusamus ab nihil aut alias inventore! Cumque, tempore.</p>
</main>
</section>
<!-- Font Awesome -->
<script src="https://kit.fontawesome.com/c9df5e490e.js" crossorigin="anonymous"></script>
<!-- Bootstrap JS & External JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="/JS/List of Course/HTML Course.js"></script>
</body>
</html>
Can someone help me fit the content to the right beside my sidebar especially its layout? Thanks for the big help!
I would just apply position: sticky and height: 100vh on the sidebar:
position: sticky;
height: 100vh;
Giving it height: 100vh makes sure the sidebar always stretches to the entire height of the screen. position: sticky works in a similiar fashion to position: fixed but it doesn't affect the document flow in the same way. You can then apply positioning values such as top: 0 and left: 0, but those properties are already applied in your snippet.
// Not bringing sidebar when active
const menu_toggle = document.querySelector('.menu-toggle');
const sidebar = document.querySelector('.sidebar');
// When the button is clicked the sidebar will be active in the following code
menu_toggle.addEventListener('click', () => {
menu_toggle.classList.toggle('is-active');
sidebar.classList.toggle('is-active');
})
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
/* Sidebar Section */
.app {
display: flex;
min-height: 100vh;
}
.sidebar {
flex: 1 1 0;
max-width: 300px;
padding: 20px;
background: linear-gradient(#ed7014, #fa5b3d);
/* With Scrollbar */
/* Edit start */
position: sticky;
height: 100vh;
/* Edit end */
top: 0;
bottom: 0;
left: 0;
z-index: 1000;
display: block;
overflow-x: hidden;
overflow-y: auto;
/* Scrollable contents if viewport is shorter than content. */
border-right: 1px solid #eee;
}
.sidebar h3 {
font-family: 'Bungee', cursive;
color: #fff;
}
.sidebar .menu {
margin: 0 -1rem;
}
.sidebar .menu .menu-item {
display: block;
padding: 1em;
color: #fff;
text-decoration: none;
transition: 0.2s linear;
}
.sidebar .menu .menu-item:hover,
.sidebar .menu .menu-item.is-active {
color: rgb(255, 238, 151);
;
border-right: 5px solid rgb(255, 238, 151);
}
/* Content Scrollbar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
border-radius: 5px;
}
::-webkit-scrollbar-thumb {
border-radius: 5px;
background-color: #ffa500;
}
::-webkit-scrollbar-thumb:hover {
background-color: #d67229;
}
/* Content Section */
.content {
flex: 1 1 0;
padding: 2rem;
background: linear-gradient(#dd5713, #d67229);
}
.content img {
width: 100%;
max-width: 300px;
display: block;
margin: auto;
}
.content h1 {
font-family: 'Bungee', cursive;
color: #fff;
margin-bottom: 1rem;
}
.content strong {
font-family: 'Bungee', cursive;
color: #fff;
}
.content p {
text-align: justify;
color: #fff;
}
/* Sample Code Content */
.sample-code {
width: 65%;
background: rgb(255, 238, 151);
padding: 1em;
margin-bottom: 2em;
border-radius: 10px;
box-shadow: 15px 15px;
}
.sample-code p {
color: #000;
}
/* Button Sidebar section */
.menu-toggle {
display: none;
position: fixed;
top: 2rem;
right: 2rem;
width: 60px;
height: 60px;
border-radius: 99px;
background-color: #ed7014;
cursor: pointer;
}
.button {
position: relative;
top: calc(50% - 2px);
left: 50%;
transform: translate(-50%, -50%);
width: 32px;
}
.button>span,
.button>span::before,
.button>span::after {
display: block;
position: absolute;
width: 100%;
height: 4px;
border-radius: 99px;
background-color: #fff;
transition-duration: .25s;
}
.button>span::before {
content: '';
top: -8px;
}
.button>span::after {
content: '';
top: 8px;
}
/* Button Animation */
.menu-toggle.is-active .button>span {
transform: rotate(45deg);
}
.menu-toggle.is-active .button>span::before {
top: 0;
transform: rotate(0deg);
}
.menu-toggle.menu-toggle.is-active .button>span::after {
top: 0;
transform: rotate(90deg);
}
/* Sidebar Footer */
.white-section {
text-align: center;
}
.p-white-sec {
color: #fff;
}
.container-fluid {
padding: 7px 15px;
}
.footer-icon {
margin: 20px 10px;
color: #fff;
}
.footer-icon:hover {
color: #ffa500;
transition: 0.2s linear;
}
/* Mobile Size */
#media (max-width: 1024px) {
/* Sidebar Section */
.sidebar {
max-width: 200px;
}
.sidebar img {
height: 6.5rem;
width: 10rem;
}
}
#media (max-width: 768px) {
/* Sidebar Section */
.menu-toggle {
display: block;
}
.sidebar {
position: fixed;
top: 0;
left: -300px;
height: 100vh;
width: 100%;
max-width: 300px;
transition: 0.2s linear;
}
.sidebar.is-active {
left: 0;
}
.sidebar img {
height: 6.5rem;
width: 10rem;
}
/* Content */
.content {
padding-top: 8rem;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Codin'up | HTML Course</title>
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght#100;400;900&family=Ubuntu:ital,wght#0,300;1,400;1,700&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Bungee&family=Poppins&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<!-- Favicon -->
<link rel="shortcut icon" href="/favicon.png">
<!-- CSS Stylesheet -->
<link rel="stylesheet" href="/CSS/List of Course/HTML Course.css">
</head>
<body>
<section class="app">
<!-- Button for Sidebar -->
<div class="menu-toggle">
<div class="button">
<span></span>
</div>
</div>
<!-- Sidebar Section -->
<aside class="sidebar">
<a href="/HTML/List of Course/HTML Course.html">
<img src="/Logo/Codin'up Logo (1) White.png" alt="Codin'up">
</a>
<h3>HTML Course</h3>
<nav class="menu">
Home
Courses
</nav>
<hr>
<nav class="menu">
HTML Introduction
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
HTML Course no.
</nav>
<hr>
<!-- Sidebar Footer -->
<footer class="white-section" id="footer">
<div class="container-fluid">
<i class="fa-brands fa-twitter footer-icon"></i>
<i class="fa-brands fa-facebook-f footer-icon"></i>
<i class="fa-brands fa-instagram footer-icon"></i>
<i class="fa-solid fa-envelope footer-icon"></i>
<p class="p-white-sec">© 2022 ITMAWD21 Group 3</p>
</div>
</footer>
</aside>
<!-- Content Section -->
<main class="content">
<h1>Introduction To HTML</h1>
<img src="/Logo/HTML Logo.png" alt="Codin'up Logo">
<strong>Description</strong>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium ipsa, quod, placeat cupiditate enim hic natus maiores nobis sequi nisi odit voluptas earum quas perspiciatis qui explicabo recusandae ullam quibusdam? Lorem ipsum dolor sit amet
consectetur, adipisicing elit. Dignissimos obcaecati exercitationem voluptatem accusamus, beatae sunt voluptatibus quam odio magnam, mollitia minima dicta distinctio, amet accusantium! Dolore debitis qui quis iusto. Lorem, ipsum dolor sit amet
consectetur adipisicing elit. Accusantium harum corrupti nisi ratione aperiam commodi rerum. Delectus illum suscipit distinctio unde iste veritatis voluptate nulla, enim rem harum ullam rerum. Lorem ipsum dolor sit amet consectetur adipisicing
elit. Ut cumque totam ipsum, quia voluptate quam esse reprehenderit explicabo atque, molestiae doloribus earum repellendus architecto aperiam minima impedit dicta autem laboriosam! Lorem ipsum dolor sit amet consectetur adipisicing elit. Similique,
corrupti adipisci. Itaque sint, nemo laborum a ratione corrupti laboriosam tenetur soluta pariatur nostrum fuga, earum voluptate ducimus iure ipsum saepe? Lorem, ipsum dolor sit amet consectetur adipisicing elit. Commodi repudiandae recusandae
iste, molestiae modi ea numquam vero repellat. Doloremque iusto labore nobis placeat perspiciatis optio repellendus eius adipisci voluptas expedita. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dolor doloremque rem debitis? Sed quod
eligendi inventore deleniti aliquid velit, magni perferendis, quaerat officiis in consequuntur tenetur ipsum animi tempore asperiores.</p>
<!-- Sample Code Content -->
<div class="sample-code">
<p><html></p>
<p><span style="padding-left: 20px;"><head></span></p>
<p><span style="padding-left: 40px;"><title>HTML Course</title></span></p>
<p><span style="padding-left: 20px;"></head></span></p>
<p><span style="padding-left: 20px;"><body></span></p>
<p><span style="padding-left: 40px;"><p>Hello World<p></span></p>
<p><span style="padding-left: 20px;"></body></span></p>
<p></html></p>
</div>
<strong>Code Description</strong>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Qui iusto, eveniet repudiandae ratione sint harum pariatur id numquam doloremque sequi eaque quo accusamus ab nihil aut alias inventore! Cumque, tempore.</p>
</main>
</section>
<!-- Font Awesome -->
<script src="https://kit.fontawesome.com/c9df5e490e.js" crossorigin="anonymous"></script>
<!-- Bootstrap JS & External JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="/JS/List of Course/HTML Course.js"></script>
</body>
</html>
I don't know if i understand well but.
Try in the content class to add:
width:100%;
padding-left:300px; (the width of the menu)
.sidebar has a position; fixed.
You could apply styling to the main content <main class="content" style="left: 272px;position: absolute;">. But you must also account for the media queries adjusting the width of the sidebar. E.g.
#media (max-width: 1024px){
.sidebar {
max-width: 200px;
}
main.content {
left: 200px;
}
}
and
#media (max-width: 768px) {
.sidebar {
position: fixed;
top: 0;
left: -300px;
height: 100vh;
width: 100%;
max-width: 300px;
transition: 0.2s linear;
}
main.content {
left: 0;
height: 100%;
}
}
I would also use width property over max-width. To be sure that the content is aligns always as expected.
I have checked the layout maybe you can try using rows and columns to sort it out
<div class="row">
<div class="col-lg-3 col-xs-4">
//Sidebar code
</div>
<div class="col-lg-9 col-xs-8">
//Content code
</div>
</div>
This could be better option and will also be responsive.
If you are not comfortable or familiar then maybe like others suggested you can remove position:fixed styling in .sidebar will solve this problem temporarily
I have 2 div elements, and I want to add something on the Div 2 that when I Click on that Div, it will Display Div 1, so both DIV's will be visible when clicking Div 2!
Div 2 should remain visible all the time, but when I click on DIV 2, it should display Div 1!
I want a JS script!
.box1 {
display: none;
color: white;
font-weight: 100;
background-color: rgba(234, 21, 56, 0.3);
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
border: 3px solid #ea1538;
width: 200px;
max-height: 300px;
overflow: scroll;
margin-left: 20px;
margin-top: 40px;
transition: ease 0.5s;
padding: 10px 10px;
box-sizing: border-box;
box-shadow: 0px 0px 10px gainsboro;
}
.box1::-webkit-scrollbar {
display: none;
}
.box1:hover {
transition: ease 0.5s;
transform: scale(1.1);
}
#cover1 {
width: 100%;
height: 40%;
}
.box2 {
display: inline-block;
color: white;
font-weight: 100;
background-color: rgba(234, 21, 56, 0.3);
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
border: 3px solid #ea1538;
width: 200px;
max-height: 300px;
overflow: scroll;
margin-left: 1%;
margin-top: 40px;
transition: ease 0.5s;
padding: 10px 10px;
box-sizing: border-box;
box-shadow: 0px 0px 10px gainsboro;
}
.box2::-webkit-scrollbar {
display: none;
}
.box2:hover {
transition: ease 0.5s;
transform: scale(1.1);
}
#cover2 {
width: 100%;
height: 40%;
}
<div class="box1">
<img src="/images/Books/book_bg.jpg" alt="cover" id="cover1" />
<h3 class="desc1">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et iste ipsum harum beatae dolor fugit repudiandae a quaerat doloremque pariatur, suscipit molestias ipsa minus. Non explicabo quam quasi illo accusamus aliquid, reiciendis autem? Quas odio hic
pariatur necessitatibus nobis nisi fugiat ab voluptate. Perferendis maiores quisquam cumque quod aspernatur ipsa?
</h3>
</div>
<div class="box2">
<button type="button" id="box2btn" onclick="href='window.location.https://www.facebook.com'">
<img src="/images/Books/book_bg.jpg" alt="cover" id="cover2" />
<h3>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Excepturi
natus quidem perferendis architecto sapiente, eius, praesentium, odio
illo provident quos nostrum quaerat! Placeat saepe, blanditiis id
assumenda ab autem in unde maxime alias, obcaecati distinctio expedita
veritatis deserunt atque exercitationem quasi dolorum eum quas. Voluptas
consequatur nisi sint porro quos?
</h3>
</div>
Here we go https://jsfiddle.net/byr0kqL5/
The simple function
function addNewDiv() {
const box1 = document.getElementById("box1-content") //find element with id `box1-content`
box1.classList.remove("display-none"); //make box 1 visible by `display-none` removal
}
but you need to add this style
.display-none {
display: none;
}
Your box 1 will be like this
<div class="box1 display-none" id="box1-content"></div>
Lastly, your box 2 needs to have onclick event
<div class="box2" onclick="addNewDiv()"></div>
Firstly add this attribute to Div2 :
onclick="showDiv()"
and add the id and class to Div1
id="div1"
class="hide"
JavaScript :
function showDiv() {
div1=document.getElementById("div1");
div1.classList.remove("hide");
}
CSS:
.hide{
display: none;
}
I have created a Flipbook using HTML, CSS3 and JavaScript. It is working fine on Google Chrome but it is not working properly on Firefox. I have Googled and tried to find answer. In most cases it is said that Firefox handle hoisting differently than Chrome. But there is no solution to it. Output is in the link below. If open with Chrome, it works fine but creates problems if opened with Firefox.
My code is:
var front = document.querySelector('.face-front');
var back = document.querySelector('.face-back');
var flip = document.querySelector('.book-content');
var uno = document.querySelectorAll('.book');
var portada = document.querySelectorAll('#portada');
var contZindex = 2;
var customZindex = 1;
// javascript hoisting function starts
// javascript hoisting function ends
for(var i = 0; i < uno.length; i++){
uno[i].style.zIndex = customZindex;
customZindex--;
uno[i].addEventListener('click', function(e){
var tgt = event.target;
var unoThis = this;
unoThis.style.zIndex = contZindex;
contZindex++;
if(tgt.getAttribute('class') == 'face-front'){
unoThis.style.zIndex = contZindex;
contZindex += 20;
setTimeout(function(){
unoThis.style.transform = 'rotateY(-180deg)';
}, 500);
// setTimeout(buntyTimeoutFront(), 500);
}
if(tgt.getAttribute('class') == 'face-back'){
unoThis.style.zIndex = contZindex;
contZindex += 20;
setTimeout(function(){
unoThis.style.transform = 'rotateY(-0deg)';
}, 500);
// setTimeout(buntyTimeoutBack(), 500);
}
if(tgt.getAttribute('id') == 'portada'){
flip.classList.remove("trnsf-reset");
flip.classList.add("trnsf");
}
if(tgt.getAttribute('id') == 'trsf'){
flip.classList.remove("trnsf");
flip.classList.add("trnsf-reset");
}
});
}
*{
pddding: 0;
margin: 0;
font-family: sans-serif;
}
p{
margin-top: 0;
font-size: 14px;
text-align: justify;
}
/* classes for javascript starts*/
.trnsf{
/* transform for diff browser starts */
-webkit-transform: translateX(80px);
-moz-transform: translateX(80px);
-ms-transform: translateX(80px);
-o-transform: translateX(80px);
transform: translateX(80px);
/* transform for diff browser ends */
}
.trnsf-reset{
/* transform for diff browser starts */
-webkit-transform: translateX(0px);
-moz-transform: translateX(0px);
-ms-transform: translateX(0px);
-o-transform: translateX(0px);
transform: translateX(0px);
/* transform for diff browser ends */
}
/* classes for javascript ends*/
.container, .book-content{
/* display flex starts*/
display: flex;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
/* display flex ends*/
/* justify-content starts */
justify-content: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
/* justify-content ends */
/* align items center */
align-items: center;
-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
/* align items center */
}
.container{
width: 100%;
height: 100vh;
background: #2d6f75;
}
.book-content{
width: 65%;
min-width: 250px;
max-width: 400px;
height: 330px;
position: relative;
/* perspective for css starts */
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-ms-perspective: 1000px;
-o-perspective: 1000px;
perspective: 1000px;
/* perspective for css ends */
transition: 1s;
}
.book{
position: absolute;
width: 65%;
height: 100%;
transition: 1s;
/* transform-style starts */
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
/* transform-style ends */
/* transform-oregin starts */
transform-origin: left;
-webkit-transform-origin: left;
-moz-transform-origin: left;
-ms-transform-origin: left;
-o-transform-origin: left;
/* transform-oregin ends */
}
.face-front, .face-back{
width: 100%;
height: 100%;
padding: 15px;
background: white;
box-sizing: border-box;
overflow: hidden;
}
.face-front{
box-shadow: inset 3px 0px 20px -7px black;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
.face-back{
position: absolute;
top: 0;
left: 0;
/* transform for diff browser starts */
transform: translateZ(-1px) rotateY(180deg);
-webkit-transform: translateZ(-1px) rotateY(180deg);
-moz-transform: translateZ(-1px) rotateY(180deg);
-ms-transform: translateZ(-1px) rotateY(180deg);
-o-transform: translateZ(-1px) rotateY(180deg);
/* transform for diff browser ends */
box-shadow: inset -3px 1px 20px -7px black;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
#portada{
background: url('../images/front.jpg');
}
#portada-back{
background: url('../images/back.jpg');
}
#portada, #portada-back{
background-size: 100% 100%;
}
/* responsive part starts here */
#media screen and (max-width: 800px){
p{
font-size: 12px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<title>Document</title>
</head>
<body>
<div class="container" id = "container">
<div class="book-content">
<!-- book container -->
<div class="book">
<div class="face-front" id = "portada"></div>
<div class="face-back" id = "trsf">
<h1>Title 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta cupiditate, at aut harum necessitatibus doloremque inventore dolores dolorem facilis quas consectetur, incidunt voluptatibus blanditiis assumenda ratione, culpa iusto exercitationem vel.</p>
</div>
</div>
<!-- book container -->
<!-- book container -->
<div class="book">
<div class="face-front">
<h1>Title 2</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta cupiditate, at aut harum necessitatibus doloremque inventore dolores dolorem facilis quas consectetur, incidunt voluptatibus blanditiis assumenda ratione, culpa iusto exercitationem vel.</p>
</div>
<div class="face-back">
<h1>Title 3</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta cupiditate, at aut harum necessitatibus doloremque inventore dolores dolorem facilis quas consectetur, incidunt voluptatibus blanditiis assumenda ratione, culpa iusto exercitationem vel.</p>
</div>
</div>
<!-- book container -->
<!-- book container -->
<div class="book">
<div class="face-front">
<h1>Title 4</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta cupiditate, at aut harum necessitatibus doloremque inventore dolores dolorem facilis quas consectetur, incidunt voluptatibus blanditiis assumenda ratione, culpa iusto exercitationem vel.</p>
</div>
<div class="face-back">
<h1>Title 5</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta cupiditate, at aut harum necessitatibus doloremque inventore dolores dolorem facilis quas consectetur, incidunt voluptatibus blanditiis assumenda ratione, culpa iusto exercitationem vel.</p>
</div>
</div>
<!-- book container -->
<!-- book container -->
<div class="book">
<div class="face-front">
<h1>Title 6</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta cupiditate, at aut harum necessitatibus doloremque inventore dolores dolorem facilis quas consectetur, incidunt voluptatibus blanditiis assumenda ratione, culpa iusto exercitationem vel.</p>
</div>
<div class="face-back" id = "portada-back"></div>
</div>
<!-- book container -->
</div>
</div>
<script src = "js/script.js"></script>
</body>
</html>
The output is in the link below.
https://studyoob.com/myCustomFlipbook/
Your help would get me the project done.
I have pieced together a portfolio website using several tutorials and I can't figure out why the hamburger menu is not visible as it downsizes. It works fine when I take out the main content in the HTML with the sections, but if there is any main content then the burger menu does not appear.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght#400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Audiowide&display=swap" rel="stylesheet">
<title>Portfolio</title>
</head>
<body>
<nav>
<div class="logo">
<h4>Portfolio</h4>
</div>
<ul class="nav-links">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<main>
<div class="about-area" id="about">
<div class="text-part">
<h1>About</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore ullam,
exercitationem voluptate enim nobis id quas praesentium, fugit ipsum porro omnis!
Illo eum exercitationem eius, quam quae deserunt? Distinctio, voluptatibus. Lorem
ipsum dolor sit amet consectetur adipisicing elit. Repellendus non ab iure, debitis
minima at maxime nisi? Illum nesciunt nihil hic, provident dolorem molestias distinctio
optio officia suscipit nemo natus!</p>
</div>
</div>
<div class="portfolio-area" id="portfolio">
<div class="text-part">
<h1>Portfolio</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore ullam,
exercitationem voluptate enim nobis id quas praesentium, fugit ipsum porro omnis!
Illo eum exercitationem eius, quam quae deserunt? Distinctio, voluptatibus. Lorem
ipsum dolor sit amet consectetur adipisicing elit. Repellendus non ab iure, debitis
minima at maxime nisi? Illum nesciunt nihil hic, provident dolorem molestias distinctio
optio officia suscipit nemo natus!</p>
</div>
</div>
<div class="contact-area" id="contact">
<div class="text-part">
<h1>Contact</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore ullam,
exercitationem voluptate enim nobis id quas praesentium, fugit ipsum porro omnis!
Illo eum exercitationem eius, quam quae deserunt? Distinctio, voluptatibus. Lorem
ipsum dolor sit amet consectetur adipisicing elit. Repellendus non ab iure, debitis
minima at maxime nisi? Illum nesciunt nihil hic, provident dolorem molestias distinctio
optio officia suscipit nemo natus!</p>
</div>
</div>
</main>
<script src="app.js"></script>
</body>
</html>
CSS:
* {
margin: 0px; /* Remove unwanted inherent sizing */
padding: 0px;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
nav {
display: flex; /*icons are next to each other */
justify-content: space-around; /* */
align-items: center; /* Center items vertically */
min-height: 8vh;
background-color: #0e9763;
font-family: 'Poppins', sans-serif;
}
.logo {
color: rgb(226, 226, 226);
text-transform: uppercase;
letter-spacing: 5px;
font-size: 20px;
}
.nav-links {
display: flex; /* spreads out text */
justify-content: space-around; /* using flex adds more space around the items using width */
width: 30%;
}
.nav-links li {
list-style: none; /* Removes bullet points */
}
.nav-links a{
color: rgb(226, 226, 226);
text-decoration: none; /* Removes default link colors */
letter-spacing: 3px;
font-size: 14px;
}
.burger {
display: none; /* Hides the burger menu */
cursor: pointer;
}
.burger div { /*the details of the burger menu bars design */
width: 25px;
height: 3px;
background-color: rgb(226, 226, 226);
margin: 5px;
transition: all 0.3s ease;
}
/* Main Area Content */
.about-area, .portfolio-area, .contact-area {
position: relative;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
flex-direction: row;
width: 100%;
height: 700px;
}
.text-part {
width: 65%;
height: 80%;
}
h1 {
font-size: 50px;
font-family: 'Audiowide', cursive;
}
p {
font-size: 24px;
line-height: 50px;
}
.about-area {
background: #fefefe;
}
.portfolio-area {
background: #0e9763;
color: #fff;
}
.contact-area {
background: #fefefe;
}
html {
scroll-behavior: smooth;
}
a:hover {
color: #000;
}
/* Quick fix breakpoint between max size and hamburger menu trigger */
#media screen and (max-width:1024px){
.nav-links {
width: 60%;
}
}
#media screen and (max-width:768px){
body {
overflow: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #0e9763;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%); /* Moves content off screen */
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
}
}
.nav-active {
transform: translateX(0%); /* When button is clicked the nav gets the transform */
}
/* Nav animation */
#keyframes navLinkFade{
from{
opacity: 0;
transform: translateX(50px);
}
to {
opacity: 1;
transform: translateX(0px);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px,6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px,-6px);
}
JS:
const navSlide = () => { //navSlide is = to an anonymous function
const burger = document.querySelector('.burger');
const nav = document.querySelector('.nav-links');
const navLinks = document.querySelectorAll('.nav-links li');
burger.addEventListener('click',() => { //on click run a function
//Toggle Nav
nav.classList.toggle('nav-active');
//Animate Links
navLinks.forEach((link, index) => {
if (link.style.animation){
link.style.animation = ''
} else {
link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.5}s`
}
});
//Burger Animation
burger.classList.toggle('toggle');
});
}
//Invoke function
navSlide();
Here is a link to the codepen:
https://codepen.io/justadirtgrub/pen/NWGJrde
You need to add z-index css property to class .nav-active to show up in front of main content
const navSlide = () => {
//navSlide is = to an anonymous function
const burger = document.querySelector(".burger");
const nav = document.querySelector(".nav-links");
const navLinks = document.querySelectorAll(".nav-links li");
burger.addEventListener("click", () => {
//on click run a function
//Toggle Nav
nav.classList.toggle("nav-active");
//Animate Links
navLinks.forEach((link, index) => {
if (link.style.animation) {
link.style.animation = "";
} else {
link.style.animation = `navLinkFade 0.5s ease forwards ${
index / 7 + 0.5
}s`;
}
});
//Burger Animation
burger.classList.toggle("toggle");
});
};
//Invoke function
navSlide();
* {
margin: 0px; /* Remove unwanted inherent sizing */
padding: 0px;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
nav {
display: flex; /*icons are next to each other */
justify-content: space-around; /* */
align-items: center; /* Center items vertically */
min-height: 8vh;
background-color: #0e9763;
font-family: "Poppins", sans-serif;
}
.logo {
color: rgb(226, 226, 226);
text-transform: uppercase;
letter-spacing: 5px;
font-size: 20px;
}
.nav-links {
display: flex; /* spreads out text */
justify-content: space-around; /* using flex adds more space around the items using width */
width: 30%;
}
.nav-links li {
list-style: none; /* Removes bullet points */
}
.nav-links a {
color: rgb(226, 226, 226);
text-decoration: none; /* Removes default link colors */
letter-spacing: 3px;
font-size: 14px;
}
.burger {
display: none; /* Hides the burger menu */
cursor: pointer;
}
.burger div {
/*the details of the burger menu bars design */
width: 25px;
height: 3px;
background-color: rgb(226, 226, 226);
margin: 5px;
transition: all 0.3s ease;
}
/* Main Area Content */
.about-area,
.portfolio-area,
.contact-area {
position: relative;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
flex-direction: row;
width: 100%;
height: 700px;
}
.text-part {
width: 65%;
height: 80%;
}
h1 {
font-size: 50px;
font-family: "Audiowide", cursive;
}
p {
font-size: 24px;
line-height: 50px;
}
.about-area {
background: #fefefe;
}
.portfolio-area {
background: #0e9763;
color: #fff;
}
.contact-area {
background: #fefefe;
}
html {
scroll-behavior: smooth;
}
a:hover {
color: #000;
}
/* Quick fix breakpoint between max size and hamburger menu trigger */
#media screen and (max-width: 1024px) {
.nav-links {
width: 60%;
}
}
#media screen and (max-width: 768px) {
body {
overflow: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #0e9763;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%); /* Moves content off screen */
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
}
}
.nav-active {
transform: translateX(0%);
z-index: 100; /* When button is clicked the nav gets the transform */
}
/* Nav animation */
#keyframes navLinkFade {
from {
opacity: 0;
transform: translateX(50px);
}
to {
opacity: 1;
transform: translateX(0px);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px, 6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px, -6px);
}
<!DOCTYPE html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght#400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Audiowide&display=swap" rel="stylesheet">
<title>Portfolio</title>
</head>
<body>
<nav>
<div class="logo">
<h4>Portfolio</h4>
</div>
<ul class="nav-links">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<main>
<div class="about-area" id="about">
<div class="text-part">
<h1>About</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore ullam,
exercitationem voluptate enim nobis id quas praesentium, fugit ipsum porro omnis!
Illo eum exercitationem eius, quam quae deserunt? Distinctio, voluptatibus. Lorem
ipsum dolor sit amet consectetur adipisicing elit. Repellendus non ab iure, debitis
minima at maxime nisi? Illum nesciunt nihil hic, provident dolorem molestias distinctio
optio officia suscipit nemo natus!</p>
</div>
</div>
<div class="portfolio-area" id="portfolio">
<div class="text-part">
<h1>Portfolio</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore ullam,
exercitationem voluptate enim nobis id quas praesentium, fugit ipsum porro omnis!
Illo eum exercitationem eius, quam quae deserunt? Distinctio, voluptatibus. Lorem
ipsum dolor sit amet consectetur adipisicing elit. Repellendus non ab iure, debitis
minima at maxime nisi? Illum nesciunt nihil hic, provident dolorem molestias distinctio
optio officia suscipit nemo natus!</p>
</div>
</div>
<div class="contact-area" id="contact">
<div class="text-part">
<h1>Contact</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore ullam,
exercitationem voluptate enim nobis id quas praesentium, fugit ipsum porro omnis!
Illo eum exercitationem eius, quam quae deserunt? Distinctio, voluptatibus. Lorem
ipsum dolor sit amet consectetur adipisicing elit. Repellendus non ab iure, debitis
minima at maxime nisi? Illum nesciunt nihil hic, provident dolorem molestias distinctio
optio officia suscipit nemo natus!</p>
</div>
</div>
</main>
</body>
</html>
I've got two different pricing cards:
<div class="card card1" id="open">
<span class=title>Basic</span>
<h1>$99 USD</h1>
<h4>Lorem ipsum dolor sit amet.</h4>
<h2>YOU GET:</h2>
<ul>
<li>Access to AM</li>
<li>Unlimited Households</li>
<li>White-Labeling</li>
</ul>
</div>
<div class="card card2" id="open2">
<span class=title>Pro</span>
<h1>$129 USD</h1>
<h4>Lorem ipsum dolor sit amet.</h4>
<h2>YOU GET:</h2>
<ul>
<li>Cash-Flow Reporting</li>
<li>Beneficiary Visualization</li>
<li>Unlimited TMs</li>
</ul>
</div>
When clicked, each should bring up a different modal:
<div class="modal-container" id="modal_container">
<div class="modal">
<h1>Modal goes here</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Atque consectetur repudiandae quia deleniti nulla, suscipit tempora magnam blanditiis ex culpa mollitia quisquam quod? Dolores, sunt dicta adipisci rem consequuntur fugit repudiandae quia deleniti nulla.</p>
<button id="close">Close me</button>
</div>
<div class="modal-container" id="modal_container2">
<div class="modal">
<h1>Modal 2 goes here</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Atque consectetur repudiandae quia deleniti nulla, suscipit tempora magnam blanditiis ex culpa mollitia quisquam quod? Dolores, sunt dicta adipisci rem consequuntur fugit repudiandae quia deleniti nulla.</p>
<button id="close2">Close me</button>
</div>
All of the ID's are unique. With this JS I am able to bring up the first modal but not the second:
const open = document.getElementById('open');
const modal_container = document.getElementById('modal_container');
const close = document.getElementById('close');
open.addEventListener('click', () => {
modal_container.classList.add('show');
});
close.addEventListener('click', () => {
modal_container.classList.remove('show');
});
I added unique IDs for the second card and modal, but when I pull them into the JS by adding this:
const open2 = document.getElementById('open2');
const modal_container2 = document.getElementById('modal_container2');
const close2 = document.getElementById('close2');
open2.addEventListener('click', () => {
modal_container2.classList.add('show');
});
close2.addEventListener('click', () => {
modal_container2.classList.remove('show');
});
I am not getting the same effect.
Here is the relevant CSS:Added relevant CSS
.modal-container {
background-color: rgba(0,0,0,0.3);
position: fixed;
top:0;
left:0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
pointer-events: none;
}
.modal-container.show {
opacity: 1;
pointer-events: auto;
}
there was some error on your codepen, double body open and close tag, the second modal was inside the first one's container, Ids were duplicated and on the JS side the listeners for the second modal were missing, try this:
const open = document.getElementById('open');
const modal_container = document.getElementById('modal_container');
const close = document.getElementById('close');
const open2 = document.getElementById('open2');
const modal_container2 = document.getElementById('modal_container2');
const close2 = document.getElementById('close2');
open.addEventListener('click', () => {
modal_container.classList.add('show');
});
close.addEventListener('click', () => {
modal_container.classList.remove('show');
});
open2.addEventListener('click', () => {
modal_container2.classList.add('show');
});
close2.addEventListener('click', () => {
modal_container2.classList.remove('show');
});
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #f4efed;
font-family: 'Muli', sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
cursor: crosshair;
}
.card {
background-color: #fff;
border-radius: 10px;
padding: 60px 30px;
text-align: center;
max-width: 450px;
min-width: 275px;
margin: 1em;
transition: .2s ease all;
}
.card:hover {
transform: translateY(-20px);
box-shadow: 0 10px 20px rgba(0,0,0,.3);
cursor: pointer;
}
.card1 {
background-image: linear-gradient(to bottom right, #41464d, #2d3137);
color: white;
}
.card2 {
background-image: linear-gradient(to bottom right, #dbb898, #b98351);
color: white;
}
.card .title {
font-size: .8em;
}
.card1 .title{
font-weight: bold;
background-color: #444950;
border-radius: 10px;
padding: 12px 10px;
}
.card2 .title{
font-weight: bold;
background-color: white;
border-radius: 10px;
padding: 12px 10px;
color: #2d3137;
}
h1 {
margin: 30px 0 30px 0;
}
h4 {
font-weight: 100;
font-size: .75em;
}
h2 {
margin: 25px;
font-size: .8em;
}
ul {
font-size: .75em;
line-height: 1.75em;
list-style: none;
}
.modal-container {
background-color: rgba(0,0,0,0.3);
position: fixed;
top:0;
left:0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
pointer-events: none;
}
.modal-container.show {
opacity: 1;
pointer-events: auto;
}
.modal {
background-color: white;
border-radius: 10px;
width: 800px;
max-width: 100%;
padding: 30px 50px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
text-align: center;
}
.modal h1 {
margin: .5em;
}
.modal p {
font-size: 14px;
opacity: 0.7;
}
.modal-container button {
background-color: #444950;
color: white;
border: 0;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
font-size: 14px;
padding: 10px 25px;
margin: 15px 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Pricing Cards</title>
</head>
<body>
<div class="card card1" id="open">
<span class=title>Basic</span>
<h1>$99 USD</h1>
<h4>Lorem ipsum dolor sit amet.</h4>
<h2>YOU GET:</h2>
<ul>
<li>Access to Asset-Map</li>
<li>Unlimited Households</li>
<li>White-Labeling</li>
</ul>
</div>
<div class="card card2" id="open2">
<span class=title>Pro</span>
<h1>$129 USD</h1>
<h4>Lorem ipsum dolor sit amet.</h4>
<h2>YOU GET:</h2>
<ul>
<li>Cash-Flow Reporting</li>
<li>Beneficiary Visualization</li>
<li>Unlimited Target-Maps</li>
</ul>
</div>
<div class="modal-container" id="modal_container">
<div class="modal">
<h1>Modal goes here</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Atque consectetur repudiandae quia deleniti nulla, suscipit tempora magnam blanditiis ex culpa mollitia quisquam quod? Dolores, sunt dicta adipisci rem consequuntur fugit repudiandae quia deleniti nulla.</p>
<button id="close">Close me</button>
</div>
</div>
<div class="modal-container" id="modal_container2">
<div class="modal">
<h1>Modal 2 goes here</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Atque consectetur repudiandae quia deleniti nulla, suscipit tempora magnam blanditiis ex culpa mollitia quisquam quod? Dolores, sunt dicta adipisci rem consequuntur fugit repudiandae quia deleniti nulla.</p>
<button id="close2">Close me</button>
</div>
</div>
</body>
</html>