What i'm trying to do is trigger a single style that contains transitions from two different styles both being mouse hover events.
I can use it using 1 of the 2 trigger styles but not both.
Example:
<div id="widget"></div>
<div id="tri" class="ibox">
<form id="trif" action="" method="get">
<input id="ipbox" type="text" name="i1" value="trialbox">
</form>
</div>
and CSS :
#widget {
position:absolute;
height:100px;
width:100px;
background-color:red;
}
#ipbox {
background-color:transparent;
position:absolute;
left:110px;
border:3px solid black;
padding-left:10px;
margin:0px;
height:40px;
width:300;
}
#widget img {
position:absolute;
top:40%;
left:45%;
width:100px;
height:100px;
-webkit-transform:scale(1, 1);
-webkit-transition-duration: 2s;
}
#widget:hover {
-webkit-transform:scale(4, 1.5);
-webkit-transition-duration: 1s;
}
#tri {
position:absolute;
opacity:0;
}
#widget:hover + #tri {
-webkit-transition-function:ease-out;
-webkit-transition-duration:3s;
-webkit-transition-delay:0.5s;
opacity:1;
}
with this piece of code i can trigger the transition of shape change and text box opacity. but after this i want to hover over the textbox and keep the changed shape of the box. I hope i'm clear with my question. Excuse any mistakes. Thanks in advance.
the running version : http://jsfiddle.net/ftBrW/
widget should #wrap #tri
So you keep hovering it.
#tri should be at opacity 1 by defaut and turned to zero onload.
With animation like :
#tri {animation : onloadifavailable 0s infinite ;}
#keyframes onloadifavailable {
0,100% {opacity:0;}
}
Then when you hover, #widget, you change animation name .
For hover :
#widget:hover #tri {
animation: showit 3s ;
}
#keyframes showit {
0% {opacity:0;}
100% {opacity:1}
}
HTML:
<div id="widget">
<div id="tri" class="ibox">
<form id="trif" action="" method="get">
<input id="ipbox" type="text" name="i1" value="trialbox">
</form>
</div>
</div>
What is important is not to set by defaut #tri at opacity:0; from the beginning. Keep in mind that a browser may not support animation.
Change this: #widget:hover + #tri to this: #tri:hover
Related
Codepen: https://codepen.io/codepenuserpro/pen/wvyVLLj
<div class="container">
<div id="ease" class="move"><div>Ease (Default)</div></div>
<div id="linear" class="move"><div>Linear</div></div>
<div id="ease-in" class="move"><div>Ease In</div></div>
<div id="ease-out" class="move"><div>Ease Out</div></div>
<div id="ease-in-out" class="move"><div>Ease In Out</div></div>
</div>
.container
{
width:90vw;
border:1px solid red;
margin:0 auto;
}
.move
{
margin:2rem;
width:150px;
height:50px;
padding:10px;
background-color:darkred;
text-align:center;
color:white;
border-radius:0.5rem;
font-size:20px;
transition:translateX() 2s;
}
#ease { transition-timing-function:ease; }
#linear { transition-timing-function:linear; }
#ease-in { transition-timing-function:ease-in; }
#ease-out { transition-timing-function:ease-out; }
#ease-in-out { transition-timing-function:ease-in-out; }
.move:hover
{
transform:translateX(calc(79vw));
}
Strange thing is, when you hover over the buttons, the animation looks jumpy and weird.
But when I set the 'transition:translateX() 2s' to 'transition:all 2s' instead, it works!
What causes this?
change the ❌ transition:translateX() 2s; to ✅ transition: transform 2s;
bacause translateX(); is not a css property
here is a list of valid CSS properties https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Properties_Reference
I have 9 divs inside a flex container.
What I'm trying to achieve is an effect where the div you're hovering over 'pushes' the divs on the right further right and the divs on the left further left. I'd like to do this using nth-child selector so that I only have to write 2 styles for each div.
For now, I just have it partialy working on the red div as a proof of concept.
Achieving the first part was easy, when you hover over the red div, the 4 divs to the right of it are pushed to the right using translateX(30px)
That css looks like this.
.team-card:nth-child(5):hover ~ .team-card:nth-child(n+4){
transform: translateX(30px);
}
Per this article on css tricks, https://css-tricks.com/useful-nth-child-recipies/, doing the first 4 should also be easy.
.team-card:nth-child(5):hover ~ .team-card:nth-child(-n+4){
transform: translateX(-30px);
}
But this doesn't work. I've tried removing the first css selector, thinking that maybe you couldn't have more than a single hover psuedo-state on a class. But that didn't do anything.
Then I removed the hover state so I just had this.
.team-card:nth-child(-n+4){
background-color:yellow;
}
And that worked. So does nth-child using -n not work when it has a psuedo-state?
Is there a pure css solution to achieve this effect when hovering? Or will I have to resort to javascript?
EDIT:
Here is the fiddle that I forgot to link to.
https://jsfiddle.net/q0x51kmw/1/
You can do this very simply, without the transform property:
.team-cards-container {
display: flex;
margin: 55px 2.5%;
height: 300px;
}
.team-card {
flex: 1;
transition: all .2s ease-in-out;
}
.team-card:hover {
margin-right: 30px;
}
/*Colors*/
.team-card:nth-child(3n+1) {background-color: #949300}
.team-card:nth-child(3n+2) {background-color: #8A1B61}
.team-card:nth-child(3n+3) {background-color: #236192}
.team-card:nth-child(5) {background: #ff0000}
<div class="team-cards-container">
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
</div>
Is this what you mean?
.team-cards-container hover moves all children -30px
current (child) .team-card hover overwrites to 0px
all next siblings to current .team-card hover are overwritten +30px
.team-cards-container{
display:flex;
width:95%;
margin-left:auto;
margin-right:auto;
padding-top:55px;
}
/*Colors*/
.team-card:nth-child(3n+1){
height:300px;
width:230px;
background-color:#949300;
}
.team-card:nth-child(3n+2){
height:300px;
width:230px;
background-color:#8A1B61;
}
.team-card:nth-child(3n+3){
height:300px;
width:230px;
background-color:#236192;
}
/*Middle*/
.team-card:nth-child(5){
background:red;
}
/*Universals*/
.team-card{
transition: all .2s ease-in-out;
}
.team-cards-container:hover .team-card {
transform: translateX(-30px);
}
.team-cards-container .team-card:hover {
transform: translateX(0);
}
.team-card:hover ~ .team-card {
transform: translateX(30px);
}
<div class="team-cards-container">
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
<div class="team-card"></div>
</div>
css do not allow you to style previous sibling element. You are using '~' but '~' can only be used to style next sibling elements
you are doing it the wrong way
replace your css with this
.team-cards-container{
display:flex;
width:95%;
margin-left:auto;
margin-right:auto;
padding-top:55px;
}
/*Colors*/
.team-card:nth-child(3n+1){
height:300px;
width:230px;
background-color:#949300;
}
.team-card:nth-child(3n+2){
height:300px;
width:230px;
background-color:#8A1B61;
}
.team-card:nth-child(3n+3){
height:300px;
width:230px;
background-color:#236192;
}
/*Middle*/
.team-card:nth-child(5){
background:red;
}
/*Universals*/
.team-card{
transition: all .2s ease-in-out;
}
.team-cards-container:hover > .team-card{
transform:translateX(-20px);
}
.team-card:hover{
transform:translateX(0px)!important;
}
.team-card:hover~.team-card{
transform:translateX(20px)!important;
}
I was wondering it it is possible to use a nested ":target" directive to modify elements on the page with pure CSS. I am bringing in a form text area which is absolutely positioned inside a div element (.container). When the text area appears, I want 3 things:
1) The open link to dissapear
2) The close link to appear
3) The contaner div to expand with the form element
I have been trying this by nesting the :target element inside my .container but it is not working. Is this possible?
<div class="container" id="container">
<h4>Show close</h4>
<div id="comments">
<form name="myForm">
<p>Write your comment:<br />
<textarea name="myTextarea"></textarea></p>
</form>
</div>
</div>
CSS
.container{
position:relative;
background:pink;
&:target {
transition: all 1s ease;
a#open { display: none; }
a#close {display: block;}
}
a#close { display: none; }
}
#comments {
position:absolute;
height:200px;
width:400px;
background:yellow;
left:-300%;
top:30px;
transition: all 1s ease;
}
#comments:target {
transition: all 1s ease;
left:20px;
}
JSFiddle here
I have this little CSS3 animation going on in my webapp, its a panel in the bottom left side of the screen. I use Linux so I can't try out the animations in Safari, however my project leader is of course a Mac user and he complained right away it didn't work.
So, here are my two files. I'll paste everything in here that I'm working on, and in the bottom I have a jsfiddle that tried to reproduce it with plain css and fewer HTML tags. :)
Here's the less file.
.panel {
position:absolute;
left:20px;
bottom:20px;
background-image : url("./images/filter_bg.png");
width:476px;
height:126px;
z-index:1;
cursor:pointer;
}
.filter {
position:relative;
float:left;
z-index: 2;
width:119px;
height:119px;
vertical-align:24px;
overflow:hidden;
&.activeLive {
background-image: url("./images/filter_active1.png");
}
&.activeSee {
background-image: url("./images/filter_active2.png");
}
&.activeEat {
background-image: url("./images/filter_active3.png");
}
&.activeDo {
background-image: url("./images/filter_active4.png");
}
}
.filter:hover > .filter-hover {
position:absolute;
height:34px;
width:119px;
-moz-transition:-moz-transform 180ms;
-webkit-transition:-webkit-transform 180ms;
-o-transition:-o-transform 180ms;
transition:transform 180ms;
background-image:url("./images/filter_hoverlabel_bg.png");
}
.filter:hover > .filter-hover {
transform: translate(0,-24px);
}
.filter-hover{
position: relative;
bottom:-26px;
text-align:center;
line-height: 32px;
}
.filter-icon{
width:68px;
height:68px;
margin: 24px auto auto;
&.inactive1{
background-image:url("./images/filter_icon1_inactive.png");
}
&.inactive2{
background-image:url("./images/filter_icon2_inactive.png");
}
&.inactive3{
background-image:url("./images/filter_icon3_inactive.png");
}
&.inactive4{
background-image:url("./images/filter_icon4_inactive.png");
}
&.active1{
background-image:url("./images/filter_icon1_active.png");
}
&.active2{
background-image:url("./images/filter_icon2_active.png");
}
&.active3{
background-image:url("./images/filter_icon3_active.png");
}
&.active4{
background-image:url("./images/filter_icon4_active.png");
}
}
.filter-text{
text-align:center;
}
It adds a class to the divs when clicked upon, I use angular for this. So don't care to much about that.
<div class="panel" ng-controller="PanelCtrl">
<div class="{{liveEnabled ? 'filter activeLive' : 'filter'}}" ng-click="liveButton()">
<div class="{{liveEnabled ? 'filter-icon active1' : 'filter-icon inactive1'}}"></div>
<div class="filter-hover">
Bo
</div>
</div>
<div class="{{seeEnabled ? 'filter activeSee' : 'filter'}}" ng-click="seeButton()">
<div class="{{seeEnabled ? 'filter-icon active2' : 'filter-icon inactive2'}}"></div>
<div class="filter-hover">
<span class="filter-text">Se</span>
</div>
</div>
<div class="{{eatEnabled ? 'filter activeEat' : 'filter'}}" ng-click="eatButton()">
<div class="{{eatEnabled ? 'filter-icon active3' : 'filter-icon inactive3'}}"></div>
<div class="filter-hover">
<span class="filter-text">Äta</span>
</div>
</div>
<div class="{{doEnabled ? 'filter activeDo' : 'filter'}}" ng-click="doButton()">
<div class="{{doEnabled ? 'filter-icon active4' : 'filter-icon inactive4'}}"></div>
<div class="filter-hover">
<span class="filter-text">Göra</span>
</div>
</div>
</div>
I made this fiddle: http://jsfiddle.net/j97ahnkv/ wich tries to show out what I'm trying to do.
It's not working in Safari because it still requires the -webkit prefix on transform.
You have to add it to this rule:
.filter:hover > .filter-hover {
-webkit-transform: translate(0, -24px);
transform: translate(0,-24px);
}
I'm trying to position a checkbox at the bottom right of a div container. The container will grow in height on hover, and I want the checkbox to be sticky so that it remains at the bottom right as the div grows.
I'm having some real trouble getting the checkbox to be in the bottom right.
Here's my code, and a Fiddle.
<div class="objectWrap">
<div class="calendarObject">
<label class="objectTitle" for="chkOb2">Tasks</span>
<input type="checkbox" id="chkOb2" />
</div>
</div>
.objectWrap {
position:relative;
float:left;
height:75px;
margin-bottom:15px;
}
.objectWrap:not(:last-child) {
margin-right:15px;
}
.objectWrap:hover {
cursor:pointer;
}
.calendarObject {
position:relative;
width:72px;
height:75%;
background-color:#f5f5f5;
border-radius:5px;
transition: height 400ms;
-webkit-transition: height 400ms;
}
.calendarObject label.objectTitle {
position:absolute;
top:3px;
left:3px;
font-size:13px;
color: #8998a4;
}
.calendarObject input[type="checkbox"] {
position:absolute;
bottom:0px;
right:0px;
}
.calendarObject:hover {
height:100%;
transition: height 400ms;
-webkit-transition: height 400ms;
}
You have a bug in your code. </span> should be </label>.
Corrected HTML:
<div class="objectWrap">
<div class="calendarObject">
<label class="objectTitle" for="chkOb2">Tasks</label>
<input type="checkbox" id="chkOb2" />
</div>
</div>
Corrected JS Fiddle
Your markup is not properly nested.. your label tag needs a closing label tag.. not a closing span tag.