I try to make an image slider which will show a picture when a mouse hovers over a dot. I tried too switch between images by using z-index but nothing moved.
.slider {
counter-reset: index 1000;
}
.slider input[name='slide_switch']:hover+label+img {
counter-increment: index;
z-index: counter(index);
}
The way you were trying to use counter wasn't going to work even if you used JavaScript/jQuery. The counter properties are used to number elements like an ordered list it has nothing to do with z-index. The best you can do is to rely on CSS animation which you can see in the following snippet. The key properties were:
transition: all 3s a long duration is needed to view z-index animated.
color: rgba(R, G, B, A) A is an opacity value that can change from totally visible to invisible, plus the levels of transparency between.
position: absolute/relative is not only required for z-index but also helpful for vertical and horizontal dimensions for elements as well.
calc() a function that will apply a simple equation for CSS properties. One of it's best features is that will work with a combination of absolute (e.g. px, pt, etc.) and/or relative (e.g. em, %, etc.) values.
When hovering over a circle, keep the cursor there for 3 sec. Animating z-index is a slow process because at faster speeds the progressive fading won't be noticeable.
Snippet
html {
font: 400 12px/1.2 'Consolas';
}
.slider {
position: relative;
width: 250px;
height: 250px;
}
output {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: all 3s;
display: block;
}
output b {
position: absolute;
font-size: 5rem;
top: calc(125px - 2.5rem);
text-align: center;
display: block;
width: 100%;
}
label {
z-index: 100;
position: relative;
height: 25px;
width: 25px;
padding: 5px;
cursor: pointer;
display: inline-block;
}
label b {
z-index: 100;
position: relative;
height: 15px;
width: 15px;
border: 1px solid #fff;
border-radius: 12px;
cursor: pointer;
margin: 5px;
display: inline-block;
padding: 1px 1px 0;
text-align: center;
color: #fff;
}
#A {
z-index: 10;
background: rgba(190, 0, 0, .5);
}
#B {
z-index: 20;
background: rgba(0, 0, 190, .5);
}
#C {
z-index: 30;
background: rgba(255, 50, 0, .5);
}
#D {
z-index: 40;
background: rgba(50, 200, 50, .5);
}
#E {
z-index: 50;
background: rgba(210, 100, 55, .5);
}
#F {
z-index: 60;
background: rbga(255, 200, 0, .5);
}
#a:hover~#A {
z-index: 70;
transition: all 3s;
background: rgba(190, 0, 0, 1);
}
#b:hover~#B {
z-index: 70;
transition: all 3s;
background: rgba(0, 0, 190, 1);
}
#c:hover~#C {
z-index: 70;
transition: all 3s;
background: rgba(255, 50, 0, 1);
}
#d:hover~#D {
z-index: 70;
transition: all 3s;
background: rgba(50, 200, 50, 1);
}
#e:hover~#E {
z-index: 70;
transition: all 3s;
background: rgba(210, 100, 55, 1);
}
#f:hover~#F {
z-index: 70;
transition: all 3s;
background: rgba(255, 200, 0, 1);
}
label:hover {
background: rgba(255, 255, 255, .1);
color: #000;
}
.top {
z-index: 75;
background: rgba(255, 255, 255, 1);
position: absolute;
width: 250px;
height: 205px;
transition: all 3s
}
label:hover~.top {
z-index: 0;
background: rgba(255, 255, 255, .1);
transition: all 3s
}
hr {
position: relative;
z-index: 101;
}
<fieldset class='slider'>
<label id="a" for="A"><b>A</b></label>
<label id="b" for="B"><b>B</b></label>
<label id="c" for="C"><b>C</b></label>
<label id="d" for="D"><b>D</b></label>
<label id="e" for="E"><b>E</b></label>
<label id="f" for="F"><b>F</b></label>
<hr/>
<output id="A"><b>A</b></output>
<output id="B"><b>B</b></output>
<output id="C"><b>C</b></output>
<output id="D"><b>D</b></output>
<output id="E"><b>E</b></output>
<output id="F"><b>F</b></output>
<div class='top'> </div>
</fieldset>
This is a neat idea, but runs into one or two problems:
The CSS counter() function returns a <string> but the z-index property is looking for an <integer>.
Browsers don't really support it anyway.
The MDN counter() docs note that:
The counter() function can be used with any CSS property, but support for properties other than content is experimental, and support for the type-or-unit parameter is sparse.
It's not completely clear what they mean by "the type-or-unit parameter" since none is discussed on that page. The attr() function does allow returning alternate types (e.g. an integer) via a <type-or-unit> parameter. I wonder if someone was toying with adding the same parameter to counter() at some point; if so, this appears to have been abandoned long ago.
Related
I have an <input type="checkbox" />
I've managed to set things like the border color, but I seem not to be able to set the background-color. It just stays white.
Can anybody offer a solution, I've been looking on this site and others for an answer, but none that I've found work. This is an internal app that will be using the Edge Browser.
It might be overriden by your browser's default settings. Have you tried adding !important to the background-color option?
If that doesn't help, appearance: none; might help, but it removes completely default styles for your input, so you will have to style all the stuff like :checked mark etc.
E: If you just want to change the background color after checking the input, you can use accent-color (https://developer.mozilla.org/en-US/docs/Web/CSS/accent-color)
i am not sure this will work or not but you can give a class name to input and try using :before and :after sudo selectors like
" .yourclassname:checked:after , .yourclassname:checked:before "
Just changing CSS won't work
Trying to set the background on input="checkbox" won't work when just given "background:some_color" because it has default values which will always override.
So we should use a label tag and a div tag to wrap the input tag, wherein input checkbox itself is hidden.
HTML
<label class="contain">
<input type="checkbox"/>
<div class="fake-input"/>
</label>
CSS
.contain *, .contain *::before, .contain *::after {
box-sizing: content-box !important;
}
.contain input {
position: absolute;
z-index: -1;
opacity: 0;
}
.contain {
display: table;
position: relative;
padding-left: 1.8rem;
cursor: pointer;
margin-bottom: .5rem;
}
.contain input[type="checkbox"] ~ .fake-input {
position: absolute;
top: 0;
left: 0;
height: 1.25rem;
width: 1.25rem;
background: rgba(0, 245, 248, 1);
transition: background 250ms;
border: 1px solid rgba(184, 194, 204, 1);
border-radius: 0.125rem;
}
.contain input[type="checkbox"] ~ .fake-input::after {
content: '';
position: absolute;
display: none;
left: .45rem;
top: .18rem;
width: .25rem;
height: .6rem;
border: solid rgba(255, 255, 255, 1);
border-width: 0 2px 2px 0;
transition: background 250ms;
transform: rotate(45deg);
}
.contain input:checked ~ .fake-input::after {
display: block;
}
.contain:hover input ~ .fake-input,
.contain input:focus ~ .fake-input {
background: rgb(10, 38, 43);
}
.contain input:focus ~ .fake-input {
box-shadow: 0 0 0 2px rgba(52,144,220,0.5);
}
.b-contain input:checked ~ .b-input {
background: rgba(0, 130, 243, 1);
border-color: rgba(0, 130, 243, 1);
}
If still are unsure about this, visit Bun.js. My answer is referred from there.
I have a dropdown where the overflow text is gradient out. There's transition applied to the selection's wrapper but now it looks a bit odd when it's hovered out. How can I make it look better?
html snippet:
<div class="durationDropdown">
<select role="listbox" class="durationSelect">
<option value="0">Less than 1 month</option>
</select>
</div>
css snippet:
.container {
width: 150px;
}
.durationDropdown {
padding: 0px;
flex: 1;
text-align: left;
position: relative;
cursor: pointer;
height: 5.1875rem;
transition: 250ms;
border: 1px solid #eee;
}
.durationDropdown::after {
content: "";
display: block;
width: 40px;
top: 0%;
right: 0;
height: 100%;
position: absolute;
background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 63%);
pointer-events: none;
}
.durationDropdown:hover::after,
.durationDropdown:active::after {
background: none;
}
.durationDropdown:hover {
background: black;
}
Here's my fiddle where you can see how it looks like and the rest of the css in the fiddle. Any help/suggestions would be great!
I am afraid you cannot add transition to the gradient, see details here Use CSS3 transitions with gradient backgrounds.
What you really see it's smooth changing of the 'color' property but not the gradient transition. If you want to hide a part of the sentence with a gradient and have a smooth transition on it, you could do like so:
Add transition to 'durationDropdown::after' element and replace 'background: none;' by 'opacity: 0;' like so:
.durationDropdown::after {
...
transition: 250ms opacity ease-in-out;
...
}
.durationDropdown:hover::after,
.durationDropdown:active::after {
/* background: none; */
opacity: 0;
}
I am trying to create a custom cursor that changes when hovering over a <div>, but there is a flicker when moving left to right across it, but not when moving right to left. Why this is happening and what I can do to fix it?
document.addEventListener('mousemove', (ev) => cursorMove(ev));
function cursorMove(ev) {
let circle = document.getElementById('circle');
let posY = ev.clientY;
let posX = ev.clientX;
circle.style.top = posY + 'px';
circle.style.left = posX + 'px';
}
body {
margin: 0;
height: 100vh;
background-color: #acd1d2;
position: relative;
display: flex;
justify-content: center;
align-items: center;
font-family: monospace;
}
#wrapper {
position: relative;
width: 70%;
height: 80%;
}
.box {
height: 25%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
#box-1 {
background-color: #e8edf3;
}
#box-1:hover ~ #circle {
background-color: #e6cf8b;
box-shadow:inset 0em -0.3em 0.4em 0.2em #ca9e03a6;
}
#box-2 {
background-color: #e6cf8b;
}
#box-2:hover ~ #circle {
background-color: transparent;
border: 3px solid #E91E63;
}
#box-3 {
background-color: #b56969;
}
#box-3:hover ~ #circle {
height: 1em;
width: 1em;
background-color: #e6cf8b;
}
#box-4 {
background-color: #22264b;
color: white;
}
#box-4:hover ~ #circle {
background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);
}
#circle {
position: fixed;
border-radius: 50%;
z-index: 5;
height: 32px;
width: 32px;
background-color: white;
}
<div id="wrapper">
<div id="box-1" class="box">Sphere</div>
<div id="box-2" class="box">Circle outline</div>
<div id="box-3" class="box">Circle pin</div>
<div id="box-4" class="box">Circle color gradient</div>
<div id="circle"></div>
</div>
That's because your mouse moves faster than the circle and you hover over it, so the styles that apply to it are the same ones than when the cursor is on the background green/blue-ish area of the page.
You can fix that by adding pointer-events: none to the circle so that it feels a bit like this:
Ok, where were we? Oh yes... So you should use position: fixed instead of absolute (as you really want your cursor to be positioned relative to the top-left corner of the viewport) and probably window.requestAnimationFrame to get a smoother animation and translate3d(0, 0, 0) to promote the element to its own layer and enable hardware-accelerated rendering, which will also contribute to make it feel smoother.
You could also hide the default cursor with cursor: none and center the circle where the arrowhead of the cursor is to make it feel just like a real cursor.
const circle = document.getElementById('circle');
const circleStyle = circle.style;
document.addEventListener('mousemove', e => {
window.requestAnimationFrame(() => {
circleStyle.top = `${ e.clientY - circle.offsetHeight/2 }px`;
circleStyle.left = `${ e.clientX - circle.offsetWidth/2 }px`;
});
});
body {
margin: 0;
height: 100vh;
background-color: #acd1d2;
position: relative;
display: flex;
justify-content: center;
align-items: center;
font-family: monospace;
cursor: none;
}
#wrapper {
position: relative;
width: 70%;
height: 80%;
}
#circle {
position: fixed;
border-radius: 50%;
z-index: 5;
height: 32px;
width: 32px;
background-color: white;
pointer-events: none;
transition:
background ease-in 10ms,
box-shadow ease-in 150ms,
transform ease-in 150ms;
/* Promote it to its own layer to enable hardware accelerated rendering: */
transform: translate3d(0, 0, 0);
}
.box {
height: 25%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
#box-1 {
background-color: #e8edf3;
}
#box-1:hover ~ #circle {
background-color: #e6cf8b;
box-shadow: 0 0 0 0 transparent, inset 0em -0.3em 0.4em 0.2em #ca9e03a6;
}
#box-2 {
background-color: #e6cf8b;
}
#box-2:hover ~ #circle {
background-color: transparent;
/* Use box-shadow instead of border to avoid changing the dimensions of the
cursor, which will make it be off-center until the mouse moves again: */
aborder: 3px solid #E91E63;
box-shadow: 0 0 0 3px #E91E63;
}
#box-3 {
background-color: #b56969;
}
#box-3:hover ~ #circle {
background-color: #e6cf8b;
/* Change its size with scale() instead of width and height for better
performance performance: */
transform: scale(0.5) translate3d(0, 0, 0);
}
#box-4 {
background-color: #22264b;
color: white;
}
#box-4:hover ~ #circle {
background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);
}
<div id="wrapper">
<div id="box-1" class="box">Sphere</div>
<div id="box-2" class="box">Circle outline</div>
<div id="box-3" class="box">Circle pin</div>
<div id="box-4" class="box">Circle color gradient</div>
<div id="circle"></div>
</div>
Here you can see another cool example I made of a custom cursor using CSS that resembles a torch: How to darken a CSS background image but keep area around cursor brighter.
Also, you can check out the cursor on my website, which is quite similar to what you have done as it has animations/transitions between its different shapes or states.
🚀 Check it out here: https://gmzcodes.com/.
👨💻 Check the code here: https://github.com/Danziger/gmzcodes
I'm struggling to set the div width to the remaining width of the container div. In the example below I want the red div (an input) to take as much space as possible. If you enter anything in the input the green div appears, which should always be right aligned.
I don't want to use either flex nor display: table-* or workarounds like setting overflow: hidden for to make space for floats.
EDIT: I'm looking for any solution that works for IE10+ (including display: table-*, etc.)
Example: https://codesandbox.io/s/23xo3wjjrp (Change the template and style tag inside /components/SearchBox.vue for changes)
The example uses vue, but for completeness I post the code here too:
HTML
<div class="ms-Fabric ms-SearchBox" :class="searchBoxStyle">
<div class="ms-SearchBox-iconContainer">
<i class="ms-SearchBox-icon ms-Icon ms-Icon--Search"></i>
</div>
<input class="ms-SearchBox-field" type="text" placeholder="Search"
v-model="searchQuery" ref="input"
#blur="onBlur" #focus="onFocus">
<div class="ms-SearchBox-clearButton" v-show="searchQuery.length > 0"
#click="clear">
<i class="ms-SearchBox-icon ms-Icon ms-Icon--Clear"></i>
</div>
</div>
SCSS
// Active styles
.ms-SearchBox.is-active {
.ms-SearchBox-iconContainer {
width: 4px;
transition: width .167s;
.ms-SearchBox-icon {
opacity: 0;
}
}
}
// Static styles
.ms-SearchBox {
display: inline-block;
font-size: 0px;
font-weight: 400;
color: #333;
border: 1px solid #a6a6a6;
height: 32px;
padding-left: 8px;
width: 208px;
.ms-SearchBox-iconContainer {
font-size: 14px;
color: #106ebe;
transition: width .167s;
.ms-SearchBox-icon {
opacity: 1;
transition: opacity .167s 0s;
}
background: rgba(0, 0, 0, 0.2);
}
.ms-SearchBox-field {
display: inline-block;
font-size: 14px;
margin: 0;
padding: 0;
text-overflow: ellipsis;
overflow: hidden;
border: none;
outline: 1px solid transparent;
height: 32px;
vertical-align: top;
background: rgba(255, 0, 0, 0.2);
}
.ms-SearchBox-iconContainer,
.ms-SearchBox-clearButton {
display: inline-block;
height: 32px;
line-height: 32px;
width: 32px;
text-align: center;
}
.ms-SearchBox-clearButton {
font-size: 14px;
background: rgba(0, 255, 0, 0.2);
&:hover {
cursor: pointer;
}
}
}
You should try to set a width:100% to your input, and to set position:absolute to your icon containers. With paddings on the input, this should do the thing.
Hope I understood the question :)
I have questions about angular-ui-switch (http://ngmodules.org/modules/angular-ui-switch). I would like to let the switch show different background colors based on the name of each object. Below is what I did:
-- I the color defined in the css file as below:
.switch {
background: #fff;
border: 1px solid #dfdfdf;
position: relative;
display: inline-block;
box-sizing: content-box;
overflow: visible;
width: 50px;
height: 30px;
padding: 0px;
margin: 0px;
border-radius: 20px;
cursor: pointer;
box-shadow: rgb(223, 223, 223) 0px 0px 0px 0px inset;
transition: 0.3s ease-out all;
-webkit-transition: 0.3s ease-out all;
top: -1px;
}
.switch small {
background: #fff;
border-radius: 100%;
box-shadow: 0 1px 3px rgba(0,0,0,0.4);
width: 30px;
height: 30px;
position: absolute;
top: 0px;
left: 0px;
transition: 0.3s ease-out all;
-webkit-transition: 0.3s ease-out all;
}
.switch.checked {
background: rgb(100, 189, 99);
border-color: rgb(100, 189, 99);
}
.switch.checked small {
left: 22px;
}
.switch.red
{
background: rgb(187, 2, 2);
}
.switch.primary
{
background: rgb(74, 124, 173);
}
.switch.green
{
background: rgb(16, 124, 42);
}
Here is my Html view:
<div ng-repeat="es in allEventSources track by $index" style="margin-top:5px; vertical-align:middle; line-height:40px">
<span style="float:left; margin-top:8px; font-size:16px;">{{es.name}}:</span>
<span style="float:right; margin-top:8px;"><switch class="{red: es.name=='Boston', primary: es.name=='New York', green: es.name=='Washington' }" ng-model="es.enabled" ng-click="toggleEventSource(es)"></switch></span>
</div>
However, my switch is always ONLY showing the green as the background color. Does any one here know why?
Any help would be great appreciated. Thank you very much :-)
(tested with angular-ui-switch version 0.1.0)
If you edit .switch.checked css class, you will globally alter all switches.
However, you could tweak the style of individual <switch/> with ng-style attribute, in order to override background color resulting from .switch.checked css class being applied to switches in "on" state.
For example:
<switch id="enabled" name="enabled" ng-model="enabled" ng-style="getStyle(enabled, 'red')" />
In your angular controller define a function:
$scope.getStyle = function(enabled, color) {
return {
'background': enabled?color:'white',
'border-color': enabled?color:'white'
}
}