Chrome hover effect sticking on rounded corners - html

I have an image within a container. The container has rounded corners in order to make the child image circular.
There's a hover effect on the parent, but in Chrome (but not Firefox!) the effect remains when the cursor leaves the image.
Expected (Firefox):
Actual (Chrome):
Please see my demo code below:
.user {
display: inline-block;
width: 200px;
height: 200px;
object-fit: cover;
}
.image-container {
background: black;
overflow: hidden;
width: 200px;
height: 200px;
border-radius: 50%;
padding-left: 0%;
}
.image-container:hover {
cursor: pointer;
}
.image-container:hover .user {
opacity: 0.3;
transition: 0.5s;
}
<div class="image-container">
<img src="https://avatars.githubusercontent.com/u/16269580?v=4" class="user">
</div>
I'm looking to have the hover effect end immediately on leaving the "circle". Any help would be appreciated.

Try to add border-radius to image class .user too:
.user {
display: inline-block;
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 50%;
}
.image-container {
background: black;
overflow: hidden;
width: 200px;
height: 200px;
border-radius: 50%;
padding-left: 0%;
}
.image-container:hover {
cursor: pointer;
}
.image-container:hover .user {
opacity: 0.3;
transition: 0.5s;
}
<div class="image-container">
<img src="https://avatars.githubusercontent.com/u/16269580?v=4" class="user">
</div>

Related

I want my image to be shown in a circle and when hovered on it gets full

I have tried achieving this effect using border-radius (code below) but I want the circle to be smaller, as shown in this example https://imgur.com/a/gKHtVXr and I don't think I can acheive this with border-radius.
<img class = "zyra-thumb" src = "thumbnail champion/thumb2.png" alt="zyra">
CSS:
.zyra-thumb{
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 150px;
transition: border-radius 0.3s;
}
.zyra-thumb:hover{
border-radius: 10px;
}
you can use clip-path to display only center of the thumb image and
transition: clip-path 1s;to give needed animation on hover
.thumb {
background: purple;
width: 200px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10px;
}
.zyra-thumb {
width: 100%;
object-fit: cover;
clip-path: circle(25% at 50% 50%);
transition: clip-path 1s;
border-radius: 10px;
}
.zyra-thumb:hover {
clip-path: circle(100% at 50% 50%);;
}
<div class="thumb">
<img class="zyra-thumb" src="https://www.gravatar.com/avatar/0cf65651ae9a3ba2858ef0d0a7dbf900?s=256&d=identicon&r=PG&f=1" alt="zyra">
</div>
Based on your attached image I assume this is the effect you are trying to achieve.
.zyra-thumb {
background: url(https://i.stack.imgur.com/OR7ho.jpg) no-repeat center;
background-size: cover;
position: relative;
width: 400px;
height: 400px;
overflow: hidden;
display: inline-block;
border-radius: 20px;
}
.zyra-thumb::before {
content: "";
display: block;
width: 50%;
padding-bottom: 50%;
position: absolute;
top: 50%;
left: 50%;
z-index: 2;
transform: translate(-50%, -50%);
border: solid 400px #41373f;
border-radius: 50%;
transition: all ease-in-out 0.3s;
}
.zyra-thumb:hover::before {
width: 150%;
padding-bottom: 150%;
}
<div class="zyra-thumb">
</div>
Simply use border-radius:0px; in hover.

move one block on another when hover

When I move mouse on red div I want grey div go a little upper. But when it moves and mouse happens to be on red div it starts to lag and hesitate between moving up and down. What should I do for this animation for avoiding this hesitation and moving grey object smooth?
.dm-intro-news {
width: 200px;
height: 200px;
background: red;
transition: 0.5s;
}
.dm-intro-news {
width: 390px;
height: 150px;
background: #333333;
transition: 0.4s;
}
.wr {display: inline-block;transition:2s}
.dm-short-news{
display:inline-block;
overflow: hidden;
width: 390px;
height: 40px;
background: red;
position: relative;
}
.dm-short-news:hover~.dm-intro-news{
margin-top:-50px;
position: absolute;
}
<div class="wr">
<div class="dm-short-news"></div>
<div class="dm-intro-news"></div>
</div>
This is because hover event will be cancelled when .dm-intro-news is on top.
Put pointer-events: none; on .dm-intro-news:
.dm-intro-news {
width: 200px;
height: 200px;
background: red;
transition: 0.5s;
}
.dm-intro-news {
width: 390px;
height: 150px;
background: #333333;
transition: 0.4s;
}
.wr {display: inline-block;transition:2s; position: relative;}
.dm-short-news{
display:inline-block;
overflow: hidden;
width: 390px;
height: 40px;
background: red;
}
.dm-short-news:hover::before {
content: '';
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.dm-short-news:hover~.dm-intro-news {
margin-top:-50px;
pointer-events: none;
position: relative;
z-index: 1;
}
<div class="wr">
<div class="dm-short-news"></div>
<div class="dm-intro-news"></div>
</div>
Remove all the position from your elements and consider hover on both elements:
.wr {
display: inline-block;
width: 390px;
}
.dm-short-news {
height: 40px;
background: red;
margin-bottom:5px;
}
.dm-intro-news {
height: 150px;
background: #333333;
transition: 0.4s;
}
.dm-short-news:hover~.dm-intro-news,
.dm-intro-news:hover{
margin-top: -50px;
}
<div class="wr">
<div class="dm-short-news"></div>
<div class="dm-intro-news"></div>
</div>
It's easy, You just need remove position:absolute from .dm-short-news:hover~.dm-intro-news.
Let me know further clarification.
Hope it will help you. :)
.dm-intro-news {
width: 200px;
height: 200px;
background: red;
transition: 0.5s;
position: relative;
}
.dm-intro-news {
width: 390px;
height: 150px;
background: #333333;
transition: 0.4s;
}
.wr {display: inline-block;transition:2s}
.dm-short-news{
display:inline-block;
overflow: hidden;
width: 390px;
height: 40px;
background: red;
}
.dm-short-news:hover~.dm-intro-news,
.dm-intro-news:hover{
margin-top:-50px;
}
<div class="wr">
<div class="dm-short-news"></div>
<div class="dm-intro-news"></div>
</div>
You can set an element to ignore the mouse cursor.
I added pointer-events: none; on .dm-short-news.
[edit] I also removed position: absolute.
.dm-intro-news {
position: relative;
width: 390px;
height: 150px;
background: #333333;
transition: 0.4s;
z-index: 1;
pointer-events: none;
}
.dm-short-news{
display:inline-block;
overflow: hidden;
width: 390px;
height: 40px;
background: red;
}
.dm-short-news:hover~.dm-intro-news{
margin-top:-50px;
}
<div class="wr">
<div class="dm-short-news"></div>
<div class="dm-intro-news"></div>
</div>

Mask position incorrect when I stop using a background image

Using http://jsfiddle.net/4UNuB/5/ as an example, the image has been set as background
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);
background-position: center;
background-repeat: no-repeat;
}
But, if I can't use a background image, and instead have an img src within the div itself like this
<div class="box1">
<img src="http://placehold.it/180x250">
</div>
The mask no longer covers the image, instead sitting below it.
See this fiddle http://jsfiddle.net/4UNuB/6/
But the mask is still being applied to the same place as before, so why does it move, and how to stop it moving?
Add Position Absolute and relative css for boxes.
Check The Fiddle here
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
/*background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);*/
background-position: center;
background-repeat: no-repeat;
position: relative;
}
.black-box {
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00,00,00,0.8);
width: 100%;
height: 100%;
opacity: 1.0;
transition: all 0.5s ease-in-out;
position: absolute;
top: 0;
}
You can put both in the same anchor and use positioning + z-index:
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
/*background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);
background-position: center;
background-repeat: no-repeat;*/
}
img {
position: absolute;
z-index: 0;
}
.black-box {
position: relative;
z-index: 1;
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00,00,00,0.8);
width: 100%;
height: 100%;
opacity: 1.0;
transition: all 0.5s ease-in-out;
}
.black-box:hover {
opacity: 0.0;
transition: all 0.5s ease-in-out;
}
h2 {
padding-top: 110px;
margin: 0px;
}
<div class="box1">
<a href="http://placehold.it">
<img src="http://placehold.it/180x250">
<div class="black-box">
<h2>View Details</h2>
</div>
</a>
</div>
Also, I had to remove the h2's margin.

Overflow hidden not working on hover

I have this div and I want to show the title when I hover over title div. The problem is that I get the hover effect even if I hover on the edges of the div. So the div is treated as a square and not as a circle when I hover on it. This works pretty well on Firefox but not on Chrome and Safari.
Fiddle: http://jsfiddle.net/roeg629c/2/
Note: I do not want to change the aspect ratio of the image. The image should be 100% of the parent height.
HTML
<div class="video_wrap update" video_name="rikthejmna">
<div class="related img_wrap"><img src="http://img.youtube.com/vi/XyzYVpJGRG8/hqdefault.jpg"></div>
<div class="title">rikthejm na</div>
</div>
CSS
.video_wrap {
width: 232px;
height: 232px;
display: inline-block;
border-radius: 116px;
overflow: hidden;
margin: 10px;
position: relative;
z-index: 2;
}
.img_wrap img {height: 100%}
.related {height: 100%;}
.title {
position: relative;
top: -50px;
left: 0px;
background: #fff;
height: 50px;
opacity: .5;
color: #f8008c;
font-size: 12px;
text-align: center;
line-height: 50px;
overflow: hidden;
cursor: default;
transition: all .5s ease-in;
}
.title:hover {opacity: 1}
Avoid positioning of the .title, and opacity.
.video_wrap{
width: 232px;
height: 232px;
border-radius: 50%;
overflow: hidden;
margin: 10px;
}
.related {
width: 232px;
height: 232px;
position: absolute;
border-radius: 50%;
overflow: hidden;
z-index: -1;
}
.img_wrap img {
height: 100%;
}
.title{
margin: 185px 0 0;
background: rgba(255,255,255,.5);
line-height: 50px;
text-align: center;
transition: all .5s ease-in;
}
.title:hover{
background: #fff;
}
<div class="video_wrap update">
<div class="related img_wrap"><img src="http://img.youtube.com/vi/XyzYVpJGRG8/hqdefault.jpg"></div>
<div class="title">
rikthejm na
</div>
</div>

Transition height, get bigger to 2 sides

I just made a text window which gets bigger if you hover over it (with a transition that adds more height). It basically "drops" down to the bottom and pushes away the other text. Is there any way I can make it "drop" to the bottom by 50% and "climb" up by 50%?
#tcontent {
float: left;
background-color: yellow;
height: 150px;
width: 100%;
margin-top: 100px;
}
#mcontent {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 150px;
transition: height 0.5s ease;
}
#bcontent {
float: left;
background-color: green;
height: 30px;
width: 100%;
height: 150px;
}
#mcontent:hover {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 250px;
}
<div id="main">
<div id="tcontent">
</div>
<div id="mcontent">
</div>
<div id="bcontent">
</div>
</div>
This is awkward through conventional means as content flows from left to right, top to bottom and #mcontent needs space to move into above. However, this can be achieved by using flexbox.
Add #main with display: flex; to get its children to use the flexbox model
Add flex-direction: column; to #main to make the children order from top to bottom
Add height: 550px; to #main to make it as high as the three children will be when #mcontent is expanded
Add justify-content: center; to #main to center the children in the middle
The principle behind it is that the elements are set to always be in the middle of #main. When #mcontent grows, it pushes #tcontent up and #bcontent because they have space to move into. As they are set to be centered #mcontent will stay in the middle.
#main {
display: flex;
flex-direction: column;
height: 550px;
justify-content: center;
}
#tcontent {
background-color: yellow;
height: 150px;
width: 100%;
}
#mcontent {
background-color: blue;
height: 150px;
transition: height 0.5s ease;
width: 100%;
}
#mcontent:hover {
height: 250px;
}
#bcontent {
background-color: green;
height: 150px;
width: 100%;
}
<div id="main">
<div id="tcontent"></div>
<div id="mcontent"></div>
<div id="bcontent"></div>
</div>
The reason the div pushes and moves down is the default behavior of CSS height is to increase the height to the bottom. You can use a new CSS3 feature: Transformation . Precisely, the scale() function.
CSS:
Add these lines to your style
#mcontent {
transition: all 0.5s ease;
}
#mcontent:hover {
-ms-transform: scale(1, 1.2);
-webkit-transform: scale(1, 1.2);
transform: scale(1, 1.2);
height: 185px;
}
Also, in your stylesheet you're using multiple height properties together, in a single block. That's not a good practice, try cleaning those up.
#mcontent {
height: 30px; /* this line is not necessary */
height: 150px; /* as this line overrides the first one */
}
Please see my fiddle here.
I used margin-top: -50px; and animated the margin as well. Used margin for the top expansion and let the bottom expansion still make the div below slide.
EDITED CSS
#mcontent {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 150px;
transition: height 0.5s ease, margin-top 0.5s ease;
}
#mcontent:hover {
height: 250px;
margin-top: -50px;
}
Use transform: scale(1,2); as shown in the snippet.
In your css you set height multiple times, try to avoid this. Also in the :hover declaration you only need to specify the parameters who change. So in this case only transform.
#tcontent {
float: left;
background-color: yellow;
height: 150px;
width: 100%;
margin-top: 100px;
}
#mcontent {
float: left;
background-color: blue;
width: 100%;
height: 150px;
transition: all 0.5s ease;
}
#bcontent {
float: left;
background-color: green;
width: 100%;
height: 150px;
}
#mcontent:hover {
transform: scale(1,2)
}
<div id="main">
<div id="tcontent">
</div>
<div id="mcontent">
</div>
<div id="bcontent">
</div>
</div>
If you can allow the effect to occur when hovering over #main and not just #mcontent, this works perfectly:
#main > div {
transition: all 0.5s ease;
}
#tcontent {
float: left;
background-color: yellow;
height: 150px;
width: 100%;
margin-top: 100px;
}
#mcontent {
float: left;
background-color: blue;
height: 30px;
width: 100%;
height: 150px;
/* new */
position: relative;
}
#bcontent {
float: left;
background-color: green;
height: 30px;
width: 100%;
height: 150px;
transition: all 0.5s ease;
}
#main:hover #mcontent {
height: 250px;
margin-top: -50px;
}
#main:hover #tcontent {
transform: translateY(-50px);
}
Fiddle demo here.