Circle Border not animating on hover - html

I'm trying to animate the border of a circle when I hover over it so that it fills up gradually. So far no luck on my #keyframes animation code. I'm not exactly sure what I'm doing wrong here as my keyframes is targeting the value of my .circle:hover property.
.circle {
position: relative;
overflow: hidden;
width: 120px;
height: 120px;
border-radius: 50%;
background: #5d0b3c;
}
#skills .text {
position: absolute;
top: 38px;
left: 30px;
width: 60px;
color: #fff;
text-align: center;
text-transform: uppercase;
font: 18px sans-serif;
transition: opacity .2s ease;
}
.circle:hover {
animation: border;
}
#keyframes border {
0% {
border: none;
}
25% {
border: 5px solid pink;
}
50% {
}
75% {
}
100% {
}
}
<div class="container">
<div class="row">
<div class="col-3">
<div class="card">
<div class="card-body" style="border: 1px solid">
<div class="circle">
<span class="text">skill 1</span>
</div>
</div>
</div>
</div>
</div>
</div>

You are passing incomplete "parameters" in CSS. When we are going to use an animation, the required parameter sequence is:
animation: [name] [duration] [interpolation function]
Interpolation function is how the animation will be executed: linearly? Will it start fast and end slowly? Or will you follow a custom rhythm?
Example:
animation: border 1s linear;
However, there are sub-parameters that you can use but are not required, such as deciding how long the animation will take to start. For more details, you can see this article.

You are using the CSS wrongly.
You only set the name of the animation, but that is not enough for it to understand what you really want to do. To do so, you need to give an interpolation function and a duration.
Beside that, I've also added -webkit-animation as that is needed for browsers like Safari and Chrome, although the latter won't support it from version 43, as far as I know.
Anyway, an example of correct CSS is this:
.circle:hover {
-webkit-animation: border 1s linear;
animation: border 1s linear;
}
Please see the full working code / demo here:
https://jsfiddle.net/9r08aoty/3/

You don't need animation / keyframes for that, a simple transition will do
.circle {
box-sizing:border-box; /* <<== so the circle doesn't grow with the border */
position: relative;
overflow: hidden;
width: 120px;
height: 120px;
border-radius: 50%;
background: #5d0b3c;
}
#skills .text {
position: absolute;
top: 38px;
left: 30px;
width: 60px;
color: #fff;
text-align: center;
text-transform: uppercase;
font: 18px sans-serif;
transition: opacity .2s ease;
}
.circle:hover {
border:5px solid pink;
transition:border .5s ease; /*<<== simple transition */
}
<div class="container">
<div class="row">
<div class="col-3">
<div class="card">
<div class="card-body" style="border: 1px solid">
<div class="circle">
<span class="text">skill 1</span>
</div>
</div>
</div>
</div>
</div>
</div>

Related

Using nth child to select one particular sibling

I am hosting three images from Google on my codepen demo.
I have built image overlays which add a semi-transparent overlay when a user hovers over them.
They're working fine, but due to the colour of the last one, it looks much darker when hovered over than the other two.
I wondered whether there was a way to select the last image using the nth child (or similar) selector so that I could style that with a lower opacity irrespective of the other two, which I want to keep the same.
Here's the codepen link - http://codepen.io/skoster7/pen/ozgjmP?editors=1100
Like I said, I would like the last image to have a lower opacity then the other two, ideally using the nth-child selector or something similar.
I know I could just use a separate overlay with a different class name, but wanted to know if this was possible before doing that.
.flexcontainer {
display: flex;
}
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
}
.overlay {
transition: .5s;
position: absolute;
margin: 12.5px 0 0 5px;
top: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
}
.overlay:hover {
transition-delay: .2s;
transition-duration: 1s;
opacity: .6;
}
.overlay p {
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
}
.photocontainer:last-child .overlay:hover {
rgba(20, 5, 5, 0.35);
text-
}
<div class="flexcontainer">
<div class="photocontainer">
<img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay">
<p>Spring is here</p>
</div>
</div>
<div class="photocontainer">
<img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay">
<p>Winter is here</p>
</div>
</div>
<div class="photocontainer">
<img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay">
<p>Autumn is here</p>
</div>
</div>
</div>
This is how you could target each one of them using nth-child, we are targeting parent element i.e. .photocontainer as they are of same class name in all three images.
.photocontainer:nth-child(1) > .overlay:hover {
opacity: 0.4;
}
.photocontainer:nth-child(2) > .overlay:hover {
opacity: 0.6;
}
.photocontainer:nth-child(3) > .overlay:hover {
opacity: 1;
}
.flexcontainer {
display: flex;
}
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
}
.overlay {
transition: .5s;
position: absolute;
margin: 12.5px 0 0 5px;
top: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
}
.overlay:hover {
transition-delay: .2s;
transition-duration: 1s;
}
.overlay p {
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
}
.photocontainer:nth-child(1) > .overlay:hover {
opacity: 0.4;
}
.photocontainer:nth-child(2) > .overlay:hover {
opacity: 0.6;
}
.photocontainer:nth-child(3) > .overlay:hover {
opacity: 1;
}
<div class="flexcontainer">
<div class="photocontainer"> <img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay"><p>Spring is here</p>
</div>
</div>
<div class="photocontainer"> <img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay"> <p>Winter is here</p>
</div>
</div>
<div class="photocontainer"><img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay"><p>Autumn is here</p>
</div>
</div>
</div>
UPDATED
The issue of text opacity lowering and last child opacity control both has been fixed
Working example at CODEPEN
HTML:
<div class="flexcontainer">
<div class="photocontainer"> <img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay"></div>
<p>Spring is here</p>
</div>
<div class="photocontainer"> <img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay"></div>
<p>Winter is here</p>
</div>
<div class="photocontainer"><img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay"></div>
<p>Autumn is here</p>
</div>
</div>
CSS:
.flexcontainer {
display: flex;
}
.photocontainer,
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
position: relative;
}
.overlay {
transition: .5s;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
margin: 5px;
}
.photocontainer p {
position: absolute;
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
top: 20px;
left: 0;
right: 0;
bottom: 0;
margin: 5px;
z-index: 1;
transition: .5s;
opacity: 0;
}
.photocontainer:hover .overlay {
transition-delay: .2s;
transition-duration: 1s;
opacity: 0.6;
}
.photocontainer:hover p {
transition-delay: .2s;
transition-duration: 1s;
opacity: 1;
}
.photocontainer:hover:last-child .overlay {
opacity: 0.3;
}
Old:
.photocontainer:last-child .overlay:hover {
opacity: 0.4;
}
I hope now your both issue has been resolved.
Enjoy :)
Here's how you target it. The opacity value is just for example.
.photocontainer:last-child .overlay:hover {
opacity: .3;
}
revised codepen
The :last-child pseudo-class targets the last sibling of the same parent.
In your HTML, the third image is contained in the last .photocontainer div.
Once the focus is on the third container, you can use a descendant selector to target the image.
Also, keep in mind that the opacity property applies not only to the targeted element, but to all of the element's descendants, as well.
So when you reduce the opacity of .overlay, the text inside will also fade away.
The solution is to use the rgba() color method. The a stands for alpha channel, and allows you to apply transparency only to the color.
Add this to your code:
.photocontainer:last-child .overlay:hover {
background-color: rgba(0, 0, 0, 0.5);
}
revised codepen illustrating both methods
(If you're applying opacity to an image, that's another ball game. You can find lots of posts on this site on that topic.)
References:
https://www.w3.org/TR/css3-selectors/#selectors
https://developer.mozilla.org/en-US/docs/Web/CSS/opacity

div height 100% with content

Would I like to know how I can put in a div 100% height?
I have a div with an image and a div with content.
The image has a width 100%, and the same content but does not fill the entire image div.
I copied the code if you can help.
Thank you,
#carta div{
position: relative;
display: table;
}
#carta div .overlay{
width: 100%;
height: 100%;
background: rgba(0,0,0,.7);
position: absolute;
top:0;
text-align: center;
color:white;
cursor: pointer;
opacity: 0;
-webkit-transition:all .4s ease-out;
transition:all .4s ease-out;
}
#carta .overlay:hover{
opacity: 1;
width: 100%;
height: 100%;
}
#carta .col-1-4{
padding: 0;
margin:0;
}
#carta div img{
width: 100%;
display: table;
}
#carta .overlay p{
font-style: oblique;
font-size: 20px;
padding-top: 50px;
text-align: center;
border-top: 1px solid white;
-webkit-transition:all .4s ease-out;
transition:all .4s ease-out;
}
#carta .overlay h5{
font-size: 30px;
margin: 50px;
}
<div class="clearFix">
<div class="col-1-4">
<img src="img/carta/atun.jpg" alt="atún revuelto"/>
<div class="overlay">
<h5>Atun revuelto</h5>
<p>15€</p>
</div>
</div>
<div class="col-1-4">
<img src="img/carta/especialidaditaliana.jpg" alt="especialidad italiana"/>
<div class="overlay">
<h5>Especialidad Italiana</h5>
<p>15€</p>
</div>
</div>
</div>
Thank you very much for your responses.
I have solved by adding "display: table-cell" in the css class ".overlay"
Thus occupies the div, which occupies the image.
Many thanks
Use background in css,something like this: background: url(img/carta/especialidaditaliana.jpg);
You also can use div to set background
Like this: <div class="img">content</div> but you also need css background.
Something like this?It should work in .html document...
<style>
.img {
position: relative;
width: 200px;
height: 100%;
background: url(http://goo.gl/ytbJn8);
color: white;
}
</style>
<div class="img">This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text. This is text.</div>
<div class="box"></div>

Animate an element that moves to occupy empty space with CSS only

http://jsfiddle.net/kscjq0y0/
I want to animate the movement of the yellow div when the red one disappears.
I know it can be done with jQuery animate but I want a CSS3 solution (even if it's not fully supported by all modern browsers).
I've tried the CSS transition property but doesn't seem to work for this kind of movement.
It's there a way to do this?
Make it shrink
div {
height: 100px;
width: 300px;
background-color: red;
margin: 20px;
padding: 10px;
}
#bottom {
background-color: yellow !important;
transition: all 0.5s ease;
}
#top {
transition: all 2s;
}
body:hover #top {
height: 0px;
padding: 0px;
margin-top: 0px;
margin-bottom: 0px;
}
<div id="top"></div>
<div id="bottom"></div>
You can do this, by modifying the CSS attribute that you want to animate. Currently the positioning is based on block layout with the other div, and this is not animating. But if you update the CSS position yourself, then that transition will animate. See the below example.
window.setTimeout(function () {
$("#top").fadeOut("slow");
$("#bottom").css({ top: '0px' });
}, 1000);
div {
height: 100px;
width: 300px;
background-color: red;
margin: 20px;
padding: 10px;
}
#bottom {
position: absolute;
top: 140px;
background-color: yellow !important;
transition: all 0.5s ease;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="top"></div>
<div id="bottom"></div>

Multiple Divs On One Line With Even Spacing

I have a Slider with a few images. Inside this slider, i have a div called "sb-bolas", and inside this div, i created new div's where i have a circle, and inside this circle i want to insert some text.
But i need to create more then 1 circle and i want to every circle have the same space between them.
How can i do this?
HTML
<div class="sb-bolas">
<div class="bolas-grad">something</div>
<div class="bolas-grad">something</div>
<div class="bolas-grad">something</div>
</div>
CSS
.sb-bolas {
padding: 10px;
bottom: 50px;
left: 100px;
right: 100px;
z-index: 1000;
position: absolute;
background: #CBBFAE;
background: rgba(190,176,155, 0.4);
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
color: #fff;
-webkit-transition: all 200ms;
-moz-transition: all 200ms;
-o-transition: all 200ms;
-ms-transition: all 200ms;
transition: all 200ms;
}
.bolas-grad {
width: 100px;
height: 100px;
border-radius: 50px;
opacity: 0.7;
filter: alpha(opacity=40);
background: linear-gradient(to bottom, #007EFF, #09f);
font-size: 12px;
color: #fff;
line-height: 100px;
text-align: center;
}
*UPDATE**
Image
Use float:left; and margin
Keep in mind, using float will remove any absolute positioning you may have established with its parent element. To further help clarify what exactly you need to do, we don't have enough context with the rest of your HTML. Please provide more detailed code if you want a more detailed answer.
View Here: http://jsfiddle.net/SinisterSystems/qwA32/2/
HTML:
<div class="slideshow">
<div class="slide" style="background:#C00;">
</div>
<div class="slide" style="background:#0C0;">
</div>
<div class="slide" style="background:#00C;">
</div>
</div>
CSS:
.slideshow {
position:absolute;
top:0;
left:0;
}
div.slide {
float:left; // <------- Here
margin-right:50px; // <------- Here
width: 100px;
height: 100px;
border-radius:50px;
opacity:0.7;
filter:alpha(opacity=40);
background:linear-gradient(to bottom, #007EFF, #09f);
font-size:12px;
color:#fff;
line-height:100px;
text-align:center;
}
View Here: http://jsfiddle.net/SinisterSystems/qwA32/2/
Add property
display:inline-block;
to the class .bolas-grad to have the circles in the same row.
To have even spaces add margin to the class .bolas-grad

Change position of div on hover

Consider following HTML.
I have .image and .details wrapped in .wrap. Outside the .wrap, I have another div .extra, which I want to hide initially but on hover over the image div only, i want to slide it down so that it takes whole area of the .wrap.
I am trying following code, does not work:
HTML:
<div class="box">
<div class="wrap">
<div class="image"><img src="http://farm9.staticflickr.com/8075/8310628243_d48e64dc66_m.jpg" /></div>
<div class="details">xxx</div>
</div>
<div class="extra">hidden, show on hover over .image</div>
</div>
CSS:
.box{
border: 1px solid red;
width: 240px;
}
.image{
border: 1px solid green;
position: relative;
}
.extra{
position: absolute;
top: -100%;
left: 0;
background: green;
}
.box .image:hover .extra{
top: 0;
}
Demo: http://jsfiddle.net/pv9jd/
.extra is not a child of .image.
I updated the fiddle by replacing .image with .wrap:hover.
http://jsfiddle.net/UrKCs/2/
I'm not sure if you want that, because now the .extra appears when hovering the whole .wrap div.
I updated it again to have the hover on the image only
http://jsfiddle.net/UrKCs/5/
I believe you are looking for something like this image hover using jQuery
$('.image').hover(function(){
$('.extra').css({'top' : '0'});
},function(){
$('.extra').css({'top' : '-100%'}
);
});​
Sorry to butcher your code but this may be able to help you:
<div class="box">
<div class="image"></div>
</div>
This is the CSS:
.box div{
color: #fff;
width: 200px;
height: 100px;
position: relative;
box-sizing: border-box;
transition: border .7s ease;
}
.image{
background: #fff url(http://farm9.staticflickr.com/8075/8310628243_d48e64dc66_m.jpg) bottom;
border-top: solid 100px #ccc;
}
.image:hover{
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
border: solid 0px;
}
You can read more here for the sliding.
You can also play around here: http://codepen.io/joe/pen/oqxJu