I want to make an effect that would trigger my button transition when I hover the outer div box (parent) that already has its own transition. Can this be done with css or is it in need of some javascript?
My example:
.box {
height: 300px;
width: 300px;
background: #eeeeee;
float: left;
margin: 50px;
-webkit-transition: All 0.5s ease;
-moz-transition: All 0.5s ease;
-o-transition: All 0.5s ease;
-ms-transition: All 0.5s ease;
transition: All 0.5s ease;
}
.box:hover {
height: 350px;
}
#box_pic1 {
background: url(http://nicholsd.com/_Media/image-15_med.png);
background-repeat: no-repeat;
background-position: relative;
height: 196px;
width: 262px;
margin: 0 auto;
margin-top: 20px;
}
.btn_ani {
font-size: 13px;
text-align: center;
color: #ffffff;
opacity: 0.5;
width: 150px;
background: #99745c;
border:1px solid #99745c;
line-height: 35px;
transition: opacity 0.5s;
-webkit-transition: all ease 0.5s;
-moz-transition: all ease 0.5s;
-o-transition: all ease 0.5s;
-ms-transition: all ease 0.5s;
transition: all ease 0.5s;
position: absolute;
margin-left: 56px;
}
.btn_ani:hover {
background: #ffffff;
color: #99745c;
opacity: 1;
-webkit-transition: all ease 0.7s;
-moz-transition: all ease 0.7s;
-o-transition: all ease 0.7s;
-ms-transition: all ease 0.7s;
transition: all ease 0.5s;
border:1px solid #99745c;
margin-top: 80px;
}
<div class="box">
<a href="www.google.com">
<div id="box_pic1">
<div class="btn_ani">View</div>
</div>
</a>
</div>
It can be done with CSS. You could simply move the :hover state to the parent .box and the target the descendants like: .box:hover .btn_ani.
In this case elements can have their own transition value.
.box {
height: 300px;
width: 300px;
background: #eeeeee;
float: left;
margin: 50px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.box:hover {
height: 350px;
}
#box_pic1 {
background: url(http://nicholsd.com/_Media/image-15_med.png);
background-repeat: no-repeat;
background-position: relative;
height: 196px;
width: 262px;
margin: 0 auto;
margin-top: 20px;
}
.btn_ani {
font-size: 13px;
text-align: center;
color: #ffffff;
opacity: 0.5;
width: 150px;
background: #99745c;
border:1px solid #99745c;
line-height: 35px;
transition: opacity 0.5s;
/* different transition from the parent */
-webkit-transition: all ease 0.7s;
-moz-transition: all ease 0.7s;
-o-transition: all ease 0.7s;
-ms-transition: all ease 0.7s;
transition: all ease 0.7s;
position: absolute;
margin-left: 56px;
}
.box:hover .btn_ani {
background: #ffffff;
color: #99745c;
opacity: 1;
border:1px solid #99745c;
margin-top: 80px;
}
<div class="box">
<a href="www.google.com">
<div id="box_pic1">
<div class="btn_ani">View</div>
</div>
</a>
</div>
If you would like to try some jQuery, you could use a solution such as this:
$('.box').hover(function(){
$('.btn_ani').toggleClass('margin');
});
With the css:
.margin{
margin-top:80px;
}
and here is an example!
Related
I have two divs side by side with an iframe. When I hover over the div on the left, I want the iframe on the right to resize to 50% width. The div on the left would then be resized to be 50%. I would prefer a pure CSS approach to this.
.answer6{
float:left;
width: 100%;
}
.mpi-options-all2 {
float: left;
width: 100%;
bottom: 75px;
right: 75px;
padding: 10px;
background-color: black;
color: white;
opacity:0.8;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
filter: alpha(opacity=80);
font-weight: bold;
text-align: left;
padding: 10px;
position: absolute;
right: -100%;
text-align: center;
top: 0px;
height: 505px;
z-index: 2;
-webkit-transition: right 0.5s ease-in-out;
-moz-transition: right 0.5s ease-in-out;
-o-transition: right 0.5s ease-in-out;
-ms-transition: right 0.5s ease-in-out;
transition: right 0.5s ease-in-out;
}
.left-right{
padding: 0px;
margin: 0px auto;
height: 525px;
position: relative;
overflow: hidden;
}
.left-right:hover .mpi-options-all2{
right: 0;
}
<div class="answer6">
<iframe src="https://wikipedia.org/wiki/Main_Page" width="75%" height="500" align="right"></iframe>
<div class ="left-right">
<div class="mpi-options-all2">
<h2><center>Description:</center></h2>
</div>
</div>
</div>
According to what I understood about the problem, here is a solution to see if it is correct.
<div class="answer6">
<div class ="left-right">
<div class="mpi-options-all2">
<h2><center>Description:</center></h2>
</div>
</div>
<iframe src="https://wikipedia.org/wiki/Main_Page" height="500" align="right"></iframe>
</div>
.answer6{
width: 100%;
}
.mpi-options-all2 h2{
display: none;
}
.mpi-options-all2 {
width: 100%;
bottom: 75px;
/*right: 75px;*/
padding: 10px;
background-color: black;
color: white;
opacity:0.8;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
filter: alpha(opacity=80);
font-weight: bold;
text-align: left;
padding: 10px;
/*position: absolute;*/
/*right: -100%;*/
text-align: center;
top: 0px;
height: 505px;
/*z-index: 2;*/
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.left-right{
padding: 0px;
margin: 0px auto;
height: 525px;
position: relative;
overflow: hidden;
float: left;
width: 2%;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
iframe{
margin:0;
width: 97.7%;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
float:right;
}
.left-right:hover .mpi-options-all2 h2{
display: block;
}
.left-right:hover{
width: 49.7%;
}
.left-right:hover ~ iframe{
width: 50%;
}
https://codepen.io/anon/pen/ROEogj
I created a link that uses css pseudo classes. As seen in css (:before). Everything is fine in an Andriod device but in iPhone it's working on the second click Why...? if there is any solution please help me.
.link{float:left;}
.link a {
color: #000;
font-size: 15px;
font-weight: 400;
padding: 10px;
display: inline-block;
border: 1px solid #b6fe54;
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
position: relative;
}
.link a:before {
position: absolute;
content: "";
width: 0px;
background: #b6fe54;
left: 0px;
top: 0px;
height: 100%;
z-index: -1;
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
-o-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
}
.link a:hover:before {
width: 100%;
}
<div class="link">Learn More</div>
Add the following
<script>
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if(!iOS)
document.write('\x3Cstyle>.link a:hover:before {width: 100%;}\x3C/style>');
</script>
This question already has answers here:
I do not want to inherit the child opacity from the parent in CSS
(18 answers)
Closed 5 years ago.
I'm creating simple animation for my project. After hovering on image I get this effect: http://imgur.com/a/L3mwF.
The thing is I'm changing opacity for the gradient foreground from 0 to 0.8. It also chenges opacity for the icon and text. I want to change gradient opacity to 0.8 and icon+text to 1.
Here's my html code
<div class="col-xs-12 col-sm-4 wrapper">
<div class="about__gallery--bg">
</div>
<div class="about__gallery--top">
<div class="row inner">
<img class="img-responsive" src="./img/pictograms/aboutus_pic1_icon.png" alt="">
<span>Super team</span>
</div>
</div>
<div class="about__gallery__img about__gallery__img--1">
</div>
</div>
And here's my sass code
.about__gallery {
&__img {
width: 380px;
height: 250px;
opacity: 1;
z-index: 50;
&--1 {
background: url('../img/aboutus_pic1.png');
background-size:cover;
}
}
&--bg {
width: 380px;
height: 250px;
opacity: 1;
z-index: -100;
position: absolute;
background-color: $color-blue;
}
&--top {
width: 380px;
height: 250px;
opacity: 0;
z-index: 90;
position: absolute;
background: linear-gradient($color-red, $color-yellow);
img{
display: block;
margin:auto;
margin-top: 15%;
}
span{
text-transform: uppercase;
font-weight: bold;
color:white;
display:block;
}
&:hover {
opacity: 0.8;
margin-top: -15px;
margin-left: -15px;
margin-bottom: 15px;
-webkit-transition: all 0.7s ease-out;
-moz-transition: all 0.7s ease-out;
-ms-transition: all 0.7s ease-out;
-o-transition: all 0.7s ease-out;
transition: all 0.7s ease-out;
}
&:hover + .about__gallery__img {
margin-bottom: 15px;
margin-top: -15px;
margin-left: -15px;
-webkit-transition: all 0.7s ease-out;
-moz-transition: all 0.7s ease-out;
-ms-transition: all 0.7s ease-out;
-o-transition: all 0.7s ease-out;
transition: all 0.7s ease-out;
}
}
}
I'm not seeing your icons, but if I understand what you're going for, use opacity: 1 on the element, and rgba() to control the gradient opacity.
.about__gallery__img {
width: 380px;
height: 250px;
opacity: 1;
z-index: 50;
}
.about__gallery__img--1 {
background: url("http://kenwheeler.github.io/slick/img/lazyfonz2.png");
background-size: cover;
}
.about__gallery--bg {
width: 380px;
height: 250px;
opacity: 1;
z-index: -100;
position: absolute;
background-color: blue;
}
.about__gallery--top {
width: 380px;
height: 250px;
opacity: 0;
z-index: 90;
position: absolute;
background: linear-gradient(rgba(255, 0, 0, 0.8), rgba(0, 255, 255, 0.8));
}
.about__gallery--top img {
display: block;
margin: auto;
margin-top: 15%;
}
.about__gallery--top span {
text-transform: uppercase;
font-weight: bold;
color: white;
display: block;
}
.about__gallery--top:hover {
opacity: 1;
margin-top: -15px;
margin-left: -15px;
margin-bottom: 15px;
-webkit-transition: all 0.7s ease-out;
-moz-transition: all 0.7s ease-out;
-ms-transition: all 0.7s ease-out;
-o-transition: all 0.7s ease-out;
transition: all 0.7s ease-out;
}
.about__gallery--top:hover + .about__gallery__img {
margin-bottom: 15px;
margin-top: -15px;
margin-left: -15px;
-webkit-transition: all 0.7s ease-out;
-moz-transition: all 0.7s ease-out;
-ms-transition: all 0.7s ease-out;
-o-transition: all 0.7s ease-out;
transition: all 0.7s ease-out;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-12 col-sm-4 wrapper">
<div class="about__gallery--bg">
</div>
<div class="about__gallery--top">
<div class="row inner">
<img class="img-responsive" src="http://kenwheeler.github.io/slick/img/fonz1.png" alt="">
<span>Super team</span>
</div>
</div>
<div class="about__gallery__img about__gallery__img--1">
</div>
</div>
I am having an issue. When I hover over the image, a dark overlay appears but CSS Transition property is not working on it.
Here is the html:
<div class="col-md-12">
<div class="collection-category">
<img src="http://dummyimage.com/600x400/#C1C1C1/fff" />
<a href="#">
<div class="overlay_wrap">
<div class="overlay">
<h2 class="collection_title">Headline One</h2>
</div>
</div>
</a>
</div>
</div>
And CSS is:
.collection-category {
display: block;
overflow: hidden;
margin: 10px 0;
position: relative;
}
.collection-category img {
width: 100%;
max-height: 250px;
}
.collection_title {
display: table-cell;
vertical-align: middle;
font-size: 28px;
}
.overlay_wrap {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
}
.overlay {
display: none;
background: rgba(2, 2, 2, 0.61);
color: #FFF;
text-align: center;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
}
.collection-category:hover>a>.overlay_wrap>.overlay {
display: table;
height: 100%;
width: 100%;
}
Here is the JSFiddle
http://jsfiddle.net/cnbvoe32/
Any help would be highly appreciated.
thanks in advance.
It's because you can't transition from display: none to display: table.
Instead, you could transition the opacity property by setting the initial display to table along with opacity: 0 and then transitioning to opacity: 1:
Updated Example
.overlay {
display: table;
background: rgba(2, 2, 2, 0.61);
color: #FFF;
text-align: center;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
opacity: 0;
height: 100%;
width: 100%;
}
.collection-category:hover>a>.overlay_wrap>.overlay {
opacity: 1;
}
I have 4 divs floating left next to each other with a set hover width transition, three divs are the same width but the fourth is smaller. When you hover up on the div it gets bigger and I need the rest to reduce the width automaticaly to the set reduced-width value.
Here is the code
.container1 {
position: relative;
height: 600px;
width: 29%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container1:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container1 .reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image1 {
background: url("../img/bg1.jpg");
}
.container2 {
position: relative;
height: 600px;
width: 29%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container2:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container2 .reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image2 {
background: url("../img/bg2.jpg");
}
.container3 {
position: relative;
height: 600px;
width: 29%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
border-right: #000 4px solid;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container3:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container3 .reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
#image3 {
background: url("../img/bg3.jpg");
}
.container4 {
position: relative;
height: 600px;
width: 13%;
top: 0px;
left:0%;
z-index: 999;
float: right;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container4:hover {
width: 30%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
#image4 {
background: url("../img/3.jpg");
}
And the HTML
<div class="container1 animated bounceInLeft reduced-width" id="image1">
</div>
<div class="container2 animated bounceInDown reduced-width" id="image2">
</div>
<div class="container3 animated bounceInDown reduced-width" id="image3">
</div>
<div class="container4 animated bounceInRight reduced-width" id="image4">
</div>
when you are targeting 2 classes you should do it without spaces( like you did .container1 .reduced-width it should be .container1.reduced-width)
set width in such a way that your design won't break.. like your width of all containers should be 24%(as you have 4px border too) so that total will be equal or less than 100%.
You should write least css and target more elements. like you are targeting a particular div everytime which is not advisible.. you could use reduced with class only once and it would have set the size everytime.
this could be your reduced/optimized code:
HTML:
<div class="container animated bounceInLeft" id="image1"></div>
<div class="container animated bounceInDown" id="image2"></div>
<div class="container animated bounceInDown" id="image3"></div>
<div class="container animated bounceInRight" id="image4"></div>
CSS:
.container {
position: relative;
height: 600px;
width: 24%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
background-color:red;
}
.container:hover {
width: 40%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container.reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image1 {
background: red;
}
#image2 {
background: yellow;
}
#image3 {
background: green;
}
#image4 {
background: blue ;
}
Here is CodePen Link
You don't need to do all that stuff for doing what you want. You can do it without any Javascript or jQuery using just CSS3.
Wrap your divs in a container.
Apply display: flex for the container.
Apply flex: 1 1 to the children. This is important.. do not give any flex-basis.. let it default.
Give a width: 100%; to children, they will automatically grow/shrink to available space.
Apply flex: 1 1 <your-width> for :hover on children. That's it.
Demo Fiddle: http://jsfiddle.net/abhitalks/xghqmq6u/
See this snippet:
.wrap {
width: 100%;
display: flex;
flex-direction: columns;
}
.floaters {
flex: 1 1 0%;
height: 120px; width: 100%;
transition: all 500ms;
}
.floaters:hover { flex: 1 1 50%; }
.container1 { background-color: #f00;}
.container2 { background-color: #0f0;}
.container3 { background-color: #00f;}
.container4 { background-color: #ccc;}
<div class="wrap">
<div class="container1 floaters" id="image1"></div>
<div class="container2 floaters" id="image2"></div>
<div class="container3 floaters" id="image3"></div>
<div class="container4 floaters" id="image4"></div>
</div>
This is how you can fix it.
HTML (you don't need a wrapper)
<div class="container1 animated bounceInLeft" id="image1"></div>
<div class="container2 animated bounceInDown" id="image2"></div>
<div class="container3 animated bounceInDown" id="image3"></div>
<div class="container4 animated bounceInRight" id="image4"></div>
CSS
.container {
position: relative;
height: 600px;
width: 24%;
top: 0px;
left: 0%;
float: left;
z-index: 99;
opacity: 1;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
background-color:red;
}
.container:hover {
width: 35%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container.reduced-width {
width: 20%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out; }
#image1 {
background: red;
}
#image2 {
background: yellow;
}
#image3 {
background: green;
}
#image4 {
background: blue ;
}
And of course you need Javascript (Jquery here)
$('.animated').mouseenter(function(){
console.log('here');
$(this).removeClass('reduced-width').siblings('.animated').addClass('reduced-width');
}).mouseout(function(){
$('.animated').removeClass('reduced-width');
});
EDIT: now the 4th column has a smaller width
Here is an example how you could fix it: http://jsfiddle.net/intergalactic_overlords/0hLmrme4/
Html needs a wrapper. When hovering the wrapper, children (the containers) width is set to 20%. When hovering a specific container, its width is set to 40%.
<div class="container-wrap">
<div class="container container1 animated bounceInLeft reduced-width" id="image1">
</div>
<div class="container container2 animated bounceInDown reduced-width" id="image2">
</div>
<div class="container container3 animated bounceInDown reduced-width" id="image3">
</div>
<div class="container container4 animated bounceInRight reduced-width" id="image4">
</div>
</div>
CSS:
.container {
background:snow;
box-sizing:border-box;
position: relative;
height: 600px;
width: 23%;
float: left;
z-index: 99;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
border-right: #000 4px solid;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container-4 {
width: 21%;
}
.container-wrap:hover > div {
width: 21%;
}
.container-wrap:hover > .container4 {
width: 16%;
}
.container-wrap > .container:hover {
background: yellow;
width: 42%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}
.container-wrap > .container4:hover {
background: yellow;
width: 37%;
transition: all 300ms ease-in-out;
-o-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
-webkit-transition: all 300ms ease-in-out;
}