overflow-x: hidden; overflow-x: clip !important; overflow-x: hidden !important;

I am trying to use this but it seems to not work no matter where I put it, I want to add it mainly for the header section when I am using the query for anything less then 650px wide. however when I do that and go to the section it don't show an arrow but still lets you slide over to the right . I am going to show you the css that my code is rendering versus breaking down the sections of scss. If I have to I will show you how I am using sass to work with this maybe it is that.
29 Replies
althepal78
althepal78OP•5mo ago
@media (width <= 650px) {
body {
position: relative;
overflow-x: clip !important;
}
header {
width: 100vw;
height: 4rem;
background-color: rgba(0, 0, 0, 0.6);
}
header nav {
justify-content: space-between;
padding: 0 2rem;
text-align: center;
display: flex;
justify-content: space-between;
align-items: center;
font-size: x-large;
}
header nav .logo {
z-index: 4;
position: relative;
}
header nav .logo #logo {
width: 4rem;
animation: upanddown 2s infinite both;
}
header nav .logo .wave {
position: absolute;
width: 100%;
height: 50%;
background-image: url(../images/wave.svg);
background-size: 100%;
background-repeat: repeat-x;
bottom: -20%;
left: 0;
animation: wave 10s linear infinite;
}
header nav .toggle-links {
z-index: 4;
color: white;
}
header nav .nav-links {
height: 100svh;
background-color: rgba(0, 0, 0, 0.8);
text-align: center;
position: absolute;
top: 0;
right: -100%;
padding: 10rem 0;
z-index: 2;
width: 100%;
overflow-x: hidden;
margin: 0 auto;
}
header nav .nav-links li {
margin: 2rem;
}
header nav .nav-links li a {
color: white;
padding: 0.5rem;
background-color: #0553d1;
margin: 1rem;
border-radius: 10px;
}
.fish-container section {
margin-bottom: 0.4rem;
}
.fish-container section h1 {
font-size: clamp(30px, 10vw, 50px);
}
.fish-container section img {
width: clamp(5rem, 40vw, 15rem);
}
.fish-container #mangrove-snapper {
z-index: -1;
}
.fish-container #videos .videos {
max-width: 95%;
}
}
@media (width <= 650px) {
body {
position: relative;
overflow-x: clip !important;
}
header {
width: 100vw;
height: 4rem;
background-color: rgba(0, 0, 0, 0.6);
}
header nav {
justify-content: space-between;
padding: 0 2rem;
text-align: center;
display: flex;
justify-content: space-between;
align-items: center;
font-size: x-large;
}
header nav .logo {
z-index: 4;
position: relative;
}
header nav .logo #logo {
width: 4rem;
animation: upanddown 2s infinite both;
}
header nav .logo .wave {
position: absolute;
width: 100%;
height: 50%;
background-image: url(../images/wave.svg);
background-size: 100%;
background-repeat: repeat-x;
bottom: -20%;
left: 0;
animation: wave 10s linear infinite;
}
header nav .toggle-links {
z-index: 4;
color: white;
}
header nav .nav-links {
height: 100svh;
background-color: rgba(0, 0, 0, 0.8);
text-align: center;
position: absolute;
top: 0;
right: -100%;
padding: 10rem 0;
z-index: 2;
width: 100%;
overflow-x: hidden;
margin: 0 auto;
}
header nav .nav-links li {
margin: 2rem;
}
header nav .nav-links li a {
color: white;
padding: 0.5rem;
background-color: #0553d1;
margin: 1rem;
border-radius: 10px;
}
.fish-container section {
margin-bottom: 0.4rem;
}
.fish-container section h1 {
font-size: clamp(30px, 10vw, 50px);
}
.fish-container section img {
width: clamp(5rem, 40vw, 15rem);
}
.fish-container #mangrove-snapper {
z-index: -1;
}
.fish-container #videos .videos {
max-width: 95%;
}
}
this is just for the < 650 here is the other stuff not in query .show { display: block; } @keyframes upanddown { 0% { transform: rotateZ(6deg); } 50% { transform: rotateZ(-6deg); } 100% { transform: rotateZ(6deg); } } @keyframes wave { from { background-position-x: 0; } to { background-position-x: 600px; } } *, *::before, *::after { padding: 0; margin: 0; box-sizing: border-box; } html { scroll-behavior: smooth; } body { font-family: "Pirata One", cursive; background: center/cover fixed no-repeat url("../images/bgfish.webp"); width: 100%; } a { text-decoration: none; } li { list-style: none; }
```css
.goToTop {
display: none;
width: 50px;
height: 50px;
font-size: larger;
text-transform: capitalize;
color: white;
background-color: rgba(0, 0, 0, 0.7);
z-index: 1000;
position: fixed;
right: 20px;
bottom: 20px;
text-align: center;
padding: 0.4rem;
line-height: 2em;
border-radius: 1000000000%;
cursor: pointer;
}
```css
.goToTop {
display: none;
width: 50px;
height: 50px;
font-size: larger;
text-transform: capitalize;
color: white;
background-color: rgba(0, 0, 0, 0.7);
z-index: 1000;
position: fixed;
right: 20px;
bottom: 20px;
text-align: center;
padding: 0.4rem;
line-height: 2em;
border-radius: 1000000000%;
cursor: pointer;
}
Chris Bolson
Chris Bolson•5mo ago
It may be simpler if you put all this CSS, along with the corresponding HTML, in a codepen (or similar). That way somebody might be able to help you rather than having to spend time trying to work out what your HTML might look like and what might be causing the issue.
althepal78
althepal78OP•5mo ago
that makes a lot of sense LOL I will do that now 🙂 https://codepen.io/althepal78/pen/JjQPWex I don't know why it seems like it is working lol
Chris Bolson
Chris Bolson•5mo ago
You are getting a horizontal (x) scroll due to the "hidden" nav menu - is that what you are reffering to?
althepal78
althepal78OP•5mo ago
yes I am getting that however, it seems to work when in codepen lol
althepal78
althepal78OP•5mo ago
No description
althepal78
althepal78OP•5mo ago
not in codepen I get this
althepal78
althepal78OP•5mo ago
Fishing With Dummies
I, ALTHEPAL78, am relearning how to fish after many years. I used to fish with my father but haven't done so since childhood. Starting from scratch, I've been learning from various online channels, though none are local to Spring Hill, Florida. I'll be fishing around Clearwater, possibly Saint Petersburg, and Tampa. My boat is an old cruiser, no...
althepal78
althepal78OP•5mo ago
this is the actual site
Chris Bolson
Chris Bolson•5mo ago
Why are you toggling (via JavaScript) the overflow on the body? As you currently have it you are setting the overflow to "auto" when the menu is outside of the viewport which is allowing the scroll - if anything it should be the other way round. But really you shouldn't need to toggle this.
althepal78
althepal78OP•5mo ago
? let me check my js I thought I took that out oh it is for the scroll-y don't work. When I click on the hamburger menu to open it, I don't want people to be able so scroll in the y should I be changing that to scroll-y: none I don't even know if that is a thing lol
Chris Bolson
Chris Bolson•5mo ago
ok, then you should set it specfically to overflow-y: hidden and define overflow-x: hidden on the body in the CSS. I am not overly convinced by this method in general but lets at least try to get what you have working. Rather than postion: absolute, you might want to try postion: fixed - that would allow the vertical scroll but your nav would remain fixed on top of the content.
althepal78
althepal78OP•5mo ago
I am confused as to what you are saying. I have to think about it again
Chris Bolson
Chris Bolson•5mo ago
First thing to try is to set overflow-x: hidden on the body selector in the CSS. Then, in your JS code, change the toggle that you have to only toggle overflow-y Ignore what I said about using position fixed for now.
althepal78
althepal78OP•5mo ago
okay I will do that now I will delete all the js that changes this SO on the the body selector did not work I just adding that overlowy = hidden it seems to be working but for some reason it is not the ov -x is not so annoying
Chris Bolson
Chris Bolson•5mo ago
You haven't updated the live site, have you? Have you added overflow-x: hidden to the body selector directly in the CSS code? (ie not via JavaScript)
althepal78
althepal78OP•5mo ago
no sorry I have not yet but I will do that now I actually did and that did not work. You might be correct about position fixed I will try that
Chris Bolson
Chris Bolson•5mo ago
May I make a couple of suggestios for your JS code? Firstly you are detecting the "click" event on the whole page so every time the user clicks anywhere on the page, the JS is calling the toggleHeader() function. Whilst this is sometimes a good solution to avoid having 100s of event handlers, in your case you only have 1 so this is being counter-productive as each time the function is called, the JavaScript has to check to see if the target is the "toggle" button. Whilst you probably won't notice it, this is taking time and processing that you really don't need. In this case it would be better to define the toggle button directly (which by the way should be an HTML button rather than a div) so the JS can get on with toggleing the nav rather than spending time checking if it is the toggle button or not. My second suggestion is that, rather than checking of the nav has a specific style (-100%), you define a JS variable to hold the "visible" state and toggle this value each time the button is clicked. Again, this will remove the need for the JavaScript to have to check if the nav has this style applied or not each time the button is clicked. All in all I would suggest changing this code:
document.addEventListener("click", toggleHeader);
function toggleHeader(e) {
if (e.target === toggle && navLinks.style.right === "-100%") {
navLinks.style.right = "0px";
toggle.textContent = "X";
document.body.style.overflow = "hidden"
} else if (e.target === toggle && navLinks.style.right === "0px") {
navLinks.style.right = "-100%";
toggle.textContent = "☰";
document.body.style.overflow = "auto"
}

if (e.target !== toggle && navLinks.style.right === "0px") {
navLinks.style.right = "-100%";
toggle.textContent = "☰";

document.body.style.overflow = "auto"
}
}
document.addEventListener("click", toggleHeader);
function toggleHeader(e) {
if (e.target === toggle && navLinks.style.right === "-100%") {
navLinks.style.right = "0px";
toggle.textContent = "X";
document.body.style.overflow = "hidden"
} else if (e.target === toggle && navLinks.style.right === "0px") {
navLinks.style.right = "-100%";
toggle.textContent = "☰";
document.body.style.overflow = "auto"
}

if (e.target !== toggle && navLinks.style.right === "0px") {
navLinks.style.right = "-100%";
toggle.textContent = "☰";

document.body.style.overflow = "auto"
}
}
to this:
// reduce the load on the JS by defining the nav toggle button directly
const toggleNavBtn = document.querySelector("[data-toggle]");
toggleNavBtn.addEventListener("click",toggleHeader);

// varaible to store to visible "state" of the nav menu
let navVisible = false;
function toggleHeader() {
// toggle visible state
navVisible = !navVisible;
if(navVisible){
navLinks.style.right = "0";
toggleNavBtn.textContent = "X";
document.body.style.overflowY = "hidden"
} else{
navLinks.style.right = "-100%";
toggleNavBtn.textContent = "☰";
document.body.style.overflowY = "auto"
}
}
// reduce the load on the JS by defining the nav toggle button directly
const toggleNavBtn = document.querySelector("[data-toggle]");
toggleNavBtn.addEventListener("click",toggleHeader);

// varaible to store to visible "state" of the nav menu
let navVisible = false;
function toggleHeader() {
// toggle visible state
navVisible = !navVisible;
if(navVisible){
navLinks.style.right = "0";
toggleNavBtn.textContent = "X";
document.body.style.overflowY = "hidden"
} else{
navLinks.style.right = "-100%";
toggleNavBtn.textContent = "☰";
document.body.style.overflowY = "auto"
}
}
althepal78
althepal78OP•5mo ago
My son tripped my power just now just got back on so I will do this now just got back on I was watching videos. I saw that they were doing it this way, the js, because they wanted to make sure that they would get to do this because they said this makes sure that you hitting the target, toggle btn, and if you are not clicking on a link it will go away but I will try it your way but for some strange reason my js is no longer working like wow before I even changed out the js I have to go buy a wire real quick but something stopped working in my code also I can't figure it out . I have no idea why it got fucked up either
Chris Bolson
Chris Bolson•5mo ago
don't change the JS if you don't feel it is necessary. That is just how I would do it, but that doesn't mean that I am right. It is probably best to contrate on resoloving your actual issue.
althepal78
althepal78OP•5mo ago
yes that is what I am trying to do now. My JS just stopped working out of no where
Chris Bolson
Chris Bolson•5mo ago
are you getting any console errors?
althepal78
althepal78OP•5mo ago
no I am not what is happening is that the right has to be declared in JS for it to know where it is when I am looking for navLinks.style.right so it is not set for some strange reason. Even thought the JS is defer. Is there a way in the css I can make say -100 now leth the js see this.
Chris Bolson
Chris Bolson•5mo ago
another reason to store the "visible" state in the JS rather than having to read the element properties each time 😉
althepal78
althepal78OP•5mo ago
so I am going to try it your way real quick to see how it works I got the no side scrolling I think
Chris Bolson
Chris Bolson•5mo ago
If you don't want to change the event listener on the document method, try changing your function to this:
let navVisible = false;
function toggleHeader(e) {
if (e.target === toggle){
// toggle nav visible state
navVisible = !navVisible;
//console.log(navVisible)

// toggle elements based on the navVisible state
if(navVisible){
navLinks.style.right = "0px";
toggle.textContent = "X";
document.body.style.overflowX = "hidden"
}else{
navLinks.style.right = "-100%";
toggle.textContent = "☰";
document.body.style.overflow = "auto"
}
}
}
let navVisible = false;
function toggleHeader(e) {
if (e.target === toggle){
// toggle nav visible state
navVisible = !navVisible;
//console.log(navVisible)

// toggle elements based on the navVisible state
if(navVisible){
navLinks.style.right = "0px";
toggle.textContent = "X";
document.body.style.overflowX = "hidden"
}else{
navLinks.style.right = "-100%";
toggle.textContent = "☰";
document.body.style.overflow = "auto"
}
}
}
This still uses your general document event listener but I have modified the code to define a variable called "navVisible". This is then toggled (true or false) when the toggle is clicked and your other styles are defined accordingly
althepal78
althepal78OP•5mo ago
I will try this I think I got it I don' t know until I test it for real with a phone lol This does not work because unless I click the toggle button it won't go away so if I click on the videos button the screen is still there what I had to do was add this line for it to work in my js
navLinks.style.right = "-100%";
navLinks.style.right = "-100%";
then I redid my js code with toggleBtn because that is a way better naming convention then just toggle lol works on my computer like a charm does not work for some reason on my phone. I mean it was I updated the site and nothing never mind I got it to work you can see it if you go to it : )
althepal78
althepal78OP•5mo ago
Fishing With Dummies
I, ALTHEPAL78, am relearning how to fish after many years. I used to fish with my father but haven't done so since childhood. Starting from scratch, I've been learning from various online channels, though none are local to Spring Hill, Florida. I'll be fishing around Clearwater, possibly Saint Petersburg, and Tampa. My boat is an old cruiser, no...
althepal78
althepal78OP•5mo ago
so I think I got it to work on the phone but I lost my phone at a dock today lol so I will test it next time It's working
Want results from more Discord servers?
Add your server