how to make overlay like youtube - html

I am having a simple web page with a navigation bar. When is toggle my navigation bar I want the rest of area in my page to be overlay live Youtube(A sample image is attached below). But after trying 100 time the result is attached below(A sample image is attached below).The problem is it's not overlaying the element which has defined color attribute.
My css code to achieve overlay:
.overlay{
width: 100%;
position: fixed !fixed;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5) !important;
z-index:0;
cursor: pointer;
}

You need to add an higher z-index and a grey background overlay.
$(".btn").click(function () {
$(".overlay").show();
});
.overlay {
background-color: rgba(128, 128, 128, 0.40);
position: fixed;
width: 100%;
height: 100%;
z-index: 99999;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="overlay">
</div>
<div class="content">
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea velit provident sint aliquid eos omnis aperiam officia architecto error incidunt nemo obcaecati adipisci doloremque dicta neque placeat natus beatae cupiditate minima ipsam quaerat explicabo non reiciendis qui sit.</div>
<input type="text">
<button class="btn btn-success">Submit</button>
</div>

The below example just plays with visibility and opacity of overlay wrapper.
$("#click").on("click", function(){
$(".orientation-check-wrapper").toggleClass('show-overlay');
});
.orientation-check-wrapper {
height: 100vh;
position: fixed;
width: 100%;
background: rgba(0,0,0,0.7);
z-index: 99;
top: 0;
opacity:0;
transition: .4s all;
opacity: 0;
visibility: hidden;
}
.orientation-check-text {
top: 100px;
right: 0;
left: 0;
bottom:0;
position: absolute;
margin: 0 auto;
width: 390px;
height: 18px;
background: #fff;
padding: 12px;
border-radius: 8px;
box-shadow: 0 0 10px #3493c1;
font-size: 13px;
color: #000;
text-align:center;
font-family: sans-serif;
}
.show-overlay{
opacity: 1;
visibility: visible;
}
#click{
z-index: 999;
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="click" id="click" />
<div class="orientation-check-wrapper">
<div class="orientation-check-text">This application is best supported on resolutions above 800px</div>
</div>

I would like to add the possibility of usage of css filters in this case, as a side technique.
They are now widely available into many browsers, we can with them do pretty nice stuffs, without adding an overlay.
Here on this simple example, the blur filter is used. The filter is added by javascript alone. This way, there is no need to modify the html or the css. It can be useful.
I took the html from the top answer, which is the good regular way to do this.
document.getElementsByClassName("content")[0].setAttribute("onclick","this.style.filter='blur(2px)'")
<div class="overlay">Some text
</div>
<div class="content">
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea velit provident sint aliquid eos omnis aperiam officia architecto error incidunt nemo obcaecati adipisci doloremque dicta neque placeat natus beatae cupiditate minima ipsam quaerat explicabo non reiciendis qui sit.</div>
<input type="text">
<button class="btn btn-success">Submit</button>
</div>
The list of css filters:
filter: blur(5px);
filter: brightness(0.4);
filter: contrast(200%);
filter: drop-shadow(16px 16px 20px blue);
filter: grayscale(50%);
filter: hue-rotate(90deg);
filter: invert(75%);
filter: opacity(25%);
filter: saturate(30%);
filter: sepia(60%);
Further infos: https://developer.mozilla.org/en-US/docs/Web/CSS/filter

I have updated a post with some code which may probably very helpful to simulate YouTube like overlay.
$(document).ready(function() {
$(".overlay, .close").hide();
$("#btnClickme").bind("click", function() {
$(".overlay, .close").fadeIn();
$(".wrapper-btn").fadeOut();
});
$(".btnClose").bind("click", function() {
$(".overlay, .close").fadeOut();
$(".close").unbind("click");
$(".wrapper-btn").fadeIn();
});
});
* {
font-family: 'arial';
font-size: 12px;
}
.close a {
color: #ffffff;
right: 0px;
top: 0px;
font-size: 10px;
position: relative;
z-index: 1;
display: block;
text-decoration:none;
font-size:13px;
}
.close {
position: absolute;
}
.overlay-wrapper {
float: left;
width: 200px;
height: 200px;
position: absolute;
padding: 10px;
}
.wrapper-row {
float: left;
}
.overlay {
float: left;
position: relative;
background-color: #000000;
width: 200px;
height: 200px;
margin: 10px;
opacity: 0.5;
filter: alpha(opacity=50);
/* For IE 8 & 9 (more valid) */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='overlay-wrapper'>
<div class="wrapper-row">
<img src="http://via.placeholder.com/200x200" />
</div>
<div class="wrapper-row wrapper-btn">
<input type="button" id="btnClickme" name="btnClickme" value="click here" />
</div>
<div class="close">
<a href="javascript:void(0);" class="btnClose">
(close)
</a>
</div>
</div>
<div class="overlay"></div>

Assuming that you have a structure like this
<aside class="sidebar">
<!-- Stuff-->
</aside>
<section class="content">
<!-- More stuff -->
</section>
and an open class is added to sidebar when the bar is opened, you can use the adjacent sibling combinator to get the overlay
.sidebar.open + .content:before {
width: 100%;
position: fixed !fixed;
display: block;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5) !important;
z-index:0;
cursor: pointer;
}

Related

How to make pure CSS parallax code work with complex site?

I'm trying to apply a complex parallax effect to my site. The background image should be behind the overall content and should move slower than the main content. I tried many approaches to this functionality but neither work.
So, according to what I understand, I need to first create a parallax wrapper.
.parallax-wrapper {
height: 100vh;
overflow-y: auto;
overflow-x: hidden;
perspective: 10px;
}
This wrapper has a perspective, it hides the x overflow and sets the height of the overall content. It will be set just after the body tag.
Then, I have a section that should have a background that is a direct child of parallax-wrapper:
.latest_news_section {
display: flex;
flex-direction: column;
height: 390px;
justify-content: center;
align-items: center;
position: relative;
overflow: hidden;
}
This section just formats the content and gives shape to it.
Then, I apply the shift of the Z plane to make sure the content is behind and it has a slower scroll:
.latest_news_section::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
transform-origin: center;
background-image: url("../img/top-back.jpeg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
transform: translateZ(-5px) scale(2);
}
However, the parallax starts working only when I disable overflow: hidden; from the section. And I don't know why. However, my colleague tested the same code and it worked.
Please check my version below:
HTML:
.parallax-wrapper {
height: 100vh;
overflow-y: auto;
overflow-x: hidden;
perspective: 10px;
transform-style: preserve-3d;
}
.latest_news_section {
display: flex;
flex-direction: column;
height: 390px;
justify-content: center;
align-items: center;
position: relative;
overflow: hidden;
transform-style: preserve-3d;
}
.latest_news_section::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
transform-origin: center;
background-image: url("https://www.freecodecamp.org/news/content/images/size/w2000/2021/06/w-qjCHPZbeXCQ-unsplash.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
transition: 1s;
transform: translateZ(-5px) scale(2);
transform-style: inherit;
}
.latest_news_section_header {
font-family: AdobeInvisFont, OpenSans, Courier;
font-size: 27px;
color: rgba(255, 255, 255, 255);
text-align: center;
margin-bottom: 55px;
}
button {
border: none;
font-family: AdobeInvisFont, Courier, OpenSans-Semibold;
font-size: 18px;
color: rgba(255, 255, 255, 255);
text-align: center;
height: 55px;
width: 170px;
border-radius: 5px;
cursor: pointer;
}
.green {
background-color: #89ca62;
margin-right: 20px;
}
.blue {
background-color: #14b9d5;
}
.some-content-to-fill {
height: 1000px;
z-index: 2;
}
<!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" />
<link rel="stylesheet" href="./css/style.css" />
<title>Document</title>
</head>
<body>
<div class="parallax-wrapper">
<div class="latest_news_section">
<h1 class=".latest_news_section_header">
THE LATEST NEWS ON DESIGN & ARCHITECTURE
</h1>
<div class="heading-buttons container">
<button class="green">Subscribe Now</button>
<button class="blue">Best Articles</button>
</div>
</div>
<p class="some-content-to-fill">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur nisi temporibus debitis deleniti velit suscipit est aliquid voluptates voluptatem, consequatur ratione, minima autem ex inventore reiciendis commodi, harum repellendus nam! Cupiditate,
amet expedita! Est beatae ut illum voluptatum quod nesciunt, similique minus labore consequuntur, nostrum ad ducimus libero eveniet aperiam recusandae, dignissimos totam quas ipsum explicabo! Dolore cupiditate expedita quisquam quis doloribus dolorum
laborum ad excepturi odit cumque praesentium, quasi neque quia totam ea officia quibusdam nostrum, libero, eaque atque!
</p>
</div>
</body>
</html>
Thank you. I am trying to get this for a too long time and I don't have a single clue why it doesn't work without overflow: hidden disabled. Thank you.
Scrolling is disabled when using overflow: hidden;
You need to do:
.parallax-wrapper::-webkit-scrollbar {
display: none;
}

Why a particular section is not visible after hover? [duplicate]

This question already has answers here:
How to affect other elements when one element is hovered
(9 answers)
Closed 1 year ago.
I made a design where I want to show text section after hover on info icon. But It is not working after hover on info icon. Please help me. I could not able to find my problem in this code. But most probably I think the problem is in the hover section. But I could not able to fix it. Please help me to fix this problem.
*{
margin: 0;
padding: 0;
}
.hover1 {
height: 500px;
width: 700px;
background: #00a8ff;
margin: 10px auto;
position: relative;
}
.icon-info{
position: absolute;
top: 150px;
left: 500px;
background: white;
padding: 5px 11px;
border-radius: 50%;
}
.text{
height: 200px;
width: 360px;
background: white;
position: relative;
top: 150px;
left: 130px;
padding: 20px;
border-radius: 13px;
display: inline-block;
visibility: hidden;
opacity: 0;
}
.text h3{
font-size: 30px;
margin: 20px 5px;
}
.text p{
font-size: 18px;
}
/* hover */
.icon-info:hover .text{
visibility: visible;
opacity: 1;
transition: .5s;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hover effect</title>
<link rel="stylesheet" href="./hover.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css">
</head>
<body>
<div class="hover1">
<i class="fas fa-info icon-info"></i>
<div class="text">
<h3>This is Tittle</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Consectetur dolores quis enim facilis doloribus iste hic dolore cumque rerum, in earum omnis obcaecati blanditiis nostrum ab. Tempora officia voluptatibus ex!</p>
</div>
</div>
</body>
</html>
Just add a + in hover style as follow:
*{
margin: 0;
padding: 0;
}
.hover1 {
height: 500px;
width: 700px;
background: #00a8ff;
margin: 10px auto;
position: relative;
}
.icon-info{
position: absolute;
top: 150px;
left: 500px;
background: white;
padding: 5px 11px;
border-radius: 50%;
z-index:1;
}
.text{
height: 200px;
width: 360px;
background: white;
position: relative;
top: 150px;
left: 130px;
padding: 20px;
border-radius: 13px;
display: inline-block;
visibility: hidden;
opacity: 0;
}
.text h3{
font-size: 30px;
margin: 20px 5px;
}
.text p{
font-size: 18px;
}
/* hover */
.icon-info:hover + .text{
visibility: visible;
opacity: 1;
transition: .5s;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hover effect</title>
<link rel="stylesheet" href="./hover.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css">
</head>
<body>
<div class="hover1">
<i class="fas fa-info icon-info"></i>
<div class="text">
<h3>This is Tittle</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Consectetur dolores quis enim facilis doloribus iste hic dolore cumque rerum, in earum omnis obcaecati blanditiis nostrum ab. Tempora officia voluptatibus ex!</p>
</div>
</div>
</body>
</html>

How to vertically align a CSS arrow that unfolds an accordion?

I used CSS instead of Fontawesome to generate the arrows. I think it makes more sense than loading a separate icon library. However I have trouble positioning those CSS arrow to the center, when it points upwards it looks great, I think it's in the center or at least near to the center, but when it points downwards it looks like the arrow moved towards the bottom.
I would be grateful for any suggestion
"use strict";
const panelHeader = document.querySelectorAll(".panel-header");
panelHeader.forEach(item => {
item.addEventListener("click", event => {
event.preventDefault();
item.parentElement.classList.toggle("open");
const panel = item.nextElementSibling;
panel.style.height = panel.style.height ? null : panel.scrollHeight + "px";
});
});
:root {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
margin: 0;
padding: 0;
}
.accordion {
max-width: 1200px;
margin: 0 auto;
}
.accordion-container {
padding: 15px;
}
h2 {
color: #444;
font-size: 1.75rem;
position: relative;
padding: 0 0 25px 0;
margin: 15px 0 20px 0;
}
h2::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 50px;
height: 5px;
background: #f79c31;
}
.panel-container > .panel + .panel {
margin-top: 15px;
}
.panel {
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: 0.1875em;
}
.panel-header {
background: #564990;
border-color: #564990;
border-top-left-radius: 0.1875em;
border-top-right-radius: 0.1875em;
position: relative;
transition: background .25s linear;
}
.panel-header > h4 {
margin: 0;
}
.panel-header > h4 > a {
position: relative;
display: block;
color: #fff;
font-size: 1.125rem;
text-decoration: none;
padding: 15px 50px 15px 15px;
}
.panel-header:hover {
background: #443776;
}
.panel-body {
height: 0;
overflow: hidden;
transition: 0.3s height 0.2s;
}
.panel-body-container {
padding: 15px;
}
.arrow {
position: absolute;
top: 22px;
right: 10px;
font-size: 1.7rem;
border: solid #fff;
border-width: 0 4px 4px 0;
display: inline-block;
padding: 5px;
opacity: .5;
transform: rotate(-135deg);
transition: transform 0.15s linear;
}
.arrow-up {
}
.panel.open .arrow {
transform: rotate(-315deg);
transform-origin: center center;
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="accordion-faq.css">
<title>Accordion FAQ</title>
</head>
<body>
<section class="accordion">
<div class="accordion-container">
<header>
<h2>FAQs</h2>
</header>
<div class="panel-container">
<div class="panel">
<div class="panel-header">
<h4>
First question?
</h4>
<div class="arrow"><div class="arrow-up"></div></div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Accusantium animi blanditiis corporis dicta, dolor dolores
enim facilis fuga itaque iure iusto molestiae mollitia
natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div> <!-- .panel -->
<div class="panel">
<div class="panel-header">
<h4>
Second question?
</h4>
<div class="arrow arrow-up"></div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Accusantium animi blanditiis corporis dicta, dolor dolores
enim facilis fuga itaque iure iusto molestiae mollitia
natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div> <!-- .panel -->
</div> <!-- .panel-container -->
</div> <!-- .accordion-container -->
</section>
<script src="accordion-faq.js"></script>
</body>
</html>
With the current setup you have, the best solution would be to either -
Change the top value in the animation class. You will also want to change the animate value to all so that it also animates the change in the top value without jumping.
.arrow {
...
transition: all 0.15s linear;
}
.panel.open .arrow {
transform: rotate(-315deg);
transform-origin: center center;
top: 18px;
}
You could also change the transform-origin to 100% center, however this causes the animation to spin in a weird way.
You could also look into using built-in HTML arrows and rotating them if you do not want to load a font library or an SVG icon. It may behave more how you are expecting - https://www.toptal.com/designers/htmlarrows/
First of all you can avoid using position: absolute for this type of problem where display: flex do the trick:
const panelHeader = document.querySelectorAll(".panel-header");
panelHeader.forEach(item => {
item.addEventListener("click", event => {
event.preventDefault();
item.parentElement.classList.toggle("open");
const panel = item.nextElementSibling;
panel.style.height = panel.style.height ? null : panel.scrollHeight + "px";
});
});
:root {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
margin: 0;
padding: 0;
}
.accordion {
max-width: 1200px;
margin: 0 auto;
}
.accordion-container {
padding: 15px;
}
h2 {
color: #444;
font-size: 1.75rem;
position: relative;
padding: 0 0 25px 0;
margin: 15px 0 20px 0;
}
h2::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 50px;
height: 5px;
background: #f79c31;
}
.panel-container>.panel+.panel {
margin-top: 15px;
}
.panel {
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: 0.1875em;
}
.panel-header {
display: flex; /* <- Use flexbox */
justify-content: space-between;
align-items: center;
background: #564990;
border-color: #564990;
border-top-left-radius: 0.1875em;
border-top-right-radius: 0.1875em;
position: relative;
transition: background .25s linear;
}
.panel-header>h4 {
margin: 0;
}
.panel-header>h4>a {
position: relative;
display: block;
color: #fff;
font-size: 1.125rem;
text-decoration: none;
padding: 15px 50px 15px 15px;
}
.panel-header:hover {
background: #443776;
}
.panel-body {
height: 0;
overflow: hidden;
transition: 0.3s height 0.2s;
}
.panel-body-container {
padding: 15px;
}
.arrow {
/* Don't need position absolute anymore */
margin: 10px;
font-size: 1.7rem;
border: solid #fff;
border-width: 0 4px 4px 0;
display: inline-block;
padding: 5px;
opacity: .5;
transform: rotate(-135deg);
transition: transform 0.15s linear;
}
.arrow-up {}
.panel.open .arrow {
margin-top: -5px; /* <- Remove arrow heigth (5px) to stay at the same level */
transform: rotate(-315deg);
transform-origin: center center;
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="accordion-faq.css">
<title>Accordion FAQ</title>
</head>
<body>
<section class="accordion">
<div class="accordion-container">
<header>
<h2>FAQs</h2>
</header>
<div class="panel-container">
<div class="panel">
<div class="panel-header">
<h4>
First question?
</h4>
<div class="arrow">
<div class="arrow-up"></div>
</div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium animi blanditiis corporis dicta, dolor dolores enim facilis fuga itaque iure iusto molestiae mollitia natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div>
<!-- .panel -->
<div class="panel">
<div class="panel-header">
<h4>
Second question?
</h4>
<div class="arrow arrow-up"></div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium animi blanditiis corporis dicta, dolor dolores enim facilis fuga itaque iure iusto molestiae mollitia natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div>
<!-- .panel -->
</div>
<!-- .panel-container -->
</div>
<!-- .accordion-container -->
</section>
<script src="accordion-faq.js"></script>
</body>
</html>
Try changing your top property of the .arrow class to top: 50% so that it isn't hardcoded.
Then, add to your transform property translate(0, -50%).
Use the top propriety in CSS.
This will set the top position of the arrow when rotating it.
Here is your code:
"use strict";
const panelHeader = document.querySelectorAll(".panel-header");
panelHeader.forEach(item => {
item.addEventListener("click", event => {
event.preventDefault();
item.parentElement.classList.toggle("open");
const panel = item.nextElementSibling;
panel.style.height = panel.style.height ? null : panel.scrollHeight + "px";
});
});
:root {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
margin: 0;
padding: 0;
}
.accordion {
max-width: 1200px;
margin: 0 auto;
}
.accordion-container {
padding: 15px;
}
h2 {
color: #444;
font-size: 1.75rem;
position: relative;
padding: 0 0 25px 0;
margin: 15px 0 20px 0;
}
h2::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 50px;
height: 5px;
background: #f79c31;
}
.panel-container > .panel + .panel {
margin-top: 15px;
}
.panel {
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: 0.1875em;
}
.panel-header {
background: #564990;
border-color: #564990;
border-top-left-radius: 0.1875em;
border-top-right-radius: 0.1875em;
position: relative;
transition: background .25s linear;
}
.panel-header > h4 {
margin: 0;
}
.panel-header > h4 > a {
position: relative;
display: block;
color: #fff;
font-size: 1.125rem;
text-decoration: none;
padding: 15px 50px 15px 15px;
}
.panel-header:hover {
background: #443776;
}
.panel-body {
height: 0;
overflow: hidden;
transition: 0.3s height 0.2s;
}
.panel-body-container {
padding: 15px;
}
.arrow {
position: absolute;
top: 22px;
right: 10px;
font-size: 1.7rem;
border: solid #fff;
border-width: 0 4px 4px 0;
display: inline-block;
padding: 5px;
opacity: .5;
transform: rotate(-135deg);
transition: transform 0.15s linear;
}
.arrow-up {
}
.panel.open .arrow {
transform: rotate(-315deg);
transform-origin: center center;
top: 15px; //Do it!
}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="accordion-faq.css">
<title>Accordion FAQ</title>
</head>
<body>
<section class="accordion">
<div class="accordion-container">
<header>
<h2>FAQs</h2>
</header>
<div class="panel-container">
<div class="panel">
<div class="panel-header">
<h4>
First question?
</h4>
<div class="arrow"><div class="arrow-up"></div></div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Accusantium animi blanditiis corporis dicta, dolor dolores
enim facilis fuga itaque iure iusto molestiae mollitia
natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div> <!-- .panel -->
<div class="panel">
<div class="panel-header">
<h4>
Second question?
</h4>
<div class="arrow arrow-up"></div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Accusantium animi blanditiis corporis dicta, dolor dolores
enim facilis fuga itaque iure iusto molestiae mollitia
natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div> <!-- .panel -->
</div> <!-- .panel-container -->
</div> <!-- .accordion-container -->
</section>
<script src="accordion-faq.js"></script>
</body>
A living demo: https://codepen.io/marchmello/pen/mdedGra
You need to use the position: absolute and top position on your .panel.open .arrow css like this :
"use strict";
const panelHeader = document.querySelectorAll(".panel-header");
panelHeader.forEach(item => {
item.addEventListener("click", event => {
event.preventDefault();
item.parentElement.classList.toggle("open");
const panel = item.nextElementSibling;
panel.style.height = panel.style.height ? null : panel.scrollHeight + "px";
});
});
:root {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
margin: 0;
padding: 0;
}
.accordion {
max-width: 1200px;
margin: 0 auto;
}
.accordion-container {
padding: 15px;
}
h2 {
color: #444;
font-size: 1.75rem;
position: relative;
padding: 0 0 25px 0;
margin: 15px 0 20px 0;
}
h2::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 50px;
height: 5px;
background: #f79c31;
}
.panel-container > .panel + .panel {
margin-top: 15px;
}
.panel {
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: 0.1875em;
}
.panel-header {
background: #564990;
border-color: #564990;
border-top-left-radius: 0.1875em;
border-top-right-radius: 0.1875em;
position: relative;
transition: background .25s linear;
}
.panel-header > h4 {
margin: 0;
}
.panel-header > h4 > a {
position: relative;
display: block;
color: #fff;
font-size: 1.125rem;
text-decoration: none;
padding: 15px 50px 15px 15px;
}
.panel-header:hover {
background: #443776;
}
.panel-body {
height: 0;
overflow: hidden;
transition: 0.3s height 0.2s;
}
.panel-body-container {
padding: 15px;
}
.arrow {
position: absolute;
top: 22px;
right: 10px;
font-size: 1.7rem;
border: solid #fff;
border-width: 0 4px 4px 0;
display: inline-block;
padding: 5px;
opacity: .5;
transform: rotate(-135deg);
transition: transform 0.15s linear;
}
.arrow-up {
}
.panel.open .arrow {
transform: rotate(-315deg);
transform-origin: center center;
position: absolute;
top: 30%;
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="accordion-faq.css">
<title>Accordion FAQ</title>
</head>
<body>
<section class="accordion">
<div class="accordion-container">
<header>
<h2>FAQs</h2>
</header>
<div class="panel-container">
<div class="panel">
<div class="panel-header">
<h4>
First question?
</h4>
<div class="arrow"><div class="arrow-up"></div></div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Accusantium animi blanditiis corporis dicta, dolor dolores
enim facilis fuga itaque iure iusto molestiae mollitia
natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div> <!-- .panel -->
<div class="panel">
<div class="panel-header">
<h4>
Second question?
</h4>
<div class="arrow arrow-up"></div>
</div>
<div class="panel-body">
<div class="panel-body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Accusantium animi blanditiis corporis dicta, dolor dolores
enim facilis fuga itaque iure iusto molestiae mollitia
natus nisi pariatur praesentium quo rerum vel.
</p>
</div>
</div>
</div> <!-- .panel -->
</div> <!-- .panel-container -->
</div> <!-- .accordion-container -->
</section>
<script src="accordion-faq.js"></script>
</body>
</html>

How to create two triangles with overlaying?

I need to create the following shape on the image. Where is the photo there will variable content as a slider. What I tried so far is create it with border-width, but the problem is that I'm not able to put the small triangle under photo because of the bigger triangle.
What I've done you can find here on live demo. Maybe I have to use other approaches? Does someone how to solve it?
.header {
float: left;
width: 100%;
background: red;
padding-top: 50px;
padding-bottom: 200px; }
.content {
float: left;
width: 100%;
background: blue;
padding: 50px 0; }
.shape {
position: relative;
float: left;
width: 100%; }
.shape--1:before {
border-top-color: yellow;
border-right-color: transparent;
border-left-color: transparent;
border-bottom-color: transparent;
border-style: solid;
border-width: 160px 330px 0 0;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 30; }
.shape--2:before {
background: transparent;
border-bottom-color: transparent;
border-left-color: blue;
border-right-color: transparent;
border-style: solid;
border-top-color: transparent;
border-width: 130px 0 0 100vw;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 20; }
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod? - There will be slider with different background, same color should be also in the shape.
</div>
<div class="shape">
<div class="shape--1"></div>
<div class="shape--2"></div>
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
What I did is first create the element that holds the photo, then I created a rectangular shape in the body background color, rotated it and made it overflown. Then inside of it I placed another rectangular block that I rotated in the opposite way of the original triangle:
HTML:
<div class="photo"></div>
<div class="triangle"></div>
CSS:
body {
background: #fff;
overflow:hidden;
padding: 0;
margin: 0;
}
.photo {
width: 100%;
height: 200px;
background: red;
}
.triangle {
position: absolute;
background: #fff;
left: -100px;
right: -100px;
height: 300px;
transform: rotate(5deg);
transform-origin: 100% 100%;
overflow: hidden;
}
.triangle:after {
content: "";
display: block;
width: 400px;
height: 200px;
position: absolute;
background: orange;
left: 0;
top: -180px;
transform: rotate(-20deg)
}
And here is a working fiddle:
https://jsfiddle.net/62o7wqom/2/
Edit: Added overflow:hidden to the body tag to avoid having a horizontal scrollbar because of the absolutely positioned element...overflowing the body.
The easiest way of doing it would be setting a background-color on a containing div and use clip-path on the actual image. That would give you the effect you're looking for.
If you don't want the triangle to move with the slider you can either create another wrapper div or just create a pseudo after-element and position it on top of the image.
you may use some Pythagore stuff to calculate more precisely angles and sizes, but the idea is here.
.shape {
width: 100%;
height: 5em;
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 0, 25% 0, 0 100%);
}
.header {
text-align: center;
font-variant: small-caps;
font-size: 2em;
}
<div class=header>
<div class=shape style="background-image: url('http://backgrounds.mysitemyway.com/wp-content/uploads/2009/03/bamboo-001126-asparagus-fern-green.jpg')"></div>
awesome header
</div>
<div class=content>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
One posibility using an inner element to contain the image.
This element is rotated, and inside a pseudo there is the image, counter-rotated.
.test {
font-size: 30px;
width: 400px;
height: 200px;
border: solid blue 1px;
background-size: 200px 200px;
background-repeat: no-repeat;
position: relative;
}
.inner {
position: absolute;
width: 140%;
height: 140%;
bottom: 0px;
right: 0px;
z-index: -1;
transform: rotate(26.4deg);
transform-origin: right bottom;
overflow: hidden;
}
.inner:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-image: url(http://lorempixel.com/800/400);
background-size: cover;
transform: rotate(-26.4deg);
transform-origin: right bottom;
}
.triangle {
position: absolute;
width: 200px;
height: 200px;
top: 0px;
left: 0px;
background-image: linear-gradient(to right bottom, red 50%, transparent 50%);
z-index: -2;
}
<div class="test">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..
<div class="inner"></div>
<div class="triangle"></div>
</div>
Here I made a jsfiddle take a look just with your answer I made some css changes. Hope it helps.
.shape-1{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 160px solid transparent;
border-left: 0vw solid green;
border-right: 97vw solid green;
position:relative;
top: -130px;
}
.shape-2{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 130px solid transparent;
border-left: 42vw solid yellow;
border-right: 0vw solid yellow;
position:relative;
top:0px;
}
.header{
position: absolute;
z-index: 1;
}
<div class="shape">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam
accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod?
</div>
<div class="shape-2"></div>
<div class="shape-1"></div>
</div>
I noticed that you have already accepted an answer, but I figured I would still post some code that could help. This would require some fine tuning given what else you may have going on in your project, but it could get the job done.
.LeftT {
position: absolute;
top: 0rem;
left: 0rem;
border-left: 30rem solid #02A698;
border-right: 6rem solid transparent;
border-bottom: 8rem solid transparent;
border-top: 0rem solid transparent;
}
.RightT {
position: absolute;
top: 0rem;
left: -5rem;
border-top: 0rem solid #004F49;
border-left: 0rem solid transparent;
border-bottom: 8rem solid transparent;
border-right: 45rem solid #004F49;
}
p{
position: absolute;
top: 0rem;
left: 15rem;
z-index: 1;
}
<div class="LeftT"></div>
<div class="RightT"></div>
<p style="color:white;text-align:right;padding-right:1rem;font-size:1.1rem;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in turpis velit.
</p>

Links aren't clickable after using parallax scrolling

I've been making this website for school and I thought i'd figure out how parallax scrolling works. So i've started with the simpelest tutorial to be precise this one. After doing this I placed my navigation bar in. I remember this worked fine at the time but after working allot on the responsiveness I didn't check back and now I can't click on the links anymore.
This is my html:
<div id="group2" class="parallax_group">
<!-- <div class="parallax_layer parallax_layer-back">
background
</div> -->
<div class="parallax_layer parallax_layer-base">
<div id="nav" class="nav">
<ul>
<li><a class="active" href="#">Home</a></li>
<li>Over ons</li>
<li>Wat leveren wij?</li>
<li>Contact</li>
<li>Demo</li>
</ul>
</div>
<div class="section group">
<div class="col span_1_of_3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam id nam, necessitatibus at odit nobis vitae, dolor sequi sunt doloremque minima, debitis. Sed debitis possimus esse soluta mollitia est culpa.</p>
</div>
<div id="middle" class="col span_1_of_3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui autem impedit, a, error accusantium soluta molestias quidem quo totam beatae eligendi sint, modi voluptatem nemo fugiat recusandae ullam consequatur nihil?</p>
</div>
<div class="col span_1_of_3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Provident voluptatibus, quaerat nostrum ullam distinctio praesentium! Nemo eveniet provident id, tenetur cumque natus, quas porro possimus maiores, minus amet laboriosam ea?</p>
</div>
</div>
</div>
</div>
And this is my css:
* {
padding: 0;
margin: 0;
}
body {
text-align: center;
}
h1{
display: inline-block;
font-family: 'Raleway', sans-serif;
color: white;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
p{
display: inline-block;
font-family: 'Raleway', sans-serif;
color: black;
}
header {
z-index: 5;
line-height: 100vh;
}
header .parallax_layer-back {
background: url(sample.jpg);
background-size: contain;
background-repeat: no-repeat;
}
#group2 {
z-index: 3;
}
#group2 .parallax_layer-base {
background-color: #dbdbdb;
}
.parallax {
perspective: 300px;
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
}
.parallax_layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.parallax_layer-base {
transform: translateZ(0px);
z-index: 4;
}
.parallax_layer-back {
transform: translateZ(-300px) scale(2);
z-index: 3;
height: 150vh;
}
.parallax_layer-deep{
transform: translateZ(-600px) scale(3);
z-index: 2;
background-color: #dbdbdb;
}
.parallax_group {
position: relative;
height: 100vh;
transform-style: preserve-3d;
/*transform: translate3d(700px, 0, -800px) rotateY(30deg);*/
}
/*Columns*/
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after {
content:"";
display:table;
}
.group:after {
clear:both;
}
.group {
zoom:1; /* For IE 6/7 */
}
/* GRID OF THREE */
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 66.1%;
}
.span_1_of_3 {
width: 32.2%;
}
#middle{
border-top: 0px;
border-bottom: 0px;
border-right: 1px;
border-left: 1px;
border-style: solid;
}
/*navigation*/
.nav {
position: sticky;
top: 0px;
height: 100px;
width: 100%;
z-index: 30;
font-family: 'Raleway', sans-serif;
font-size: 20px;
background-color: #dbdbdb;
}
.nav ul {
list-style-type: none;
margin-left: 0;
padding-top: 40px;
font-size: 25px;
font-family: 'Raleway', sans-serif;
line-height: 0;
z-index: 30;
}
.nav li {
display: inline-block;
margin-left: 15px;
padding-bottom: 25px;
z-index: 30;
}
a:link {
color: #2F649B;
font-family: inherit;
}
a:visited {
color: #2F649B;
}
a:hover {
color: #6D92B9;
text-decoration: none;
}
a:active {
color: #26507C;
text-decoration: none;
}
footer {
position: sticky;
bottom: 0px;
height: 100px !important;
line-height: 100px;
width: 100%;
}
I know it's allot of code but I have no idea what it could be so i went and gone ahead and gave you everything.
edit: The other html parallax group:
<!DOCTYPE html>
<html>
<head>
<title>Squirel WebDesign</title>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" type="text/css" href="handheld.css" media="screen and (max-device-width: 480px), screen and (max-width: 480px)">
</head>
<body>
<div class="parallax">
<header class="parallax_group">
<div class="parallax_layer parallax_layer-base">
<h1>i'm a bloody big header preferably with a squirel</h1>
</div>
<div class="parallax_layer parallax_layer-back">
</div>
<div class="parallax_layer parallax_layer-deep">
</div>
</header>