Put some space between webkit scrollbar and screen edge - css

I've got this css code that makes a webkit scrollbar.
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
This will make a scrollbar that will be right next to the screen edge. Is there any way that I can put some space between the screen edge and the scrollbar?

Here is an interesting solution to what I think you are talking about; they actually put padding/position on the body element:
body {
position: absolute;
top: 20px;
left: 20px;
bottom: 20px;
right: 20px;
padding: 30px;
overflow-y: scroll;
overflow-x: hidden;
}

Do not do this, you will be murdering usability.
If a scrollable region extends to the edge of the screen, the scrollbar must also be at the edge of the screen. This way, the user can simply hit the edge of the screen with their cursor and use the scrollbar. This action doesn't require visual attention or precise positioning; it's a simple, easy movement.
If the scrollbar is not at the edge of the screen, the following will happen:
The user will want to scroll the content which will unconsciously translate to hitting the edge of the screen with the cursor.
This unconscious scrolling action will fail, breaking the user's focus on the content.
The user will look toward the cursor to see what's wrong.
After detecting the problem, the user will have to make a precise movement of the mouse to position the cursor over the scrollbar. The difficulty of this movement is even greater if you use a non-standard, narrower scrollbar.
The user will click and drag, scrolling the content and returning their focus to it.
Even if all this takes a second, it's still very annoying and completely unnecessary, and, I imagine, quite likely to make the user take their business elsewhere.

Change the width of the scrollable element. For instance...
#div_content {
width: calc(100% - 20px);
}
That way, the other elements of the page are unaffected. For instance.
<div id="div_header">Welcome</div>
<div id="div_content">
Scrollable content goes here.
</div>
<div id="div_footer">©2015 by Whomever</div>
Sample CSS...
#div_header {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100px;
}
#div_content {
position: absolute;
left: 0;
top: 100px;
width: calc(100% - 20px);
height: calc(100% - 140px);
padding: 50px;
overflow-x: hidden;
overflow-y: auto;
}
#div_content::-webkit-scrollbar {
-webkit-appearance: none;
}
#div_content::-webkit-scrollbar:vertical {
width: 5px;
}
#div_content::-webkit-scrollbar:horizontal {
height: 5px;
}
#div_content::-webkit-scrollbar-thumb {
border-radius: 8px;
border: none;
background-color: #404040;
}
#div_footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 40px;
}

Related

Make a div go beneath another one when scrolling

I have the a page that looks like this:
What I want to do is that when I scroll the page, only the bottom half should move. I did it but because of the padding it makes it like this:
This is my css file:
.sites-list {
height: 40%;
width: 100%;
position: absolute;
right: 0;
bottom: 0;
left: 0;
top: 400px;
padding-left: 18rem;
padding-top: 5%;
background-color: #ffffff;
text-align: left;
font-size: 30px;
line-height: 40px;
color: #396aba;
}
When I inspect it in browser and uncheck top and padding-top it works fine:
How should I change it to make the white border be there if there is no scrolling but when I scroll to make the text go beneath the blue part as in the last picture?
I don't know exactly how your bars look like in CSS, but here is a working example that uses position: fixed.
.Bar {
position: fixed;
left: 0;
width: 100%;
height: 20vh;
z-index: 10;
background: #175f8f;
}
.Bar-top {
top: 0;
}
.Bar-bottom {
bottom: 0;
}
.Content {
position: relative;
z-index: 0;
padding-top: calc( 20vh + 100px ); /* set to the same height as the bar would be */
/* If you want to increase the padding and mix relative with absolute dimensions, use calc. Otherwise just add them up for a slightly better performance */
height: 2000px; /* we cheat a bit so we have something to scroll */
}
<div class="Bar Bar-top"></div>
<div class="Content">
Having your content here.
</div>
<div class="Bar Bar-bottom"></div>
You could set the blue bar to the following:
Position: fixed;
top: 0px;
z-index: 1;
And then set the element which you want the bar
to go over to:
z-index: 2;
This basically means that the blue bar is 'Fixed' to the top of the browser at all times. The nav element underneath it may require a margin-top of however tall the blue bar is to push it below the blue bar before it has been scrolled.

Image-Scaling "too late" when not centered (on windows-resize)

I'm not finding any information on this. Might be because my approach is incorrect.
I'm having my image positioned absolutely under a div which uses full window width.
I'm using margin-left: 30%, so that images are always positioned 30% from the left border.
Everything else is set for responsive image handling..
I got the code correct that it scales like I want if the browser-window gets resized.
But because the image is not centered, the scaling happens "too late", so the right part will be hidden outside view.
Can I solve this with the scaling starting "earlier"?
Or using sth different than margin-left: 30% or left: 30% ?
see here: JsFiddle - Image out of view when resizing window
img.aaa
{
position: absolute;
max-width: 85%;
max-height: 85%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin-top: auto;
margin-right: auto;
margin-bottom: auto;
margin-left: 30%;
}
You can use margin-left: auto which will center the image. If it has to be a certain distance from the left, use a container div and the following css. This will prevent the image from going outside the body and getting cut off.
.container {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
padding-left: 30%;
//text-align: center; //remove padding and uncomment this to center image in div
}
img.aaa {
max-width: 100%;
max-height: 85%;
box-shadow: 0 5px 10px rgba(0,0,0,0.8);
}
DEMO

Hide content but respond to :hover

I am working on a pure oocss approach to creating the charms as found in Windows 8. I have the Dock class finished, but am having problems with figuring out how to "expand" the charm when the mouse is moved over a docked area. I know there are ways to hide content but have the browser respond to the :hover event of Charm. If you have any ideas, let me know.
Dock
Docks content to the edge of the screen.
.dock
{
position: fixed;
height: auto;
width: auto;
}
.dock--top
{
width: 100%;
top: 0;
}
.dock--bottom
{
width: 100%;
bottom: 0;
}
.dock--left
{
height: 100%;
width: auto;
left: 0;
}
.dock--right
{
height: 100%;
right: 0;
}
Charm
Island containing the content.
.charm
{
padding: 24px;
}
.charm:hover
{
}
Html
<div class="charm dock dock--right">
</div>
I tried padding it and setting the width to 1px but had no luck. On my original plan I would have applied the background-color when the move moved over it so it did not render a line going down the side of the screen.
This is as close as I have gotten but its ugly:
.charm__body
{
width: 0;
visibility: collapse;
}
.charm:hover
{
background: blue;
}
.charm:hover .charm__body
{
width: auto;
visibility: visible;
}
You can make a transparent div, positioned absolutely, and make it work as a hover trigger.

Prevent CSS footer from scrolling

#bottom_fade {
position: absolute;
bottom: 0;
width: 100%;
background: url("bottom-fade.png");
background-repeat:repeat-x;
height: 400px;
z-index: 2;
}
.categories {
position: absolute;
left: 50%;
color:black;
word-wrap: break-word;
font-family: 15px 'Libre Baskerville', serif;
margin-left: -200px;
z-index: 1;
}
.categories td {
width: 200px;
}
you may see the result of the above code here.
Try to resize your browser window so that you're forced to scroll to see the whole text in the table.
As you scroll, you may see that #bottom_fade will not remain sticked to the bottom of the page but will follow your scrolling. I don't want that to happen: how can I say to bottom_fade to ALWAYS stays attached to the bottom of the browser window, no matter what happens to the scrollbar?
Many thanks!
Change
#bottom_fade {
position: absolute;
}
to
#bottom_fade {
position: fixed;
};
and it should work like a charm.
(nice effect by the way!)

CSS property width: 100%; make a page longer

I have a totally simple layout, in the page is only a silver background and the red DIV, as is possible to see on the image below. My problem is, that when I add the red DIV into my layout page, the page is longer on the length than 100% (bottom on the right corner - slider). Where could be a problem that caused this?
The CSS properties of the red DIV are:
html, body {
background-color: silver;
margin: 0;
padding: 0;
}
.red-div {
overflow: hidden;
width: 100%;
position: absolute;
top: 0;
left: 0;
}
.red-div {
overflow: hidden;
position: absolute;
top: 0;
left: 0;
right:0; /* This is what you need */
}
That way, you can force it to go to the end of the browser. When you do 100%, you do not account for the scrollbars. Which add the extra space and thus the annoying side-scroll

Resources