Scroll-snap and smooth scrolling

So I have this scroll snap and I am trying to use it and smooth scrolling going left and right. I have some code here but once I add scroll-snap it stops it from scrolling smoothly. Additionally how can I get rid of the scrollbar and have the same affect?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}

body {
overflow-x: clip;
}

header {
width: 100%;
}

header nav {
background-color: black;
color: white;
height: 5rem;
display: flex;
align-items: center;
justify-content: center;
}

ul {
display: flex;
align-items: center;
justify-content: center;
gap: 1rem;
}

li {
list-style-type: none;
}

a {
background-color: rgb(244, 115, 3);
text-decoration: none;
color: white;
font-size: xx-large;
padding: 0.5rem;
border-radius: 10px;
transition: background-color 0.4s ease-in-out;
}

a:hover {
background-color: brown;
}

.scroll-container {
display: grid;
grid-auto-flow: column;
grid-auto-columns: 100%;
gap: 0.5rem;
overflow-x: auto;
scroll-behavior: smooth;

scroll-snap-type: x mandatory;
}

.scroll-item {

scroll-snap-align: start;
scroll-behavior: smooth;
gap: 0.5rem;
grid-template-rows: min-content;
background-color: brown;
color: white;
font-size: xx-large;
height: 85svh;
text-align: center;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}

body {
overflow-x: clip;
}

header {
width: 100%;
}

header nav {
background-color: black;
color: white;
height: 5rem;
display: flex;
align-items: center;
justify-content: center;
}

ul {
display: flex;
align-items: center;
justify-content: center;
gap: 1rem;
}

li {
list-style-type: none;
}

a {
background-color: rgb(244, 115, 3);
text-decoration: none;
color: white;
font-size: xx-large;
padding: 0.5rem;
border-radius: 10px;
transition: background-color 0.4s ease-in-out;
}

a:hover {
background-color: brown;
}

.scroll-container {
display: grid;
grid-auto-flow: column;
grid-auto-columns: 100%;
gap: 0.5rem;
overflow-x: auto;
scroll-behavior: smooth;

scroll-snap-type: x mandatory;
}

.scroll-item {

scroll-snap-align: start;
scroll-behavior: smooth;
gap: 0.5rem;
grid-template-rows: min-content;
background-color: brown;
color: white;
font-size: xx-large;
height: 85svh;
text-align: center;
}
1 Reply
althepal78
althepal784w ago
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smooth Horizontal Scroll</title>
<link rel="stylesheet" href="src/css/style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#1">Box 1</a></li>
<li><a href="#2">Box 2</a></li>
<li><a href="#3">Box 3</a></li>
</ul>
</nav>
</header>

<div class="scroll-container snaps-inline">
<div id="1" class="scroll-item">Box 1</div>
<div id="2" class="scroll-item">Box 2</div>
<div id="3" class="scroll-item">Box 3</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smooth Horizontal Scroll</title>
<link rel="stylesheet" href="src/css/style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#1">Box 1</a></li>
<li><a href="#2">Box 2</a></li>
<li><a href="#3">Box 3</a></li>
</ul>
</nav>
</header>

<div class="scroll-container snaps-inline">
<div id="1" class="scroll-item">Box 1</div>
<div id="2" class="scroll-item">Box 2</div>
<div id="3" class="scroll-item">Box 3</div>
</div>
</body>
</html>
So I am guessing I am not allow to do this, is there a way I can do it with animation and key frames and still have the snap. Is there an if statement I can use that would say,
if(section >= 50%)
{
scroll.left.smoothly;

}
else{
scroll.right.smoothly;
}
if(section >= 50%)
{
scroll.left.smoothly;

}
else{
scroll.right.smoothly;
}