Can we drop CSS property"-webkit-scrollbar" from a single node? - html

How can I drop the CSS property ::-webkit-scrollbar from a single HTML element?
In my CSS file, I have this code:
::-webkit-scrollbar {
width: 6px;
height: 6px;
background-color:transparent;
}
::-webkit-scrollbar-track {
background-color:transparent;
width: 6px;
}
::-webkit-scrollbar-track-piece {
background-color: blue;
}
::-webkit-scrollbar-thumb {
background-color: #d4dee8;
width: 6px;
}
It will replace every scrollbar with webkit scrollbars. But there are two places where I don't need webkit scrollbar, I need normal scrollbars instead.
HTML file:
<td class="viewDialogLabel" height="21" style="width:156px;padding:0px">
<!-- Inner elements --->
</td>
Here, I need to change class viewDialogLabel to normal scrollbars.
How do I get this effect?

WebKit supports the handy CSS value initial, which sets properties back to the values they would have had if no styles applied to the page.
So, you can reset the ::-webkit-scrollbar values you’ve set like this:
.viewDialogLabel::-webkit-scrollbar {
width: initial;
height: initial;
background-color:initial;
}
.viewDialogLabel::-webkit-scrollbar-track {
background-color:initial;
width: initial;
}
.viewDialogLabel::-webkit-scrollbar-track-piece {
background-color: initial;
}
.viewDialogLabel::-webkit-scrollbar-thumb {
background-color: initial;
width: initial;
}
See http://jsfiddle.net/uVGKr/
WebKit also supports the :not() selector, so I would have thought the following amendment to your original CSS would prevent the custom scrollbars from applying to that table cell:
:not(.viewDialogLabel)::-webkit-scrollbar {
width: 6px;
height: 6px;
background-color:transparent;
}
:not(.viewDialogLabel)::-webkit-scrollbar-track {
background-color:transparent;
width: 6px;
}
:not(.viewDialogLabel)::-webkit-scrollbar-track-piece {
background-color: blue;
}
:not(.viewDialogLabel)::-webkit-scrollbar-thumb {
background-color: #d4dee8;
width: 6px;
}
However, it doesn’t work for me in Chrome 16 — the custom scrollbar styles aren’t applied at all (see http://jsfiddle.net/uVGKr/1/). I’m not sure if I’m doing something wrong, if you just can’t combine these selectors, or if this is a WebKit bug.
As per your suggested edit removing the td selectors from the CSS, this seems to be working in Chrome 24 at least: http://jsfiddle.net/uVGKr/2/

You can specify a more accurate selector:
.new-scrollbar::-webkit-scrollbar {
/* ... */
}
Then, only elements with the class new-scrollbar will have the custom scrollbars.
Or you can try to override the properties in specific elements:
.old-scrollbar::-webkit-scrollbar {
background: none;
}
.old-scrollbar::-webkit-scrollbar-track {
background: none;
}
/* ... */
Also try it with different properties / values.

Instead of removing these properties from those two elements you can specify a separate class or ids for these two elements and override the -webkit-scrollbar styles with new ones

Related

Style the HTML5 input type="time" popup window [duplicate]

I'm trying to find a source explaining how to fully style the input type "time". I cannot find a single example explaining all of the style attributes!
Only one I've found is:
input[type="time"]{
/**style goes here **/
}
Which doesn't help much..
Tried this:
input[type="time"]::-webkit-inner-spin-button {
-webkit-appearance: none;
cursor:pointer;
display: block;
width:20px;
color: red;
text-align:center;
position:relative;
}
Spinner does not turn red for example.
I made some progress styling the input in Chrome/webkit, but I can't figure out how to style anything in Firefox. Here's a demo that I put together on Codepen.
input[type=time] {
border: none;
color: #2a2c2d;
font-size: 14px;
font-family: helvetica;
width: 180px;
}
/* Wrapper around the hour, minute, second, and am/pm fields as well as
the up and down buttons and the 'X' button */
input[type=time]::-webkit-datetime-edit-fields-wrapper {
display: flex;
}
/* The space between the fields - between hour and minute, the minute and
second, second and am/pm */
input[type=time]::-webkit-datetime-edit-text {
padding: 19px 4px;
}
/* The naming convention for the hour, minute, second, and am/pm field is
`-webkit-datetime-edit-{field}-field` */
/* Hour */
input[type=time]::-webkit-datetime-edit-hour-field {
background-color: #f2f4f5;
border-radius: 15%;
padding: 19px 13px;
}
/* Minute */
input[type=time]::-webkit-datetime-edit-minute-field {
background-color: #f2f4f5;
border-radius: 15%;
padding: 19px 13px;
}
/* AM/PM */
input[type=time]::-webkit-datetime-edit-ampm-field {
background-color: #7155d3;
border-radius: 15%;
color: #fff;
padding: 19px 13px;
}
/* 'X' button for resetting/clearing time */
input[type=time]::-webkit-clear-button {
display: none;
}
/* Up/Down arrows for incrementing/decrementing the value */
input[type=time]::-webkit-inner-spin-button {
display: none;
}
<input type="time" value="13:30"/>
I wasn't able to find documentation anywhere. I got this far by inspecting the input's internal DOM, hovering over each element in devTools to see what portion of the UI it corresponded to, then grabbed its pseudo attribute.
If you can't currently see the internal DOM, you'll have to expose it by going into Chrome's DevTools Settings, Preferences, Elements and make sure the "Show user agent shadow DOM" option is enabled.
There's another pseudo element: -webkit-calendar-picker-indicator - the clock that shows up in chrome to allow you picking time using a mouse.
input[type="time"]::-webkit-calendar-picker-indicator {
filter: invert(0.5) sepia(1) saturate(5) hue-rotate(175deg);
}
<input type="time">
To style the input type date and time - use the following css -
[type="date"] {
background:transparent url(/assets/images/calendar.png) 97% 50% no-repeat !important;
}
[type="date"]::-webkit-inner-spin-button {
display: none;
}
[type="date"]::-webkit-calendar-picker-indicator {
opacity: 0;
}
[type="time"] {
background:transparent url(/assets/images/clock.png) 97% 50% no-repeat !important;
}
[type="time"]::-webkit-inner-spin-button {
display: none;
}
[type="time"]::-webkit-calendar-picker-indicator {
opacity: 0;
}

How can I customize the browser scroll bar for specific parts in a web page?

I need to reduce the scroll bar width in my web page but not for the whole page. I am using one splitter and a grid in that page if height exceeds scrollbar occurs. How can I reduce the width of it. I have used the following styles
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
But these styles are applying for the whole page. Can anyone suggest me to resolve this issue?
/* width */
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
More information: https://www.w3schools.com/howto/howto_css_custom_scrollbar.asp
One option would be to use a class for parts of the webpage where you want to customize the scroll bar. For that class, let us say class='customScroll', you could define your css code:
.cuctomScroll {
overflow: scroll;
scrollbar-width: 20px; */for Mozilla support/*
}
.customScroll::-webkit-scrollbar {
width: 20px; */for Chrome and IE support/*
}
Edit 1: Here is the working example: https://jsfiddle.net/43o50m6a/6/.
Please feel free to ask any further clarifications.

Transparent background scrollbar displays on top of content

I want to achieve this:
What I already achieve:https://plnkr.co/edit/a3XfJo6Fxtru9V5zpVYR?p=preview
.dropdown-menu { //container
overflow-y: overlay;
background-color: transparent;
}
.dropdown-menu::-webkit-scrollbar {
width:10px;
}
.dropdown-menu::-webkit-scrollbar * {
background:transparent;
}
.dropdown-menu::-webkit-scrollbar-thumb {
background:$blue !important;
border-radius: 6px;
}
Does someone have any ideas how I can do that? How can I make the items stay between their container and the container's scrollbar so they looks like the design?
I tried putting z-index in the elements but seems not to work.
Just switch the unit in body tag from % to vw
and you will get the over content effect.
body {
width: 100vw;
overflow-x: hidden;
}
body::-webkit-scrollbar {
width: 0.7em;
background: transparent;
}
body::-webkit-scrollbar-thumb {
background: #c0392b;
}
http://manos.malihu.gr/jquery-custom-content-scroller/
This plugin works pretty well. Suggested! Easy to modify as well!
Make some changes in your css file use this code
.dropdown-menu::-webkit-scrollbar-track {
background-color: #E0E0E0;
}
remember to remove display: none; property from your code or change it to display: block;

<meter> not working properly in Chrome

I am following this article on creating password strength meter. This is working fine in Firefox but it is not switching colors in the Chrome browser. I tried the accompanied code pen demo too and that also doesn't seem to be working in Chrome browser. Following is CSS styling for the meter element:
meter {
/* Reset the default appearance */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin: 0 auto 1em;
width: 100%;
height: .5em;
/* Applicable only to Firefox */
background: none;
background-color: rgba(0,0,0,0.1);
}
meter::-webkit-meter-bar {
background: none;
background-color: rgba(0,0,0,0.1);
}
meter[value="1"]::-webkit-meter-optimum-value { background: red; }
meter[value="2"]::-webkit-meter-optimum-value { background: yellow; }
meter[value="3"]::-webkit-meter-optimum-value { background: orange; }
meter[value="4"]::-webkit-meter-optimum-value { background: green; }
meter[value="1"]::-moz-meter-bar { background: red; }
meter[value="2"]::-moz-meter-bar { background: yellow; }
meter[value="3"]::-moz-meter-bar { background: orange; }
meter[value="4"]::-moz-meter-bar { background: green; }
Please suggest what might get changed in Chrome which is leading to this behaviour? I tried looking for any change in vendor prifixes but not able to find any.
There was a bug in Chrome at version 52 that caused -webkit-appearance:none; on the meter element to wipe out the coloured bar itself.
https://bugs.chromium.org/p/chromium/issues/detail?id=602928
Removing the -webkit-appearance property from the meter causes the coloured bar to show. Please see the fiddle below for an example:
https://jsfiddle.net/t58fnan9/1/
Edit:
The issue link above shows the issue as fixed. However, it has been re-opened here: https://bugs.chromium.org/p/chromium/issues/detail?id=632510
It actually shows for me perfectly.
update your browser and if you are up to date, clear your cache

How do I vertically align placeholder text in textarea?

I am trying to vertically align the placeholder text in textarea (textbox). I am using textarea instead of text input because I need to use multiple lines.
.textbox1 {
width: 440px;
}
<textarea class="textbox1"name="mytextarea"placeholder="Name"></textarea>
One option is to use line-height:
.textbox1 {
width: 440px;
height:30px;
line-height:30px;
}
.textbox1 {
width: 440px;
height:30px;
line-height:30px;
}
<textarea class="textbox1"name="mytextarea"placeholder="Name"></textarea>
You can also use padding to control the position of the text.
Here's an example using padding-top
.textbox1 {
width: 440px;
padding-top:15px;
}
<textarea class="textbox1"name="mytextarea"placeholder="Name"></textarea>
UPDATE
Since the requirements include multi-line support, I'd recommend setting the top and bottom padding i.e:
.textbox1 {
width: 440px;
height:6px;
padding: 30px 5px;
}
.textbox1 {
width: 440px;
height:60px;
padding: 30px 5px;
}
<textarea class="textbox1"name="mytextarea"placeholder="Name"></textarea>
Instead of using padding-top which will increase the height of the textarea and extra space down use the line-height here is a sample, you can vary the line-height.
textarea::placeholder {
line-height: 90px;
}
you can also use transform property like this:
textarea::placeholder {
transform: translateY(-20px);
}
This works for latest Firefox, IE/Edge, Chrome in pure CSS:
textarea {
width: 440px;
height:600px; /* Note this is the same height as the placeholders line-height */
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
line-height:600px;
}
::-webkit-input-placeholder { /* Webkit */
line-height:600px;
}
:-ms-input-placeholder { /* IE */
line-height:600px;
}
See this fiddle. The key is to set the height of the textarea to the same line-height as the placeholder.
Sadly vertical-align: middle; seems not to be supported yet.
Your best bet is to use padding, as line height will not work over multiple lines.
Additionally, make sure to take into account the line height / font size when calculating your padding.
I guess this is not exactly what you want, But try to look ..
To center it vertically, I multiplied the height of the element to 7.5% and make it line-height.
.textbox1{
width: 440px;
height:100px;
line-height: calc(100 * 7.5%);
}
.textbox1:focus{
line-height: 14px;
}
Check it here. pure CSS jsFiddle
Note: CSS3 calc() function only works on modern browsers. You can manually change/calculate the line-height if you want it to work on older browsers.
or you really have to use jQuery
I made a help of jQuery here jQuery jsFiddle
.textbox1 {
width: 440px;
height:70px
}
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
line-height:70px;
text-align: center;
}
:-moz-placeholder { /* Firefox 18- */
line-height:70px;
text-align: center;
}
::-moz-placeholder { /* Firefox 19+ */
line-height:70px;
text-align: center;
}
:-ms-input-placeholder { /* IE 10+ */
line-height:70px;
text-align: center;
}
You can check here CSS jsfiddle
Use the line-height property to make the placeholder vertically centered.
Just as an alternate solution - you could set the rows to an odd number and add half the rows rounded down in line feed characters to put the placeholder in the middle...
.textbox1 {
width: 440px;
}
<textarea class="textbox1"name="mytextarea"placeholder="
Name" rows=3></textarea>
<textarea name="example" onFocus={onFocus} onBlur={outFocus} />
<label className={styles.Teaxarea_label}>Label</label>
and then you have those functions:
const outFocus = (event) => {
if (event.target.value !== '') {
event.target.nextSibling.style = "display:none;"
}
else {
event.target.nextSibling.style = "display:block;"
}
}
const onFocus = (event) => {
event.target.nextSibling.style = "display:none;"
}
CSS:
.Teaxarea_label{
position: absolute;
user-select: none;
pointer-events: none;
display: block;
}
textarea {
position: relative;
}
To improve on the padding answers, here is a way to guarantee calculations that center it. This works better than line-height for multiple lines, but it still means that once the user enters multiple lines of text, there will now be overflow to scroll, rendering the centering essentially useless
.textbox1 {
--title-modal--textarea--height: 100px;
/* font-size variable for calculations cannot be em, otherwise calculations become doubly-dependent on font-size */
--title-modal--textarea--font-size: 1rem;
--title-modal--textarea--line-height: 1.5;
height: var(--title-modal--textarea--height) !important;
font-size: var(--title-modal--textarea--font-size);
line-height: var(--title-modal--textarea--line-height);
padding-top: calc((var(--title-modal--textarea--height) - (var(--title-modal--textarea--line-height) * var(--title-modal--textarea--font-size)))/2);
/* I used these to make sure the border doesn't take away from the height, */
/* affecting the padding calculation, */
/* but you could similarly turn them into variables and subtract */
border-bottom: 0;
border-top: 0;
}
You can use absolutely positioned placeholder:
textarea::placeholder {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Check this example