How to make ::-webkit-scrollbar-thumb smaller? - html

I customize scrollbar by CSS3. And I don't know, how to make scrollbar-thumb smaller (shorter). Width or height don't work. Can anybody help me?
#parent {
width: 300px;
height: 300px;
padding: 20px;
overflow: auto;
}
#child {
width: 250px;
height: 1000px;
margin: 0 auto;
border: 2px solid #8c1b21;
}
#parent::-webkit-scrollbar {
width: 15px;
background-color: #B79889;
border-radius: 5px;
box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
#parent::-webkit-scrollbar-thumb {
background-color: #8c1b21;
border-radius: 5px;
}
<div id="parent">
<div id="child"></div>
</div>

Height of thumb depends on the height of the div where you are applying scroll
#parent {
width: 300px;
height: 300px;
padding: 20px;
overflow: auto;
}
#child {
width: 250px;
height: 4000px;
margin: 0 auto;
border: 2px solid #8c1b21;
}
#parent::-webkit-scrollbar {
width: 10px;
background-color: #B79889;
border-radius: 5px;
box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
#parent::-webkit-scrollbar-thumb {
background-color: #8c1b21;
border-radius: 5px;
}
<div id="parent">
<div id="child"></div>
</div>

I've come across a lot of methods for this very problem; the usual answer is create a div, make a custom scroll bar (don't), or don't bother. This is a solution I found previously to solve this problem:
border-top: 15px solid transparent;
border-bottom: 35px solid transparent;
background-clip: padding-box;
Basically surround the track with transparent thicc borders, ie. shorten the track.

This works for me, "::-webkit-scrollbar /width" is the key
::-webkit-scrollbar-track
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
background-color: #F5F5F5;
}
::-webkit-scrollbar
{
width: 4px !important;
background-color: #F5F5F5;
}
::-webkit-scrollbar-thumb
{
background-color: $apple-gray;
}

Related

How can I fit a div to its content and align it to the right? [duplicate]

This question already has answers here:
How can I make a div not larger than its contents?
(43 answers)
Closed 1 year ago.
I am trying to make a simple chat application and can't seem to display the chat text belonging to one user stick to the left while the other user's message sticks to the right.
Here is a sample of the code:
.chat-session {
width: 400px;
height: 400px;
border: 1px solid #aaaaaa;
padding: 1%;
}
.user1 {
padding: 0 2px 2px 2px;
border: 1px solid #09aedc4f;
border-radius: 3px;
background-color: #09aedc4f;
margin-bottom: 2px;
}
.user2 {
padding: 0 2px 2px 2px;
text-align: right;
border: 1px solid rgba(0, 128, 0, 0.493);
background-color: rgba(0, 128, 0, 0.493);
margin-bottom: 2px;
border-radius: 3px;
}
<div class="chat-session">
<div class="user1">Hello</div>
<div class="user2">Hi</div>
<div class="user1">What's up?</div>
<div class="user2">Not much</div>
</div>
I would like the divs to fit the text size and user2's div to align right. I have tried display: inline-block; to fit the divs, but that just displays them all on the same line. I have also tried float: right; and float: left; but that also displays them on the same line.
Can someone help?
you could use display with the table-layout algorithm to shrink element to its content, then max-width and margin-left:auto
.chat-session {
width: 400px;
height: 400px;
border: 1px solid #aaaaaa;
padding: 1%;
}
.chat-session>* {/* Update */
display: table;/* for infos : okay with any browser for ages and only from IE8 for MSIE */
max-width: 100%;
}
.user1 {
padding: 0 2px 2px 2px;
border: 1px solid #09aedc4f;
border-radius: 3px;
background-color: #09aedc4f;
margin-bottom: 2px;
}
.user2 {
padding: 0 2px 2px 2px;
text-align: right;
border: 1px solid rgba(0, 128, 0, 0.493);
background-color: rgba(0, 128, 0, 0.493);
margin-bottom: 2px;
border-radius: 3px;
margin-left: auto/* Update */
}
<div class="chat-session">
<div class="user1">Hello</div>
<div class="user2">Hi</div>
<div class="user1">What's up?</div>
<div class="user2">Not much</div>
<div class="user1">What's up? What's up? What's up? What's up? What's up if there a long text here?</div>
<div class="user2">Not much</div>
</div>
Your can put your message tag in another tag with text-align property
.chat-session {
width: 400px;
height: 400px;
border: 1px solid #aaaaaa;
padding: 1%;
}
.user1 {
display:inline;
padding: 0 2px 2px 2px;
border: 1px solid #09aedc4f;
border-radius: 3px;
background-color: #09aedc4f;
margin-bottom: 2px;
}
.user2 {
display:inline;
padding: 0 2px 2px 2px;
border: 1px solid rgba(0, 128, 0, 0.493);
background-color: rgba(0, 128, 0, 0.493);
margin-bottom: 2px;
border-radius: 3px;
}
.message-right{
position: relative;
width: 100%;
text-align: right;
}
.message-left{
position: relative;
width: 100%;
text-align:left;
}
<div class="chat-session">
<div class="message-left"><div class="user1">Hello</div></div>
<div class="message-right"><div class="user2">Hi</div></div>
<div class="message-left"><div class="user1">What's up?</div></div>
<div class="message-right"><div class="user2">Not much</div></div>
</div>

Hide scrollbar track but show scrollbar-thumb

Good evening! I just wanna to change my scroll like this.
So it looks like that track is hidden. I got my style like this
::-webkit-scrollbar{
width: 15px;
height: 40px;
}
::-webkit-scrollbar-thumb{
background-color: #DBDBDB;
border: 4px solid transparent;
border-radius: 11px;
background-clip: content-box;
}
::-webkit-scrollbar * {
background: transparent;
}
::-webkit-scrollbar-thumb:vertical {
height: 90px;
}
And I got such result:
So there is a question. How can I do this with CSS or JS maybe.
Thanks
I think this might work:
::-webkit-scrollbar-track {
border-radius: 10px;
background-color: transparent;
}
::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(,0,0,0.5);
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
You might have to edit it according to your need.
here to save the day, you must first add overflow: overlay; to your body tag, works the same as overflow: auto; but it will be on top of the content instead of on its side.
then just add this:
*::-webkit-scrollbar {
background-color: transparent;
width: 12px;
}
*::-webkit-scrollbar-track {
background-color: transparent;
}
*::-webkit-scrollbar-thumb {
border-radius: 20px;
border: 3px solid transparent;
background-color: rgba(0,0,0,0.3);
background-clip: content-box;
}
and adjust the color and the width to your liking, your welcome!

How to create a double outline border?

I am writing my CSS in JS using radium and thus, I can't use pseudo classes :after and :before (which would have been made the solution very simple). How should I create the border as show in the below diagram.
Here, grey border is the same color as the main background color, which is separated by white border.
So far my CSS looks like this
upload: {
position: "absolute",
left: "0",
top: "0",
overflow: "hidden",
width: "100%",
height: "100%",
borderRadius: "50%",
backgroundColor: "#ccdde5",
cursor: "pointer"
}
which will produce the output like this
Try using nested box-shadows:
.circle-border-2 {
border-radius: 50%;
width: 200px;
height: 200px;
margin: 10px;
background-color: #ccdde5;
box-shadow: 0 0 0 5px white,
0 0 0 10px #ccdde5;
}
<div class="circle-border-2"></div>
This approach even allows you to add multible borders:
.circle-unicorn {
border-radius: 50%;
width: 200px;
height: 200px;
margin: 50px;
background-color: white;
box-shadow: 0 0 0 5px #9932FF,
0 0 0 10px #B231FD,
0 0 0 15px #FF31EB,
0 0 0 20px #FF3291,
0 0 0 25px #FE3030,
0 0 0 30px #FE6031,
0 0 0 35px #FFC132,
0 0 0 40px #30FE5B,
0 0 0 45px #5230FF,
0 0 0 50px #3E25BF;
}
<div class="circle-unicorn"></div>
HaNdTriX's answer is a good one.
Another possible solution:
.circle-shadow-border {
border-radius: 50%;
width: 200px;
height: 200px;
background-color: gray;
box-shadow: 0px 0px 0px 5px white inset;
border: solid 5px gray;
margin: 20px;
}
<div class="circle-shadow-border"></div>
Or use background-clip: content-box;:
.circle-border-backclip {
border-radius: 50%;
width: 200px;
height: 200px;
background-color: gray;
margin: 20px;
border: solid 5px gray;
padding: 5px;
background-clip: content-box; /* support: IE9+ */
}
<div class="circle-border-backclip"></div>
for more information you could see https://css-tricks.com/snippets/css/multiple-borders/.
You can do this very easily, by simply adding an background color, padding and solid border.
I created a quick example: https://jsfiddle.net/o81rre69/
.upload {
border-radius: 50%;
padding: 5px;
height: 150px;
width: 150px;
background: #FFF;
border: 3px solid #BBB;
}
Hope it helps!

Prevent box-shadow from appearing below an element's left/right borders?

I'm applying a box-shadow to an element with left and right borders.
I want the box shadow to stop so it doesn't appear underneath those borders.
Is there any way to achieve this without too many crazy wrappers?
<div id="button">Box-shadow, stop before the red borders!</div>
Here's a JSFiddle: http://jsfiddle.net/AHUEY/
You could do this with a pseudo element absolutely positioned relative to your target, instead of a box shadow:
#button {
position: relative;
background: #ccc;
text-align: center;
width: 400px;
border-left: 10px solid red;
border-right: 10px solid red;
}
#button::before {
content: '';
position: absolute;
bottom: -5px;
left: 0;
right: 0;
height: 5px;
background: black;
}
demo
This is possible using the spread parameter of the box shadow.
Please see the working fiddle
http://jsfiddle.net/prashant_11235/dkR4H/
#button {
background: #ccc;
text-align: center;
width: 400px;
height: 25px;
border-left: 10px solid red;
border-right: 10px solid red;
box-shadow: 0px 15px 0px -10px black;
}
Replace border-right and border-left with box-shadow:
#button {
background: #ccc;
text-align: center;
width: 400px;
box-shadow: 10px 0 0 0 red, -10px 0 0 0 red, 0 5px 0 0 black;
}
http://jsfiddle.net/eEnpp/

Stretch div to max size

My css:
#main {
display: block;
top: 0px;
bottom: 0px;
height: auto;
margin-top: 55px;
max-width: 100%;
overflow: scroll;
position: absolute;
}
#content {
background-color: #fff;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-border-radius: 5px;
border: 1px solid #eee;
-moz-box-shadow: inset 0 0 5px #000;
-webkit-box-shadow: inset 0 0 5px #000;
box-shadow: inset 0 0 5px #000;
margin: 5px;
}
What i want:
What i get:
Red = absolute header
White = #main with "blue" scrollbars
Green = #content border with the text in it.
I guess it is quite easy to solve but i still couldnt manage after trying for ages :P
Updated/simplified jsfiddle:
http://jsfiddle.net/YAgW2/9/
Your CSS should be:
#main {
display: block;
top: 0px;
bottom: 0px;
height: auto;
margin-top: 55px;
max-width: auto;
overflow: scroll;
position: absolute;
}
#content {
background-color: #fff;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-border-radius: 5px;
border: 1px solid #eee;
-moz-box-shadow: inset 0 0 5px #000;
-webkit-box-shadow: inset 0 0 5px #000;
box-shadow: inset 0 0 5px #000;
margin: 5px;
width:auto;
}
Use the following CSS:
#main {
display: block;
top: 0px;
bottom: 0px;
height: auto;
margin-top: 55px;
max-width: 100%;
overflow: scroll;
position: absolute;
background-color: green;
}
#content {
white-space: nowrap;
padding: 5px;
color: white;
background-color: red;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-border-radius: 5px;
border: 1px solid #eee;
-moz-box-shadow: inset 0 0 5px #000;
-webkit-box-shadow: inset 0 0 5px #000;
box-shadow: inset 0 0 5px #000;
margin: 5px;
}
And the following HTML:
<div>
<div id="main">
</div>
<div id="content" style="position:absolute">
Try to extend this text
</div>
</div>
Could you not move #content outside of #main and position it where you want, i.e. on top of #main?
Adding float: left; to #content solves the display issue!