Why isn't smooth snap scrolling working with my nav links? - css

Smooth snap scrolling works in every regard except when the nav links are used. Btw enabling smooth scrolling in Chrome didn't help and it's not working in other browsers anyway so there's something I'm not getting.
Here's my Codepen in case you don't want to deal with the provided code: https://codepen.io/CyberGolem/pen/RwLGJeQ
Many thanks in advance...
const section = document.querySelector(".container__section");
const sections = document.querySelectorAll(".container__section");
const clrBG = ["#dbf8c3", "#d8b0dd", "#9b9bdb", "#fff1c5", "#a9ecf8"];
const options = {
threshold: 0.5,
// rootMargin: "-100px",
};
const observer = new IntersectionObserver(function (entries, observer) {
entries.forEach((entry) => {
if (!entry.isIntersecting) {
return;
}
console.log(entry.target);
// observer.unobserve(entry.target);
});
}, options);
sections.forEach((section) => {
observer.observe(section);
});
*,
*::before,
*::after {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html {
font-size: 62.5%;
text-decoration: none;
scroll-behavior: smooth;
overflow-y: scroll;
}
::-webkit-scrollbar {
display: none;
}
:root {
--nav-width: 10vw;
}
body {
color: #000;
background-color: whitesmoke;
font-family: "montserrat", sans-serif;
font-weight: 400;
width: 100vw;
height: 100vh;
margin: 0;
-webkit-transition: background-color 1s ease;
transition: background-color 1s ease;
}
.site-logo {
font-weight: 900;
font-size: 3rem;
color: var(--text);
text-decoration: none;
border: 1px solid red;
}
header {
--text: black;
--text-inverse: #333;
--background: transparent;
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: var(--nav-width);
z-index: 999;
padding: 2em 3em;
-webkit-transition: background 250ms ease-in;
transition: background 250ms ease-in;
background: var(--background);
color: var(--text);
border: 3px solid blue;
}
.nav-bar {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-flow: column nowrap;
flex-flow: column nowrap;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
}
.nav-bar .nav__list {
list-style: none;
margin: 0;
padding: 0;
background: lightblue;
}
.nav-bar .nav__link {
--spacing: 1em;
margin-top: 10px;
text-decoration: none;
color: inherit;
display: inline-block;
padding: calc(var(--spacing) / 2) var(--spacing);
position: relative;
letter-spacing: 2px;
font-size: 0.9rem;
}
.nav-bar .nav__link:after {
content: "";
position: absolute;
bottom: 0;
left: var(--spacing);
right: var(--spacing);
height: 2px;
background: currentColor;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: -webkit-transform 150ms ease-in-out;
transition: -webkit-transform 150ms ease-in-out;
transition: transform 150ms ease-in-out;
transition: transform 150ms ease-in-out, -webkit-transform 150ms ease-in-out;
}
.nav-bar .nav__link:hover::after {
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.nav-bar .nav__link--btn {
border: 1.5px solid currentColor;
border-radius: 2em;
margin-left: 1em;
-webkit-transition: background 250ms ease-in-out;
transition: background 250ms ease-in-out;
letter-spacing: 1px;
padding: 0.75em 1.5em;
}
.nav-bar .nav__link--btn:hover {
background: var(--text);
color: var(--text-inverse);
border-color: var(--text);
}
.nav-bar .nav__link--btn::after {
display: none;
}
.nav-bar .nav__link--btn--highlight {
background: limegreen;
border-color: limegreen;
color: #333;
}
.nav-bar .nav__link--btn--highlight:hover {
background: var(--text);
border-color: var(--text);
}
.nav-scrolled {
--text: #333;
--text-inverse: #f4f4f4;
--background: #f4f4f4;
-webkit-box-shadow: 0 3px 20px rgba(0, 0, 0, 0.2);
box-shadow: 0 3px 20px rgba(0, 0, 0, 0.2);
}
.container {
width: 100%;
height: 100%;
-ms-scroll-snap-type: y mandatory;
scroll-snap-type: y mandatory;
overflow-y: scroll;
}
.container__section {
height: 100vh;
width: 100vw;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
scroll-snap-align: start;
font-family: "Rubik", sans-serif;
}
.container #sec0 {
color: slategrey;
}
.container #sec1 {
color: red;
}
.container #sec2 {
color: blue;
}
.container #sec3 {
color: green;
}
.container h2 {
font-size: 23rem;
}
/*# sourceMappingURL=main.css.map */
<body>
<header>
<div class="nav-bar">
<a href="#sec0"
class="site-logo"
aria-label="homepage">HOME</a>
<nav>
<ul class="nav__list">
<li class="nav__list--item">
<a href="#sec1"
class="nav__link">SEC 1</a>
</li>
<li class="nav__list--item">
<a href="#sec2"
class="nav__link">SEC 2</a>
</li>
<li class="nav__list--item">
<a href="#sec3"
class="nav__link">SEC 3</a>
</li>
</ul>
</div>
</nav>
</header>
<main class="container">
<section class="container__section"
id="sec0">
<h2>HOME</h2>
</section>
<section class="container__section"
id="sec1">
<h2>ONE</h2>
</section>
<section class="container__section"
id="sec2">
<h2>TWO</h2>
</section>
<section class="container__section"
id="sec3">
<h2>THREE</h2>
</section>
</main>
</body>

Related

How do I get my images to fit into my rows and columns of my bootstrap grid?

I have searched SO for this answer and could not find something specific enough that works. I saw there were a lot of similar questions, but none that lead me to a working solution. I am sorry if this is a duplicate
I am trying to replicate the feature elements from the MySpace homepage (https://myspace.com/). I am trying to get one main feature image on the left and two smaller elements (img and video) on the right. The images should go flush against each other with each column being the same height. The grid should be responsive to the changes in size of the web broser so it stays centered, proportionate, and flush.
I am using the Bootstrap 5 grid system. I have a container with a main row. That row contains two columns. The left column is for the main image. The right column holds two more rows. The top row has an image, the bottom row has an iframe.
I have used object-fit: cover, overflow:hidden, max-width: some value, max-height: auto (and vice-versa), and all combinations of rows/cols.
I've spent hours Googling and looking up examples and YouTube videos. Everything is showing basic concepts but nothing with examples in ReactJS or that are at my lower skill level.
This feels like it should be super easy and it has been the hardest thing I've had. I have even been staring at the HTML in the devtools of the MySpace page to see if I can reverse-engineer it.
import React from "react";
import Feature from "../page/Feature";
import { IMAGES_BANDS, VIDEOS_HIGHLIGHTS } from "../../images/images";
export default function Bands() {
return (
<>
<div className="container">
<div className="row">
<Feature
IMAGES_FEATURE={IMAGES_BANDS}
IMAGE_HIGHLIGHT={IMAGES_BANDS[0].image}
VIDEO_HIGHLIGHT={VIDEOS_HIGHLIGHTS[0].video}
/>
</div>
</div>
</>
);
}
import React from "react";
import Slider from "../page/Slider";
export default function Feature(props) {
const { IMAGES_FEATURE, IMAGE_HIGHLIGHT, VIDEO_HIGHLIGHT } = props;
return (
<>
<div className="container image-fit-cover no-margin-padding">
<div className="row row-cols-2 justify-content-center row-size-feature">
<div className="col-8">
<Slider images={IMAGES_FEATURE} />
</div>
<div className="col-4">
<div className="row">
<img src={IMAGE_HIGHLIGHT} alt="band-highlight" />
</div>
<div className="row">
<iframe
src={VIDEO_HIGHLIGHT}
title="YouTube video player"
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowFullScreen
/>
</div>
</div>
</div>
</div>
</>
);
}
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
#media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
#keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.colors-theme {
background-color: black !important;
color: white !important;
}
.btn-theme {
background-color: white;
color: #000000;
display: inline-block;
font-weight: 400;
text-align: center
white-space: nowrap;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border: 1px solid transparent;
padding: .375rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
text-decoration: none
}
.btn-theme:focus,
.btn-theme:hover {
text-decoration: none;
background-color: #944dff;
color: #e0ccff;
}
.btn-theme-dark {
color: white;
background-color: black;
display: inline-block;
font-weight: 400;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border: 1px solid transparent;
padding: .375rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out
}
.btn-theme-dark:focus,
.btn-theme-dark:hover {
text-decoration: none;
color: black;
background-color: #e0f2f1;
}
.btn-link-theme {
font-weight: 400;
color: #f0e6ff;
background-color: transparent;
border-color: transparent;
text-decoration: none;
padding: 0px;
}
.btn-link-theme:hover {
color: gray;
text-decoration: underline;
background-color: transparent;
border-color: transparent
}
.navbar-search-form {
justify-content: flex-end;
}
.float-right{
float: right;
}
/*slider css*/
.slider {
position: relative;
margin-top: 10px;
margin-bottom: 20px;
display: flex;
justify-content: center;
align-items: center;
}
. right-arrow {
position: absolute;
top: 50%;
right: 5px;
font-size: 1rem;
color: black;
z-index: 10;
cursor: pointer;
user-select: none;
}
.left-arrow {
position: absolute;
top: 50%;
left: 5px;
font-size: 1rem;
color: black;
z-index: 10;
cursor: pointer;
user-select: none;
}
.slide {
opacity: 0;
transition-duration: 2s ease;
}
.slide.active {
opacity: 1;
transition-duration: 2s;
transform: scale(1.00);
}
/**/
.text-overlay-parent {
position: relative;
width: 100%;
height: 100%;
}
.text-overlay-child{
position: absolute;
top: 15%;
left: 10%;
}
.font-styles-heading{
font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
.row-size-feature{
height: 360px;
}
.image-fit-cover img {
height:auto;
max-width:700px;
overflow: hidden;
object-fit: cover;
}
.image-fit-cover iframe {
height: auto;
max-width: 700px;
overflow: hidden;
object-fit: cover;
}
.no-margin-padding * {
margin: 0px;
padding: 0px;
}
img of current page

z index multiple elements

hey guys I have 3 elements I'm using z-index and position property.
the first one is the main navbar (working fine)
the 2nd is sidenav
the 3rd is a button.
the button must have the position relative.
when I'm scrolling the main navbar is taking over the button which is great !
but the side navbar is not.
I did try to change the z-index on each element.
the mobile navbar is the main navbar which working fine.
.mobile-navbar {
background-color: rgb(0, 0, 0);
position: fixed;
z-index: 1;
width: 100%;
display: flex;
justify-content: space-between;
img {
background-color: rgba(0, 0, 0, 0.274);
}
div {
display: flex;
justify-content: center;
align-items: center;
a {
font-size: 2rem;
color: #fff;
margin: 5px;
text-decoration: none;
span {
background-color: red;
border-radius: 10px;
padding: 0 3px;
}
}
}
}
.side-nav {
position: fixed;
z-index: 0;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out;
button.close-nav {
padding: 5px;
background-color: rgb(14, 12, 12);
color: #fff;
border: none;
font-size: 2rem;
font-weight: 700;
}
.dynamic-links {
height: 30%;
button {
padding: 5px;
font-size: 2rem;
background: rgba(0, 0, 0, 0);
color: #fff;
border: none;
}
.sidenav-link {
color: #fff;
text-decoration: none;
font-size: 2rem;
margin: 0 10px;
}
}
.sidenav-links {
display: flex;
flex-direction: column;
height: 50%;
.sidnav-link {
color: #fff;
margin: 10px 0;
font-size: 2rem;
text-decoration: none;
text-align: center;
}
}
}
}
the button I need to use position relative and taking over the side-navbar:
button {
position: relative;
z-index: 0;
cursor: pointer;
font-size: 1.3rem;
padding: 10px 15px;
border: none;
outline: #06a821;
border-radius: 30px;
color: #fff;
letter-spacing: 0.3rem;
background: linear-gradient(
90deg,
rgba(5, 116, 197, 1) 35%,
rgba(106, 183, 239, 1) 100%
);
transition: ease-in-out 300ms;
&::before {
position: absolute;
border: 1px solid #fff;
left: 5px;
right: 5px;
top: 5px;
bottom: 5px;
border-radius: 30px;
content: "";
}
only had to add the z-index in the active class.
befor :
.side-nav {
position: fixed;
z-index: 0;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out
after:
.side-nav {
position: fixed;
width: 100%;
height: 100vh;
transform: translateX(-100%);
transition: 300ms ease-out;
&-active {
position: fixed;
z-index: 1;
width: 100%;
height: 100vh;
background-color: rgb(12, 6, 39);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateX(0);
transition: 300ms ease-out;

Fixed Left Menu scrolling not working?

I have made following demo on Codepen. Problem is when the height of viewport is decreased scroll appear which i want but logo is hidden under icon-list which is the unwanted behavior. Everything works properly if viewport height is enough.
<input type="checkbox" id="menu-expander" name="ert">
<div class="main-menu-container">
<div class="logo-area">
<div class="logo"><img src="http://extensiondl.maxthon.com/skinpack/11018970/1375652328/icons/icon_32.png"></div>
</div>
<ul class="sidebar-icon-list">
<li class="sidebar-icon">
<img src="http://www.clipartsfree.net/vector/small/go-home_Clipart_Free.png">
<span>Week</span>
</li>
<li class="sidebar-icon menu-active">
<img src="http://www.clipartsfree.net/vector/small/go-home_Clipart_Free.png">
<span>Projects</span>
</li>
<li class="sidebar-icon" title="Life">
<img src="http://www.clipartsfree.net/vector/small/go-home_Clipart_Free.png">
<span>Life</span>
</li>
<li class="sidebar-icon">
<img src="http://www.clipartsfree.net/vector/small/go-home_Clipart_Free.png">
<span>Analysis</span>
</li>
<li class="sidebar-icon">
<img src="http://www.clipartsfree.net/vector/small/go-home_Clipart_Free.png">
<span>Projects</span>
</li>
</ul>
<div class="sidebar-wt">
<label for="menu-expander"><img src="https://cdn3.iconfinder.com/data/icons/awesome-lineca-vol-1/17/angle-right-128.png"></label>
</div>
<div class="user-area">
<div class="user-pic"></div>
</div>
CSS
input[name="ert"] {
position: absolute;
opacity: 0;
width: 0;
height: 0;
overflow: hidden;
}
/* Main Menu Contaier */
.main-menu-container {
width: 6em;
position: fixed;
top: 0;
left: 0;
height: 100vh;
background-color: hsl(207,6%,12%);
color: #fff;
display: flex;
flex-direction: column;
z-index: 100;
border-right: 1px solid black;
transition: width 0.2s ease-in;
overflow-y: auto;
overflow-x: hidden;
}
input[name="ert"]:checked + .main-menu-container {
width: 12em;
transition: width .3s linear;
}
/* Logo Area */
.logo-area {
height: 6em;
background-color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 4em;
width: 4em;
}
.logo img {
height: 4em;
width: 4em;
}
/* Icon List */
.sidebar-icon-list {
display: flex column;
list-style: none;
width: 100%;
padding: 0;
margin: 0;
flex-grow: 1;
}
.sidebar-icon {
color: #eaeaea;
width: 100%;
border-left: 3px solid hsl(207,6%,12%);
height: 3em;
margin: 1em 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
cursor: pointer;
position: relative;
transition: all 0.3s linear;
}
.sidebar-icon:hover {
color: #fff;
border-left: 3px solid #EEFF22;
}
.sidebar-icon img {
color: #fff;
width: 2em;
height: 2em;
}
.sidebar-icon span {
font-size: 0.75em;
opacity: 0;
position: absolute;
transition: all 0.1s linear;
}
input[name="ert"]:checked + .main-menu-container .sidebar-icon-list .sidebar-icon {
flex-direction: row;
justify-content: flex-start;
padding-left: 1em;
transition: all 0.3s linear;
}
input[name="ert"]:checked + .main-menu-container .sidebar-icon-list .sidebar-icon span {
font-size: 0.75em;
opacity: 1;
position: relative;
transition: all 0.3s linear;
margin-left: 1em;
}
.menu-active {
border-left: 3px solid #EEFF22;
color: #EEFF22;
}
/* Sidebar Expander */
.sidebar-wt {
display: flex;
justify-content: flex-end;
}
.sidebar-wt label img {
height: 1.5em;
width: 1.5em;
cursor: pointer;
}
.main-menu-container .sidebar-wt label img {
transition: all 0.3s linear;
}
input[name="ert"]:checked + .main-menu-container .sidebar-wt label img {
transform: rotateZ(180deg);
transition: all 0.3s linear;
}
/* USer Area at Bottom */
.user-area {
height: 4em;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
}
.user-pic {
width: 100%;
height: 5em;
border-bottom: 2px solid #2ca58d;
background-image: url(http://soccer1x2.net/wp-content/uploads/2012/03/leo-messi1.png);
background-size: cover;
}
.main-menu-container .sidebar-wt label img {
transition: all 0.3s linear;
}
input[name="ert"]:checked + .main-menu-container .sidebar-wt label img {
transform: rotateZ(180deg);
transition: all 0.3s linear;
}
It looks like the height of .logo-container is changing, when you decrease the window's height.
If you min-height: 6em; for .logo-area the height will not decrease.

Triggering a list with CSS3 animations and Sass #for loop

I'm trying to create a keyframe animation in Sass with a for loop, but I'm stumbling on the writing of it. What I would like is have each single item to appear one after the other but with a minor delay. Sort of like a stacking of cards.
Here is a codepen. Here is the code:
<ul>
<li>About</li>
<li>Contact</li>
<li>Labs</li>
</ul>
html {
font-size: 62.5%;
box-zising: border-box;
}
*,
*:before,
*:after {
box-zising: inherit;
}
html, body {
width: 100vw;
height: 100vh;
background: black;
font-size: 1rem;
}
ul {
position: fixed;
display: flex;
flex-direction: column;
align-items: flex-start;
border: 1px solid white;
width: 100vw;
height: 100vh;
}
li {
list-style: none;
border: 1px solid white;
width: 100%;
text-align: center;
margin-top: 10px;
background: red;
#for $i from 1 through 4 {
&:nth-of-type(#{$i}) {
animation: slideTop;
animation-duration: 1.5s + (40ms * $i);
animation-iteration-count: 5;
animation-delay: 2.5s + (40ms * $i);
}
}
a {
display: block;
padding: 50px;
color: white;
font-size: 24px;
text-decoration: none;
letter-spacing: 0.1em;
}
}
#keyframes slideTop {
0% {
opacity: 0;
transform: scaleY(0);
}
100% {
opacity: 1;
transform: scaleY(50px);
}
}
see here > jsfiddle
you have to set a much bigger animation-delay so you can see that the lis appear one after the other
and you have to set opacity:0 together with animation-fill-more:forwards so at first the lis are hidden and then they appear and stay with opacity:1
let me know if this is what you were looking for
CODE :
( snippet not working because it doesn't have SASS; i've only put it so that the code is visible here on the site )
html {
font-size: 62.5%;
box-zising: border-box;
}
*,
*:before,
*:after {
box-zising: inherit;
}
html, body {
width: 100vw;
height: 100vh;
background: black;
font-size: 1rem;
}
ul {
position: fixed;
display: flex;
flex-direction: column;
align-items: flex-start;
border: 1px solid white;
width: 100vw;
height: 100vh;
}
li {
list-style: none;
border: 1px solid white;
width: 100%;
text-align: center;
margin-top: 10px;
background: red;
opacity:0;
#for $i from 1 through 4 {
&:nth-child(#{$i}) {
animation: slideTop;
animation-duration: 1s + ($i*400ms);
animation-iteration-count: 1;
animation-delay: 2.5s + ($i*400ms);
animation-fill-mode:forwards;
}
}
a {
display: block;
padding: 50px;
color: white;
font-size: 24px;
text-decoration: none;
letter-spacing: 0.1em;
}
}
#keyframes slideTop {
0% {
opacity: 0;
transform: scaleY(0);
}
100% {
opacity: 1;
transform: scaleY(50px);
}
}
<ul>
<li>About</li>
<li>Contact</li>
<li>Labs</li>
</ul>

transition width not working?

I have this HTML:
.orderData_button {
background-color: #FF5733;
border: none;
color: white;
padding: 5px 60px;
text-align: center;
display: inline-block;
font-size: 16px;
transition: width 1s ease-in-out
}
.slideDown_orderData {
display: none;
position: relative;
z-index: 3;
transition: width 1s ease-in-out
}
.orderData_button:hover .slideDown_orderData {
display: block;
width: 100%;
}
.orderData_button:hover {
width: 50%;
}
#orderData_2 {
font-size: 20px;
text-align: center;
}
<div class="orderData_button">
<p>Your Orders</p>
<p></p>
<div class="slideDown_orderData">
<p id="orderData_2"></p>
</div>
</div>
My orderData_button and slideDown_orderData will not transition width, but will change instantly. Why is this? (Yes I have look all over google, with no success)
-CSS noob

Resources