Css hover work, but not(:hover) don't do its purpose - html

I would like my hover to make the "hidding" div appear by fading in and then appearing, and when not(:hover) I want it to fade out and then disappear, I've tried this:
.éléments:not(:hover) #hidding {
font-size: 0;
opacity: 0;
transition: opacity 1s, font-size 2s 1s;
}
.éléments:hover #hidding {
background-color: #97e6bc;
width: 20em;
margin: 0 auto;
padding: 1em;
transition: font-size 1s, opacity 2s 1s;
}
<div class="éléments">
<div class="école">
<h3>Where is Charly ?</h3>
</div>
<div id="hidding">
<p>hidding</p>
</div>
<div class="école">
<h3>Where is Charly ?</h3>
</div>
<div id="hidding">
<p>hidding</p>
</div>
<div class="école">
<h3>Where is Charly ?</h3>
</div>
<div id="hidding">
<p>hidding</p>
</div>
</div>
But for an unknown reason the div instantly disappears and only the text seems affected by the :not(:hover), can someone explain me what is happening please?

You cannot have more than one <div id="hidding">. id must be unique at all times. Use <div class="hidding"> instead.
https://www.w3schools.com/hTML/html_id.asp
That being said, it is bad practice to use non-ascii characters in development.
I corrected these issues.
The cause of your problem is that you have some properties which a) are only defined in :hover state (width, padding, margin) and b) which are not defined when it comes to your rules for transition.
The second issue is that your .element:not(:hover) .hidding really should simply just be .elements .hidding. The reason for this is that anything that is defined in .element:not(:hover) .hidding immediately is no longer applied at all when hovering .elements.
.elements .hidding {
background-color: #97e6bc;
font-size: 0;
margin: 0 auto;
opacity: 0;
width: 20em;
transition: all 1s;
}
.elements:hover .hidding {
background-color: #97e6bc;
font-size: 16px;
opacity: 1;
padding: 1em;
transition: all 1s;
}
<div class="elements">
<div class="ecole">
<h3>Where is Charly ?</h3>
</div>
<div class="hidding">
<p>hidding</p>
</div>
<div class="ecole">
<h3>Where is Charly ?</h3>
</div>
<div class="hidding">
<p>hidding</p>
</div>
<div class="ecole">
<h3>Where is Charly ?</h3>
</div>
<div class="hidding">
<p>hidding</p>
</div>
</div>

There are multiple problems with your code, as noticed by many others:
Firstly, as connexo said, ids must be unique. Use class instead.
Secondly, as Temani Afif said, you shouldn't use special charactors like é. It's a bad coding practice that may cause errors.
The .elements:not(:hover) isn't a good idea for many reasons.
Don't put inanimate properties, like background-color, into a :hover Pseudo class.
You're trying to animate the transition property. This might be the source of most of your glitches.
But importantly, the use of .elements:not(:hover) is nonexistent. It seemes what you are trying to achieve is just .elements itself. The :not(:hover) is implied I guess. You should put all your default css formatting in .elements itself, including all your transitions. Put only properties you want to animate on :hover in the hover Pseudo class.
W3Schools: CSS Pseudo-classes
.elements .hidding {
height: 0;
width: 15em;
opacity: 0;
margin: 0 auto;
overflow: hidden;
box-sizing: border-box;
background-color: #97e6bc;
transition: opacity 1s, height 1s ease-out, width 1s ease-out;
}
.elements .hidding>p {
display: block;
padding: 1em;
margin: 0;
}
.elements:hover>.ecole>.hidding {
width: 20em;
height: 3em;
opacity: 1;
}
<div class="elements">
<div class="ecole">
<h3>Where is Charly ?</h3>
<div class="hidding">
<p>hidding</p>
</div>
</div>
<div class="ecole">
<h3>Where is Charly ?</h3>
<div class="hidding">
<p>hidding</p>
</div>
</div>
<div class="ecole">
<h3>Where is Charly ?</h3>
<div class="hidding">
<p>hidding</p>
</div>
</div>
</div>
I wouldn't animate the transition property, (I don't even think it's remotely possible). You might have better luck with CSS animations.

It works but you have written opacity 2s 1s;. This means opacity starts to be 1 after 1 seconds in 2 seconds of transition.
This is not the correct way. Use .elements #hidding{ instead. Then .elements:hover #hidding{. This question if full of wrongs :). Try to learn better before asking jsfiddle.net/90v2yLq8

Related

How can I switch a background image in separate div using only CSS

I'm having difficulty making one background-image transition to another using only CSS. What I'm trying to accomplish --> click on the .carrier1 or .carrier2 divs in the left column, the larger background-image of .map-block in the right column will change to another background-image corresponding to that carrier div.
Below is the code I've come up with so far. Not sure if it's written correctly as far as functionality goes. For the sake of not dealing with background images, I've substituted the images with colors.
HTML -
<div id="logistics">
<div id="carriers">
<div class="carrier1" tabindex="1">
<img src="#" title="logo1" />
</div>
<div class="carrier2" tabindex="2">
<img src="#" title="logo2" />
</div>
</div>
<div id="map">
<div class="map-block"></div>
</div>
</div>
CSS -
.carrier1:focus,
.carrier2:focus {
outline:none;
}
.carrier1:hover,
.carrier2:hover {
cursor: pointer;
}
#map > .map-block {
display:block;
width:100px;
height:100px;
background-color:blue;
}
#carriers > .carrier1:focus ~ #map > .map-block {
background-color:red;
transition: ease-in-out 1s;
}
#carriers > .carrier2:focus ~ #map > .map-block {
background-color:yellow;
transition: ease-in-out 1s;
}
Any assistance will be greatly appreciated. Thanks guys.
What you're asking for can't be done... without modifying your HTML. Unfortunately, there is no parent selector in CSS. Thus, there is no way to target your #map from within #carriers. You are correctly making use of the tilde (~) selector to target the next relevant element, but this can only target siblings, and thus will only work from the same parent.
Essentially, this can only be solved with pure CSS by shifting #map inside #carriers:
#carriers > .carrier1:focus ~ #map > .map-block {
background-color: red;
transition: ease-in-out 1s;
}
#carriers > .carrier2:focus ~ #map > .map-block {
background-color: yellow;
transition: ease-in-out 1s;
}
<div id="logistics">
<div id="carriers">
<div class="carrier1" tabindex="1">
<img src="#" title="logo1" />
</div>
<div class="carrier2" tabindex="2">
<img src="#" title="logo2" />
</div>
<div id="map">
<div class="map-block">test</div>
</div>
</div>
</div>
Hope this helps! :)

CSS Grayscale image cannot get header to be a different colour

I am having issues in setting the colour of my header h2 that is on top of a image that I am setting to grayscale. I want it to be orange but as I have added grayscale it is overriding my css to make the h2 text grey.
My html code is the following:
<div id="thumbnails" class="pt-page pt-page-current">
<div class="scalediv">
<div class="row no-gutter" data-id="one">
#for (var i = 0; i < Model.Count; i++)
{
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<figure class="callpost" data-num="#Model.Article[i].DataNumber" style="background-image: url('#String.Format("data:image/png;base64,{0}", Convert.ToBase64String(#Model.Article[i].Picture.Image))');" data-property="border-width" data-from="0" data-to="35px">
<div class="content">
<div class="content-wraper">
<h2>#Model.Article[i].Title</h2>
<div class="excerpt">#Model.Article[i].IntroText</div>
<div class="postinfo"> ARTICLES <span>#Convert.ToDateTime(Model.Article[i].DateCreated).ToString("dd/MM/yyyy")</span> </div>
</div>
</div>
</figure>
</div>
}
<div class="clear"></div>
</div>
</div>
This is my CSS for the grayscale:
#thumbnails figure {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
#thumbnails figure:hover {
-webkit-filter: grayscale(0);
filter: none !important;
}
I have tried adding to the css like this:
#thumbnails figure h2{
color: #DD2C00 !important;
}
This is my CSS for the header:
figure .content h2 {
color: #DD2C00;
font-family: FuturaBT-Medium;
font-size: 40px;
font-weight: normal;
letter-spacing: 0;
line-height: 47px;
margin-bottom: 20px;
}
Along with other attempts and trying to change the CSS for the h2 but I cannot get the header to display in orange while the image is in gray scale.
Any ideas or pointers would be really appreciated.
Your code does not work, because the filters are calculated after the DOM rendering. Therefore, !important will have no effect.
To disable the filter effect to h2, you need to bring it out. You can visually put h2 on the figure in different ways, such as a negative margin.
Example:https://jsfiddle.net/j9fbc0sw/3/
Sorry for my English)

Apply CSS Filter to all but specific sub-elements

I need a CSS filter to apply to all elements in a container, except for specific ones. Quick example to explain the situation:
<div class="container">
<img class="one" src="blah" />
<img class="two" src="blah" />
<img class="three" src="blah" />
</div>
Then I am applying filters as so:
.container {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
}
So the container has the greyscale filter applied to it, and all img in it are turned to grey. However, I want one of the img to not turn to grey:
.two {
-webkit-filter: grayscale(0);
filter: grayscale(0);
}
However, this is not working. The filter of the container seems to be overriding the filter of the contained element.
Any ideas how I can get around this? Is there an easy way, or do I have to write up some jQuery to look at all the elements that aren't ".two" and apply the filter to them, rather than the container?
Update: I neglected to mention an important caveat: The container has to be greyscale, due to it having a background-image property that is to also be turned grey. This little snippet is part of more containers that are all going greyscale as well, I'm really just trying to figure out if there's a way to have an overriding exemption to the rule on the parent, since the parent has to have the rule as well.
According to CSS specifity rules -
Either put the .two after the .container in the css,
Or make the .two more specific, i.e. img.two
UPDATE
The .container rule is on the div itself - not on the images. So the container goes grayscale regardless of what you tell the images to do. Try changing that into .container img, and then try incorporating the answers you received.
use > to specify an image that is a child of .container the use not: to specify that you don't want the second image grey
.container > img:not(.two) {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
}
<div class="container">
<img class="one" src="http://lorempixel.com/400/200" />
<img class="two" src="http://lorempixel.com/400/200" />
<img class="three" src="http://lorempixel.com/400/200" />
</div>
jsfiddle
.container > img:not(.two) {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
}
Use :not to exclude .two
The negation CSS pseudo-class, :not(X), is a functional notation taking a simple selector X as an argument. It matches an element that is not represented by the argument. X must not contain another negation selector.
.container img:not(.two) {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
}
Seven years after this question was asked, I thought I'd come up with a brilliant CSS-native solution to this, using:
calc()
CSS Custom Properties
Hours of experimenting with CSS filter have satisfied me that the solution will never work.
Why not? Because functions like filter: hue-rotate() are both more complicated than you might expect and also, unhelpfully, unreliable.
My first ("clever") solution
(Calculate reverse transformations - cute, but doesn't work)
The starting point of my "clever" solution was:
It's well-established that once you apply filter to a parent element, that filter (much like opacity) continues to apply to all descendant elements and there is no way to mask a descendant element from that filter.
But filter simply describes transformations, right? And - surely - anything transformed can be un-transformed via a transformation which represents a mirror-image of the original?
Furthermore, if the original transformation is built in the right way from CSS Custom Properties, then it ought to be possible to build the mirror-image transformation using the same CSS Custom Properties and calc().
So I came up with something like this:
/*
OTHER CSS CUSTOM PROPERTIES (NOT NECESSARY FOR THIS EXAMPLE)
.square[data-theme="green"] {
--saturation: 1;
--contrast: 0.775;
--brightness: 1.2;
}
.square[data-theme="blue"] {
--saturation: 1;
--contrast: 0.775;
--brightness: 1.2;
}
.filter {
--lightness: contrast(var(--contrast)) brightness(var(--brightness));
--hsl-filter: hue-rotate(var(--hue)) saturate(var(--saturation)) var(--lightness);
}
.no-filter {
--reverse-lightness: contrast(calc(1 / var(--contrast))) brightness(calc(1 / var(--brightness)));
--reverse-hsl-filter: hue-rotate(calc(0deg - var(--hue))) saturate(calc(1 / var(--saturation))) var(--reverse-lightness);
}
*/
h2 {
position: absolute;
top: 0;
left: 0;
z-index: 6;
margin: 2px 0 0 2px;
padding: 0;
color: rgb(255, 255, 255);
font-size: 12px;
font-family: sans-serif;
font-weight: 700;
}
.square {
position: relative;
float: left;
display: inline-block;
width: 92px;
height: 92px;
margin: 2px;
padding: 6px;
background-color: rgb(191, 0, 0);
box-sizing: border-box;
}
.square:nth-of-type(4) {
clear: left;
}
.circle {
width: 80px;
height: 80px;
padding: 30px;
background-color: rgb(255, 0, 0);
border-radius: 50%;
box-sizing: border-box;
}
.inner-square {
width: 20px;
height: 20px;
background-color: rgb(255, 127, 0);
}
.square[data-theme="green"] {
--hue: 112.5deg;
}
.square[data-theme="blue"] {
--hue: 212.5deg;
}
.filter {
--hsl-filter: hue-rotate(var(--hue));
filter: var(--hsl-filter);
}
.no-filter {
--reverse-hsl-filter: hue-rotate(calc(0deg - var(--hue)));
filter: var(--reverse-hsl-filter);
}
<div class="square">
<h2>Original</h2>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
<div class="square filter" data-theme="green">
<h2>Filtered</h2>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
<div class="square filter" data-theme="green">
<h2>No-Filter Test</h2>
<div class="circle no-filter">
<div class="inner-square"></div>
</div>
</div>
<div class="square">
<h2>Original</h2>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
<div class="square filter" data-theme="blue">
<h2>Filtered</h2>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
<div class="square filter" data-theme="blue">
<h2>No-Filter Test</h2>
<div class="circle no-filter">
<div class="inner-square"></div>
</div>
</div>
It's less obvious in the top row (at first glance), but in the second row, the last square (ie. bottom right) clearly shows how this reverse-transformation approach is neither robust nor reliable:
The orange square in the bottom-right square isn't perfect, but it's close enough to the original
The orange square in the top-right square is less perfect, but it's still passable (just about)
The red circle in the top-right square isn't perfect, but it's close enough to the original
The red circle in the bottom-right square is no good at all
My second (less clever) solution
(Make the non-filtered element a sibling instead of a descendant element - less clever but it does work)
We may conclude from the above that the matrix transformation initiated by filter: hue-rotate() cannot be easily reversed - and that even if a computational way to reverse it consistently via JavaScript can be found - I'm currently doubtful over whether even that is possible - it's almost certainly not going to be possible via CSS calc().
Alternatively, we can turn the descendant elements we don't want to be affected by the filter into siblings of the element which has the CSS filter applied to it, instead:
h2 {
position: absolute;
top: 0;
left: 0;
z-index: 6;
margin: 2px 0 0 2px;
padding: 0;
color: rgb(255, 255, 255);
font-size: 12px;
font-family: sans-serif;
font-weight: 700;
}
.container {
position: relative;
float: left;
display: inline-block;
width: 92px;
height: 92px;
margin: 2px;
background-color: rgb(0, 0, 0);
box-sizing: border-box;
}
.container:nth-of-type(4) {
clear: left;
}
.square {
width: 92px;
height: 92px;
background-color: rgb(191, 0, 0);
}
.circle {
position: absolute;
top: 0;
left: 0;
width: 80px;
height: 80px;
margin: 6px;
padding: 30px;
background-color: rgb(255, 0, 0);
border-radius: 50%;
box-sizing: border-box;
}
.inner-square {
width: 20px;
height: 20px;
background-color: rgb(255, 127, 0);
}
.container[data-theme="green"] {
--hue: 112.5deg;
}
.container[data-theme="blue"] {
--hue: 212.5deg;
}
.filter {
--hsl-filter: hue-rotate(var(--hue));
filter: var(--hsl-filter);
}
<div class="container">
<h2>Original</h2>
<div class="square"></div>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
<div class="container" data-theme="green">
<h2>Filtered</h2>
<div class="square filter"></div>
<div class="circle filter">
<div class="inner-square"></div>
</div>
</div>
<div class="container" data-theme="green">
<h2>No-Filter Test</h2>
<div class="square filter"></div>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
<div class="container">
<h2>Original</h2>
<div class="square"></div>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
<div class="container" data-theme="blue">
<h2>Filtered</h2>
<div class="square filter"></div>
<div class="circle filter">
<div class="inner-square"></div>
</div>
</div>
<div class="container" data-theme="blue">
<h2>No-Filter Test</h2>
<div class="square filter"></div>
<div class="circle">
<div class="inner-square"></div>
</div>
</div>
This second solution works perfectly, but it requires the HTML to be restructured and the CSS adjusted to compensate:
the filtered element from the original setup needs to be placed within a container element
the non-filtered descendant of the filtered element now needs to become a sibling of the filtered element, within the same container
finally, the non-filtered sibling needs to be re-positioned within the container so that it displays in the same place as before, back when it was a descendant
After taking some time to re-arrange markup and re-adjust styles, we can achieve the originally intended effect with some elements filtered and other elements non-filtered.
This second approach feels much less elegant than calculating mirror-image colour-transformations via CSS Custom Properties and calc() but until some kind of filter mask like:
filter-apply: all | none // or even (2 - n), (n + 3) etc.
is introduced into CSS...
... the only way for a child-element to be masked from a filter is to turn the child-element into a sibling-element.

Elements with opacity < 1 not rendering in chrome when not in first column

I have a site that gets divided into multiple columns. Whenever an element is not in the first column and has opacity set to < 1, it doesn't get rendered when its container has both the overflow y and border radius properties.
Shown in this fiddle
css
.main {
-webkit-column-width: 100px;
column-width: 100px;
max-height: 200px;
}
.main > div {
overflow-y:auto;
border-radius: 6px;
}
.opac {
opacity: 0.5;
}
html
<div class="main">
<div>
<div class="opac">element 1</div>
</div>
<div>
<div class="opac">element 2</div>
</div>
...
<div>
<div class="opac">element 30</div>
</div>
</div>
I'm using chrome 40.0.2214.94 (64-bit) on OSX 10.10.1. Works in Firefox.
That looks like a rendering bug. For now you can mitigate the effect by applying will-change: opacity to the parent elements:
.main > div {
overflow-y:auto;
border-radius: 6px;
will-change: opacity;
}
http://jsfiddle.net/yx1cp9f8/
Anther workaround apparently is to set the opacity on the parent element:
<div class="main">
<div class="opac">
<div >element 1</div>
</div>
<div class="opac">
<div >element 2</div>
</div>
...
<div class="opac">
<div >element 30</div>
</div>
Seems to work. (you seem to have forgotten to close your divs, so I did that as well)
Since the issue in chrome doesn't seem like it will be fixed anytime soon and the will-change: opacity fix doesn't allow pointer/click events, I've decided to just calculate what the rgb values would be with the desired opacity and hard code them in CSS.
I was using the opacity for disabled buttons and was only using a few of the bootstrap button types for this particular case, so it's not too bad of a hack.
.btn.btn-success[disabled] {
opacity: 1;
background: rgb(141, 194, 141);
}
.btn.btn-info[disabled] {
opacity: 1;
background: rgb(120, 187, 206);
}

what is the code for reset the text field form?

I want to set a button which allow the user to reset the contact form, is there any method to do it?
here is my coding for text field
<div style="float:left;width:600px;"><!--textfield-->
<div style="float:left;">
<div style="float:left;width:90px;padding-top:5px">
NAME
</div>
<div style="float:left;padding-top:4px">
:
<input type="text" class="textfield"/>
</div>
</div>
<div style="float:left;padding-top:8px;">
<div style="float:left;width:90px;padding-top:5px">
EMAIL ADDRESS
</div>
<div style="float:left;padding-top:2px">
:
<input type="text" class="textfield"/>
</div>
</div>
<div style="float:left;padding-top:8px;">
<div style="float:left;width:90px;padding-top:5px">
CONTACT NUMBER
</div>
<div style="float:left;padding-top:2px">
:
<input type="text" class="textfield"/>
</div>
</div>
<div style="width:120p;float:left;padding-top:8px;">
<div style="float:left;width:90px;padding-top:5px">
MESSAGE
</div>
<div style="float:left;padding-top:2px">
:
</div>
<div style="float:left;margin-left:3px;padding-top:2px;">
<textarea cols="48" rows="6" class="textfield"></textarea>
</div>
</div>
</div><!--textfield-->
</div><!--end leave your personal details-->
<div style="clear:both"></div>
<div>
<div id="buttonreset"><!--buttonreset-->
<img src="img/buttonreset1.png" width="54" height="24" alt="reset" />
</div><!--end.buttonreset-->
<div id="buttonsend"><!--buttonsend-->
<img src="img/buttonsend1.png" width="54" height="24" alt="send" />
</div><!--end.buttonsend-->
</div>
Css
.textfield {
font-family: CenturyGothic;
font-size: 12px;
color: #231F20;
resize: none;
text-align: left;
}
textarea {
border: thin solid #221F1F;
border-radius: 5px;
width: 430px;
height: 160px;
opacity: 0.8;
}
input {
border: thin solid #221F1F;
border-radius: 4px;
width: 430px;
height: 21px;
opacity: 0.7;
}
#buttonreset {
margin-top: 5px;
background-image: url(../img/buttonreset.png);
background-repeat: no-repeat;
height: 24px;
width: 54px;
margin-top: 10px;
margin-left: 410px;
float:left;
}
#buttonreset img {
-webkit-transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-o-transition: opacity .5s ease-in-out;
transition: opacity .5s ease-in-out;
opacity:0;
}
#buttonreset img:hover {
opacity:1;
cursor:pointer;
-webkit-animation-duration: 1s;
-webkit-animation-timing-function: linear;
Chrome, and Safari */
}
I haven't add any coding to my button, what code suitable for my button?
this is my fiddle:
http://jsfiddle.net/K5CJ4/
<input type='reset'>
is the easiest method.
[Edit]
Since you're trying to reset the form using an image, the easiest way is to use the reset() method in Javascript. (No need for a library like jQuery). To accomplish this, I simply added a bit of javascript to your <a> tag in your form, as well as wrapped the entire example in <form></form> tags, giving it an id of contactForm .
DEMO
use jQuery way to solve it. like this :
$("#buttonreset").click(function() { // div's id
$("#txtField1").val("");
$("#txtField2").val("");
});
Try to use :
<button type="reset" id="btnreset" value="Reset">Reset</button>
The button is a reset button (resets the form-data to its initial values)
#btnreset {
background-image: url("http://www.ricksdailytips.com/wp-content/uploads/2013/11/reset-button.gif");
border: 0 none;
height: 204px;
width: 200px;
}
If you want to automate this, you could set it such that the page refreshes the entire page after a given number of seconds. use the meta tag:
<meta http-equiv="refresh" content="(enter number of seconds before refresh);url=thispage.html" />