I do not have any example for this however it's really not needed for this question. Is it possible to make a div scrollable left and right but not up and down? I understand that a relative layout does both, and a fixed doesn't move at all.
Requirement must be done through HTML and CSS only.
Try using this, the only issue is that it doesn't work with all browsers:
div {
position: sticky;
}
Maybe this is a bit too short (but can't answer without more information or markup, or JSFIDDLE to apply)
CSS
div {
overflow-x: scroll;
overflow-y: hidden;
}
Related
I am new to HTML and CSS and am creating a website for a basic university course. For a project, I have created 8 div cards highlighting the planets of the Solar System but cannot get the cards out of this fixed/unscrollable position.
This is the link to the current page state:
https://hollandtheperson.com/dight/250/website/planets.html
Any tips on how to fix this?
You have added overflow: hidden; for the CSS in the body tag, which hides the scrollbar essentially making the scroll feature unusable, if you remove it then it should work.
You can set the overflow-x instead of overflow to hidden, like so:
...
overflow-x: hidden;
...
This disables horizontal scroll but allows vertical scroll
The problem isn't really with it being fixed in place, but i can see why you got that impression.
You're using overflow: hidden; which means "if something doesn't fit, snip it off".
So, because the overflow has cut away everything wasn't already within the viewport - there is now nothing outside the viewport, and hence, no reason to allow scrolling.
Fixed the .card height and add overflow-x: hidden which give you scrolling card. Sample code given below:
.card{
// add additional code
height: 350px;
overflow-x: hidden;
}
Hi can see that you have added items in css of body tags which i guess you should remove in order make it scrollable feature those are
height: 100vh;
overflow: hidden;
Please check if that works hopefully it should be.
I've asked this question before. Here is an original post.
We've found a solution but I would like to ask is there any chance to solve this in another way?
Original fiddle link with that issue.
Could someone explain why element with display:block; or even with dipslay:flex; or any other display type (except table) does not take the width, hidden under scroll?
It's a bit confusing me.
When using width 100% it will want to stretch to the size of its container, if you have more content than space, try adding overflow: scroll; it will add a scrollbar and attempt to keep the width you set it at stable.
.pane .body {
width: 100%;
overflow: scroll;
}
Is there a way to prevent scrollbar from pushing content, or the entire page to the left with pure css?
I mean no hacks or anything.
I tried two javascript solutions:
1) Set body to overflow hidden, store the body.offsetWidth in a variable, then overflow visible and then subtract that offsetWidth with the current body.offsetWidth and apply the difference to the right margin.
2) Calculate the offsetWidth and apply it on the wrapper div on every resize.
What didnt work:
1) Position absolute.
2) Floating everything to the left was a bad idea.
3) Leaving the scrollbar visible (Looks bad).
4) Overflow-y hidden makes things user unfriendly.
There are a lot of ways to go around this issue though normally you won't mind a little push to the left:
Give overflow-y: scroll to body and make sure always there is a scrollbar.
Make use of the fact that viewport width includes the scrollbar while percentages do not account for it:
a. Giving width: 100vw to body element, or
b. Giving margin-left: calc(100vw - 100%) to the html element so that scrollbar or not, you have a fixed area to work on.
There is even a deprecated overflow: overlay property that draws over the page instead of shifting it to the left.
Just give your body a width of 100vw like this:
body{
width: 100vw;
}
Even though all the answers above are correct, I stumbled upon this issue and I had to come up with another solution.
Since my content width takes up the whole page and it has some properties to justify in the center, it was being pushed to the left and these options didn't prevent it from happening.
What fixed the problem for me was to add a padding of the size of the scroll when the scroll is added on hover.
I tested on Chrome and Edge. It's not a perfect fix but it is enough for what I need right now.
.scrollable {
width: 100%;
height: 91vh;
overflow: hidden;
padding: 0px !important;
}
.scrollable:hover {
width: 100%;
height: 91vh;
overflow-y: auto;
padding-left: 16.8px !important;
}
Unfortunately there is no other way to prevent your problem.
Just use
body {
overflow:hidden;
}
As an alternative, I recommend you to use a Framework for custom scroll bars. Or disable the scrollbar as shown in the above snippet and emulate it with an absolute positioned and some JS.
Of course you will have to consider calculating the height of the page and the offset of the scrollbar thumb.
I hope that helps.
To disable the horizontal scrollbar, you can use overflow-x, so it won't affect your vertical scroll:
body {
overflow-x: hidden;
}
Just set overflow-x to hidden on the element that has the scrollbar (usually this would be the body or the immediate children of it).
I had the same problem on my nextjs app which already had overflow-x set to hidden on the body. The below solution worked for me
#__next{
overflow-x: hidden;
}
I am creating a horizontal scrolling site that will dynamically resize itself when i add the javascript to it later. However i started setting up the HTML and the code seems to cause a issue when i put another div inside of the div that makes up my dynamic code.
Also, would someone with more experience like to explain the drawbacks of using such a code if there are any?
#main_cont {
height : 500px;
white-space : nowrap;
overflow-x: scroll;
width: auto;
}
.ads {
display : inline-block;
height : 100%;
}
Is there a way for me to adjust the code below so that i can put divs and potentially images inside of it. I don't want to use a Javascript fix for this. thank you in advance.
http://jsfiddle.net/YVyFA/
You're just missing vertical-align: top; for your panels
.wlds {
vertical-align: top;
}
Updated fiddle
Also you don't need javascript to resize your layout, use a fluid layout by setting height and width in percentage values
I found a link that might be able to explain how to make a website that requires horizontal scrolling. Try this tutorial by CSS-Tricks. Hope this helped. Have a good day.
Well, the quickest and dirtiest solution to this is to give the #main-cont div a specific width and make the .wlds divs floated. So add the following CSS rules:
#main-cont {
width: 783px;
}
.wlds {
float: left;
}
JSFiddle.
Hey guys, ive been working on this drop down for wayyy to long now. I just cant get the drop down to fall on top of the main content on the page. I have tried adding position: relative and z-index on all relevant areas.
I think what may be causing the problem is "overflow: hidden" in some places.. but that is by far my favorite way to contain floats..
http://dev.redstoneinvestments.com/index.php?s=&p=redstone&v=home
Any suggestions?
Remove position: relative and overflow: hidden from both header and maincontent. If you need to clear the floats, use the clearfix method: http://net.tutsplus.com/tutorials/html-css-techniques/css-fudamentals-containing-children/ (this article specifically explains why clearfix is a better solution than overflow: hidden when you have absolutely positioned elements that need to extend outside the container).
change #header css to
#header {
background-color:#FFFFFF;
height:140px;
width:900px;
}
that enough, it fixed the problem on my firefox.