I have a problem with oveflow-x in my page. Althought the body has overflow-x hidden, I can still scroll on the page.
<html>
<body>
<div id="content">
<div id="mydiv"></div>
<div>
</body>
</html>
html and body have overflow-x:hidden.
Div "content" has nothing in the css and div "myDiv" has position absolute.
How can I make the "mydiv" not to go out of the page? Because now what happens is that I can still scroll on x.
Fiddle > http://jsfiddle.net/o7dph6sj
Without more code, the best answer I can think of is that your html and body tags do not have any kind of width set so they are inheriting the default width of 100%. Meaning that every child element is going to be inside of that 100%.
Set the body to have a set width and then set overflow to hidden, then check if the elements in your page are exceeding the width.
Example:
body{
width: 1024px;
overflow-x: hidden;
}
Also, the code that you set inside of #content could directly be affecting it as well, some elements will ignore its parents and be rendered outside of them which brings us back to... give us more code.
Because you're using a bad selector for overflow. If you want to avoid VERTICAL SCROLLING you use this:
html, body {
overflow-y: hidden;
}
to avoid HORIZONTAL SCROLLING:
html, body {
overflow-x: hidden;
}
to avoid BOTH
html, body {
overflow: hidden;
}
take a look to your forked fiddle where I avoid BOTH overflow axises and there's no overflow at all
Change "overflow-x: hidden !important;" to be
html, body {
overflow: hidden !important;
}
or
html, body {
overflow-y: hidden !important;
}
In-fact you can ignore "!important" since you use !important to override other rule. And here you were just using the wrong property "overflow-x" which is for "Horizontal scroll"
And it works!!!
Here is the working Fiddle > http://jsfiddle.net/o7dph6sj/1/
Updated the Answer with addition requirement:
You add "overflow: hidden" when you don't want both scrolls,
AND "overflow-y: hidden;" hides the Horizontal Scroll
AND "overflow-x: hidden;" hides the Vertical Scroll
Checkout the updated Fiddle and try on your by commenting and un-commenting this code:
html, body {
overflow-y: hidden; /* Hides Horizontal Scroll*/
/*overflow-x: hidden;*/ /* Hides Vertical Scroll*/
/*overflow: hidden;*/ /* Hides Both Vertical and Horizontal Scroll*/
}
Updated Fiddle "http://jsfiddle.net/o7dph6sj/3/"
Checkout these articles >
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-y
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-x
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
I tried for several hours and I found that the body size needs to be specified, and its attribute position must be set to absolute. Then you can have overflow-x: hidden work well in your code.
in this case, I have a web with a navbar that I want to slide right to hide from the main body in mobile size. I called #media screen and (max-width:576px) to make it run on mobile size. the problem occurred before I specify the max-width the body must be shown: I still can scroll to the right though I specified the overflow-x: hidden
so I added max-width:100vh inside the body style, and voila. it works!
checkout my code:
body{
min-width: 0px;
max-width: 100vh;
position: absolute;
overflow-x: hidden;
}
nav ul {
position: absolute;
right: 0;
width: 40%;
top: 34px;
height: 100vh;
z-index: 1;
background-color: #194ca7;
}
Related
Here is the photo of the border of the body
As you can see the body is not at 100% height.
Here's the CSS codes of the HTML and Body
html{
height: 100%;
min-height: 100vh;
}
body{
height: 100%;
min-height: 100vh;
font-family: sans-serif;
min-width: 400px;
position: relative;
display: flex;
justify-content: center;
border: 5px solid black;
padding: 0;
margin: 0;
}
I tried putting the height of the html and body separately but it still didn't work. I tried searching and them saying make min-height and height at 100% or 100vh and so I did but it still didn't work. I think it is because those things that are over the body are overflowing from its container?
Edit: I forgot to add this but the reason why I want body to extend along with the overflow is because that left and right container is positioned as sticky. So I can't use overflow: hidden;
I can try putting the left and right container as position: fixed; but it does not take space so I have to resize everything and also I want to know what is happening so I can avoid this problem.
Here's the whole code
https://codepen.io/n01knowz/pen/qBpBapV
I'm new to CSS so I don't know if there's any writing problem there so please tell me what I can fix.
Update: Okay so the reason the body wasn't extending was because the container is overflowing and technically isn't getting any bigger and so the body isn't expanding because its child's height isn't expanding too. So that's the danger of using when you set the height of the container.
Solution: Just let the container's height be and let the child components of the container be the one to decide its height.
Add in the overflow attribute. Which can work more than one way.
If you want no scroll bar use hidden, if you want to keep the content you can use scroll.
body {
overflow: hidden; /*any content that would overflow would be hidden and there is no scroll bar, NOTE, this will not stop the containers from overflowing. */
overflow: scroll; /* this would place scroll bar once the content overflows */
overflow: auto; /*will only add the scroll bar only after content over flows but will not add if it the content does not overflow */
}
I am trying to make the horizontal scroll bar hidden so that the user cannot scroll . I have read somewhere that my body tag should contain a width of 100% and to set overflow-x:hidden but the following code but I can still scroll a bit on my mobile media query as shown below:
html, body {
background-color: silver;
height: 400%;
width: 100%;
overflow-x:hidden;
}
enter image description here
Check the example below, I've set the div width to be higher than my window and in the body tag, I remove the scroll using an overflow-x: hidden.
Since I don't have access to your source I can't help much.
HTML
<body>
<div class="scroll">
<p>Hi</p>
</div>
</body>
CSS
body {
overflow-x: hidden;
}
.scroll {
min-height:800px;
min-width: 1000px;
}
Working example: FiddleJs Example, note that if you remove the overflow-y the horizontal bar will show up. Maybe you're overwriting the overflow, try to mark it as:
overflow-y: hidden !important
Or open your console and debug in there.
I need to give an div a width of 120%. But I don't want horizontal scrollbars, so I set overflow-x hidden for the body. Can the normal website view be harmed by that command?
CSS
body{
overflow-x: hidden;
}
If you have a div with width: 120% of the body and you give
body{
overflow-x: hidden;
}
You will not see that 20% more of the div's content. It will he hidden.
See the working sample: http://jsfiddle.net/carloscalla/tducn765/
It is not "harmful". If you don't want to hide that 20% then you should use overflow-x: auto;
Here is a simplified jsfiddle test.
This CSS causes no problem on a page where the content has overflow:
html, body {
height: 100%;
}
body {
overflow: auto;
}
But once this CSS is applied, despite scrolling, no element has a non-zero scrollTop:
html, body {
height: 100%;
}
body {
overflow: auto;
}
html {
overflow: hidden;
}
The problem seems to be applying overflow: hidden to the html element* causes the scrollTop of the body element to always return 0. Which makes no sense. There is a scrollbar with a non-zero position. How do I read/control it?
* doing this to prevent some ugly artifacts from CSS transitions, but also because it makes sense; we only want the body to scroll. Removing it is not an option.
Maybe you could create a fixed, fullsize wrapper around your page and remove the overflow:auto from the body. Then, the scroll you would be reading would not be from the body, but from the wrapper.
See this fiddle: http://jsfiddle.net/ZTt3S/1/
This div below is causing the page to scroll horizontally on smaller then 1450px browsers. I thought overflow would fix this issue, but does not appear to... may be something I need to do on the parent div's. Any ideas?
http://barr-display.mybigcommerce.com/
#Header {
position: relative;
clear: both;
width: 1450px;
min-height: 190px;
overflow: hidden;
background: url('/content/headerbg3.jpg') repeat-x;
}
On body you need the following
body {
width:100%;
overflow:hidden;
}
The reason your code is not working is that you're setting overflow on the child(#header) when it needs to be set on the parent.
Looks like you want three things:
No scrollbar when header image is cut off.
YES to scrollbars when main page content is cut off.
Ability for your header background to extend to the right if the browser window is wide.
You really needed to post more of the relevant code here. However, I look at your site, and this'll fix it:
Change your rule for #outer:
#Outer {
clear: both;
margin: 0 auto;
min-height: 190px;
width: 1024px;
}
Remove the margin and width rules from #outer's parent, and replace with width:100%;overflow-x:hidden;
Add these lines to your css:
html, body {
width:100%;
}
body {
overflow-x:hidden;
}
You need overflow-x so the vertical scroll bar doesn't disappear.
Also, remove overflow: hidden; from the #Header.