I have pictures on a page, and when I hover over them, a blue border appears
But this frame appears abruptly, but I would like it to gradually shrink from the edges of the picture and stand in the same place, can I do this?
Here are my styles
.article-block__img-wrapper {
position: relative;
}
.article-block__img-wrapper span {
position: relative;
display: inline-block;
}
.article-block__img-wrapper span::before {
display: block;
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
transition: 0.2s ease-in-out;
outline: 1px solid #4F8EFF;
outline-offset: -10px;
opacity: 0;
}
.article-block__img-wrapper:hover span::before {
opacity: 1;
}
<div class="article-block">
<div class="article-block__img-wrapper">
<span>
<img class="block-img" src="https://via.placeholder.com/500" alt="" title="">
</span>
</div>
</div>
The simplest way would be to expand on your current animation using transition.
transition: opacity 0.2s ease-in-out, outline-offset 0.2s ease-in-out;
You can edit the timing/easing independently for each style.
Then apply outline-offset: -10px; inside your hover styles.
Functional Codepen example of the below code (Since I don't think Stack snippets support LESS) available here.
<div class="article-block">
<div class="article-block__img-wrapper">
<span>
<img class="block-img" src="https://picsum.photos/300" alt="" title="">
</span>
</div>
</div>
.article-block__img-wrapper {
position: relative;
display: inline-block;
span {
position: relative;
display: inline-block;
&::before {
display: block;
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
transition: opacity 0.2s ease-in-out, outline-offset 0.2s ease-in-out;
outline: 1px solid #4f8eff;
outline-offset: 0;
opacity: 0;
}
}
&:hover {
span::before {
opacity: 1;
outline-offset: -10px;
}
}
}
Related
Help i work on hover link effect, the effect is opacity. The effect is working but it stop when i hover the caption inside it its stop the effect.
here the code of the css:
a .hover11 img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
a .hover11 img:hover {
opacity: .5;
}
.imagebig {
position: relative;
width: 24%;
/* for IE 6 */
height: 60%;
background: #D9138E;
background: linear-gradient(#D9138E, rgba(0, 0, 0, 0));
border: solid 1px #FFFFFF;
display: inline-block;
}
h2 {
position: absolute;
bottom: -10px;
left: 0;
width: 100%;
display: block;
<a href="">
<div class="imagebig hover11" align="left">
<img style="width:100%; height:100%" src="//placehold.it/100" alt="" />
<h2>Kung Fu Panda</h2>
</div>
</a>
The last one is the html. Is there anyway to stop the h2 stopping the effect when hover ? I already try user-select its not work
try this
a .hover11:hover img {
opacity: .5;
}
instead of this :
a .hover11 img:hover{
opacity: .5;
}
You have given hover effect on image tag only that's the reason your hover effect don't work on text.
So instead of giving hover effect on image tag give hover effect on outer div and it will work for both image as well as text.
Use this:
a .hover11:hover img {
opacity: .5;
}
Just add pointer-events: none; this will prevent the hover effect on h2
a .hover11 img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
a .hover11 img:hover {
opacity: .5;
}
.imagebig {
position: relative;
width: 24%;
/* for IE 6 */
height: 60%;
background: #D9138E;
background: linear-gradient(#D9138E, rgba(0, 0, 0, 0));
border: solid 1px #FFFFFF;
display: inline-block;
}
h2 {
position: absolute;
bottom: -10px;
left: 0;
width: 100%;
display: block;
pointer-events: none;
}
<a href="">
<div class="imagebig hover11" align="left">
<img style="width:100%; height:100%" src="//placehold.it/100" alt="" />
<h2>Kung Fu Panda</h2>
</div>
</a>
Alright, so, I'm still fairly new to CSS and HTML and have run into another problem. I couldn't seem to find my question already answered on here, but I hope to be redirected if someone finds out it has been asked and answered. Anyway, I'm using flex-box and attempting to horizontally align these three boxes within a wrapping div element. The three boxes themselves are relatively positioned, with a single absolutely positioned rectangle within each. So a div, surrounding three div boxes, surrounding a single rectangular div each.
image example
I've managed to horizontally align them, but I've found an issue. The rectangular divs inside the three boxes are set up to "pull" out from the side of the boxes and form a band across with a tooltip over the front. I haven't even started work on the third box yet, because only the first box works how it's supposed to. The second box, for some reason, isn't functioning, and the absolute positioning of its band seems to be latching onto the header. So instead of pulling out from the side of its box, it is pulling out from the top side of the screen.
image example
When I delete the first box, the second box works fabulously. But both of them together, the first works, and the second blunders. Wrapping the faulty box in a second div prevents the problem. Also, borders don't show when I try to see where the apparently non-functioning div is, and letters typed within the div's HTML appear outside the image of the box. There is also a tiny dot below the element, or sometimes appearing beside it, that triggers the tooltip when hovered over.
What could possibly be the error? Are the two boxes somehow interacting and slipping each other up? Have I missed something? Help, please!
#bodyWrap {
display: inline-flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
justify-content: space-around;
}
/* (1st) thumbnail begin */
.icon01 {
height: 177px;
width: 177px;
position: relative;
text-align: center;
background-color: #ff0000;
}
.icon01 img {
border: 1px solid #000000;
}
.expThumb {
position: relative;
top: 0;
opacity: 0;
visibility: hidden;
z-index: 3;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.tooltip {
position: absolute;
width: 0;
top: 25%;
bottom: 0;
left: 0;
right: 0;
color: #ffffff;
opacity: 0;
visibility: hidden;
z-index: 2;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.band {
position: absolute;
width: 0;
height: 88px;
top: 25%;
bottom: 0;
left: 0;
right: 0;
background: #000000;
opacity: 0;
visibility: hidden;
z-index: 1;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.icon01:hover .tooltip {
width: 177px;
visibility: visible;
opacity: 1;
}
.icon01:hover .band {
width: 178px;
visibility: visible;
opacity: 1;
}
.icon01:click .expThumb
/* (1st) thumbnail end */
/* (2nd) thumbnail begin */
.icon02 {
height: 177px;
width: 177px;
position: relative;
text-align: center;
background-color: #ff0000;
}
.icon02 img {
border: 1px solid #000000;
}
/* insert expanded image here
. {
position:absolute;
top:0;
opacity:0;
visibility:hidden;
z-index:6;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
*/
.tooltip2 {
position: absolute;
width: 0;
top: 25%;
bottom: 0;
left: 0;
right: 0;
color: #ffffff;
opacity: 0;
visibility: hidden;
z-index: 5;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.band2 {
position: absolute;
width: 0;
height: 88px;
top: 25%;
bottom: 0;
left: 0;
right: 0;
background: #000000;
opacity: 0;
visibility: hidden;
z-index: 4;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.icon02:hover .tooltip2 {
width: 177px;
visibility: visible;
opacity: 1;
}
.icon02:hover .band2 {
width: 178px;
visibility: visible;
opacity: 1;
}
.icon02:click .expThumb2
/* (2nd) thumbnail end */
<div id="bodyWrap">
<div class="icon01">
<a href="#info">
<img src="img/thumb.jpg" alt="box">
<img class="expThumb" src="img/thumb2.png">
<h2 class="tooltip">aTip</h2>
<div class="band"></div>
</a>
</div>
<div class="icon02">
<a href="#info">
<img src="img/thumb_announce.jpg" alt="box">
<img class="" src="">
<h2 class="tooltip2">aTip</h2>
<div class="band2"></div>
</a>
</div>
<div class="icon03">
<a href="#info">
<img src="img/thumb_announce.jpg" alt="box">
<img class="" src="">
<h2 class="tooltip3">aTip</h2>
<div class="band3"></div>
</a>
</div>
<div id="info" class="active">
<p>blahlbahlbahlbhalbhalbhalbhalbhalbhalbhalbhalah</p>
</div>
</div>
only .icon01 is position: relative;. The other parents, .icon02, .icon03 are statically positioned.
You can make those divs relative with the child combinator selector, or you could give them all a common class and target them that way, or you could just do .icon01, .icon02, .icon03 { position: relative; }. I'm using the child combinator selector here.
#bodyWrap > div {
position: relative;
}
#bodyWrap {
display: inline-flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
justify-content: space-around;
}
/* (1st) thumbnail begin */
.icon01 {
height: 177px;
width: 177px;
position: relative;
text-align: center;
background-color: #ff0000;
}
.icon01 img {
border: 1px solid #000000;
}
.expThumb {
position: relative;
top: 0;
opacity: 0;
visibility: hidden;
z-index: 3;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.tooltip {
position: absolute;
width: 0;
top: 25%;
bottom: 0;
left: 0;
right: 0;
color: #ffffff;
opacity: 0;
visibility: hidden;
z-index: 2;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.band {
position: absolute;
width: 0;
height: 88px;
top: 25%;
bottom: 0;
left: 0;
right: 0;
background: #000000;
opacity: 0;
visibility: hidden;
z-index: 1;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.icon01:hover .tooltip {
width: 177px;
visibility: visible;
opacity: 1;
}
.icon01:hover .band {
width: 178px;
visibility: visible;
opacity: 1;
}
.icon01:click .expThumb
/* (1st) thumbnail end */
/* (2nd) thumbnail begin */
.icon02 {
height: 177px;
width: 177px;
position: relative;
text-align: center;
background-color: #ff0000;
}
.icon02 img {
border: 1px solid #000000;
}
/* insert expanded image here
. {
position:absolute;
top:0;
opacity:0;
visibility:hidden;
z-index:6;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
*/
.tooltip2 {
position: absolute;
width: 0;
top: 25%;
bottom: 0;
left: 0;
right: 0;
color: #ffffff;
opacity: 0;
visibility: hidden;
z-index: 5;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.band2 {
position: absolute;
width: 0;
height: 88px;
top: 25%;
bottom: 0;
left: 0;
right: 0;
background: #000000;
opacity: 0;
visibility: hidden;
z-index: 4;
-webkit-transition: 0.2s;
-moz-transition: 0.2s;
-o-transition: 0.2s;
transition: 0.2s;
}
.icon02:hover .tooltip2 {
width: 177px;
visibility: visible;
opacity: 1;
}
.icon02:hover .band2 {
width: 178px;
visibility: visible;
opacity: 1;
}
.icon02:click .expThumb2
/* (2nd) thumbnail end */
<div id="bodyWrap">
<div class="icon01">
<a href="#info">
<img src="img/thumb.jpg" alt="box">
<img class="expThumb" src="img/thumb2.png">
<h2 class="tooltip">aTip</h2>
<div class="band"></div>
</a>
</div>
<div class="icon02">
<a href="#info">
<img src="img/thumb_announce.jpg" alt="box">
<img class="" src="">
<h2 class="tooltip2">aTip</h2>
<div class="band2"></div>
</a>
</div>
<div class="icon03">
<a href="#info">
<img src="img/thumb_announce.jpg" alt="box">
<img class="" src="">
<h2 class="tooltip3">aTip</h2>
<div class="band3"></div>
</a>
</div>
<div id="info" class="active">
<p>blahlbahlbahlbhalbhalbhalbhalbhalbhalbhalbhalah</p>
</div>
</div>
I have an image and I try to make the top 50% show a different colour and text when hover over. And the same for the lower 50% of the height of the image.
I came so far to get the below 50% but its all over the page, not just the image, and the top 50% doesnt show. Is it possible to achieve my goal?
BOOTPLY... BOOTPLY
/* CSS used here will be applied after bootstrap.css */
.image img {
display: block;
}
.thumb-wrap img {
width: 50%;
height: auto;
}
.thumb-wrap:hover .thumb-caption {
opacity: 0.7;
}
.thumb-caption {
position: absolute;
left: 0px;
bottom: 0;
width: 100%;
height: 50%;
background-color: #000;
margin: 0;
z-index: 1;
text-align: center;
opacity: 0;
-webkit-transition: all, .5s;
-moz-transition: all, .5s;
-o-transition: all, .5s;
-ms-transition: all, .5s;
transition: all, .5s;
}
/*.thumb-caption-above {
position: absolute;
left: 0px;
top: 0;
width: 100%;
height: 50%;
background-color:red;
margin: 0;
z-index: 0;
text-align: center;
opacity: 0;
-webkit-transition: all, .5s;
-moz-transition: all, .5s;
-o-transition: all, .5s;
-ms-transition: all, .5s;
transition: all, .5s;
}*/
<div class="image">
<div class="thumb-wrap">
<img src="http://placehold.it/550x150">
<h2 class="thumb-caption"><a href="#">More info
</a></h2>
<h2 class="thumb-caption-above"><a href="#">See larger
</a></h2>
</div></div>
<div id="push"></div>
Try this:
.thumb-wrap {
width: 550px;
position: relative;
}
.thumb-caption:hover {
opacity: 0.7;
}
/* Default styles for hover block */
.thumb-caption {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 50%;
background-color: #000;
margin: 0;
z-index: 1;
text-align: center;
opacity: 0;
transition: all, .5s;
}
/* Alternate positioning and background color */
.thumb-caption.above {
top: 0;
background: red;
}
/* For the text color */
.thumb-caption > a {
color: blue; /* default */
}
.thumb-caption.above > a {
color: yellow; /* alternate */
}
<div class="image">
<div class="thumb-wrap">
<img src="http://placehold.it/550x150">
<h2 class="thumb-caption">More info</h2>
<h2 class="thumb-caption above">See larger</h2>
</div>
</div>
The important part for positioning was adding position: relative on your .thumb-wrap container element. I removed the CSS browser prefixes for brevity, but you could add them back in.
The following example shows up both alternatives (info and zoom) at the same time, with the one immediately on hover highlighted.
* {
font-size:1.05em;
color: white;
font-family: arial;
}
#image {
width:550px;
height:150px;
position:relative;
background: url('http://i.imgur.com/HNj6tRD.jpg');
background-repeat: no-repeat;
background-size:100% 100%;
}
.coverUP {
width: 100%;
height: 50%;
position:absolute;
top:0%;
}
.coverDOWN {
width: 100%;
height: 50%;
position:absolute;
top:50%;
}
.coverUP:hover::after {
background: #cc99ff;
opacity: 0.6;
pointer-events: none;
transition: all, 0.6s;
}
.coverDOWN:hover::before {
background: #cc99ff;
opacity: 0.6;
pointer-events: none;
transition: all, 0.6s;
}
.coverUP:hover::before {
background: purple;
opacity: 0.8;
pointer-events: none;
transition: all, 0.6s;
}
.coverDOWN:hover::after {
background: purple;
opacity: 0.8;
pointer-events: none;
transition: all, 0.6s;
}
.coverUP::after {
content: "\A ZOOM";
white-space: pre;
text-align:center;
width: 100%;
height: 100%;
background: #cc99ff;
position:absolute;
top:100%;
opacity: 0.0;
pointer-events: none;
transition: all, 0.6s;
}
.coverDOWN::before {
content: "\A INFO";
white-space: pre;
text-align:center;
width: 100%;
height: 100%;
background: #cc99ff;
position:absolute;
top:-100%;
opacity: 0.0;
pointer-events: none;
transition: all, 0.6s;
}
.coverUP::before {
content: "\A INFO";
white-space: pre;
text-align:center;
width: 100%;
height: 100%;
background: purple;
position:absolute;
top:0%;
opacity: 0.0;
pointer-events: none;
transition: all, 0.6s;
}
.coverDOWN::after {
content: "\A ZOOM";
white-space: pre;
text-align:center;
width: 100%;
height: 100%;
background: purple;
position:absolute;
top:0%;
opacity: 0.0;
pointer-events: none;
transition: all, 0.6s;
}
<div id="image" alt=image>
<a href="#">
<div class="coverUP"></div>
</a>
<a href="#">
<div class="coverDOWN"></div>
</a>
</div>
I've consulted these similar questions, 1, 2, 3, 4, but couldn't find the solution to my problem.
I have a simple play button and semi-transparent div transition when hovering over a block-level link which is placed over an image.
The problem is that the divs jitter when moving the mouse vertically over the image.
There are two exceptions to this behavior (in which case, the transition and div behavior run smoothly):
Moving the cursor vertically and parallel to
<span class="play">
and moving the mouse horizontally across the div.
/*------- Media Play Button -------*/
.vThumb {
position: relative;
width: 100%;
height: auto;
font-size: 0;
}
.vThumb img {
position: relative;
width: 100%;
display: block;
z-index: -1;
opacity: .5;
}
.vThumb a {
position: absolute;
top: 0;
display: block;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
}
.vThumb a .play,
.vThumb a .vOverlay {
opacity: 0;
}
.vThumb a:hover .play {
position: relative;
font-size: 14vw;
color: #f00;
top: 50%;
transform: translateY(-50%);
z-index: 1001;
opacity: .95;
border: none;
display: block;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.vThumb a:hover ~ .vOverlay {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-color: #f00;
opacity: .3;
z-index: 1000;
display: inline-block;
transition: opacity .15s ease-in-out;
-moz-transition: opacity .15s ease-in-out;
-webkit-transition: opacity .15s ease-in-out;
}
/*------- End Media Play Button -------*/
<div class="vThumb">
<a href="#">
<span class="play">►</span>
</a>
<div class="vOverlay">
</div>
<img src="http://i.imgur.com/wZzgmVt.jpg">
</div>
Unlike the similar questions mentioned above nothing here is changing size and the issue occurs across all browsers. What am I doing wrong?
The reason you're seeing the flickering is because of the selector .vThumb a:hover ~ .vOverlay.
You are only applying styling to the .vOverlay element when hovering over the previous a element. When the .vOverlay element appears, it is positioned over the a element (which means that you are no longer hovering over the a element), resulting in it disappearing and repeating again.
You can easily prevent this by applying the styling when hovering over .vOverlay as well (rather than only applying it when hovering over the a element).
In other words, you want the following:
.vThumb a:hover ~ .vOverlay,
.vOverlay:hover {
/* ... */
}
However, that will result in the play button not being visible (since you are no longer hovering over the a element either).
You can resolve this by changing the selector .vThumb a:hover .play to .vThumb:hover .play.
Updated Example:
.vThumb {
position: relative;
width: 100%;
height: auto;
font-size: 0;
}
.vThumb img {
position: relative;
width: 100%;
display: block;
z-index: -1;
opacity: .5;
}
.vThumb a {
position: absolute;
top: 0;
display: block;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
}
.vThumb a .play,
.vThumb a .vOverlay {
opacity: 0;
}
.vThumb:hover .play {
position: relative;
font-size: 14vw;
color: #f00;
top: 50%;
transform: translateY(-50%);
z-index: 1001;
opacity: .95;
border: none;
display: block;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.vThumb a:hover ~ .vOverlay,
.vOverlay:hover {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-color: #f00;
opacity: .3;
z-index: 1000;
display: inline-block;
transition: opacity .15s ease-in-out;
-moz-transition: opacity .15s ease-in-out;
-webkit-transition: opacity .15s ease-in-out;
}
<div class="vThumb">
<a href="#">
<span class="play">►</span>
</a>
<div class="vOverlay"></div>
<img src="http://i.imgur.com/wZzgmVt.jpg">
</div>
I made this rollover:
jsfiddle.net/DH6Lu/
But as you can see the background image glitches. This is not the case when I don't use the opacity on the main div:
http://jsfiddle.net/6KT9p/
Any idea what is wrong?
<div id="opacity">
<div class="box">
<a class="link" href="#">
<div class="inner">
<img src="http://lorempixel.com/340/192/" width="340" height="192">
<div class="description">
<h3>titel2</h3>
</div>
</div>
</a>
</div>
</div>
.box {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.inner {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
overflow: hidden;
}
.inner img {
position: absolute;
opacity: 1;
-webkit-transition: opacity 0.5s ease;
}
.inner img:hover {
opacity: 0.15
}
.description {
background: url(http://www.merkendiewerken.be/wp-content/themes/merkendiewerken/img/close-recent.png) #aaa repeat 0 0 fixed;
width: 340px;
height: 192px;
position: absolute;
z-index: -1;
}
.description h3 {
color: #fff;
font-size: 18px;
text-transform: uppercase;
text-align: center;
position: absolute;
}
#opacity {
opacity: 0.5
}
The problem arises from the fixed property of the background.
Set the CSS to
.description {
background: url(http://www.merkendiewerken.be/wp-content/themes/merkendiewerken/img/close-recent.png) #aaa repeat 0 0;
width: 340px;
height: 192px;
position: absolute;
z-index: -1;
}
and it will work
fiddle
The problem is also linked to the GPU handling this different from the CPU. The GPU is handling the background during the transtion, the CPU in the static states. If you set transform: translateZ(1px) - one of the usual tricks to enable GPU - the background will be permanently in an offset. It solves the glitch, but the look isn't correct.
I guess it glitches because .inner inherits the opacity from #opacity... but I don't know why. Interesting.
Still, I have a workaround for your case, if you want to keep the initial alpha to 0.5: make the .inner half visible, hide the .description unless it's hovered.
The adjacent sibling selector + is useful to show the description when the image is hovered.
Here's what you have to add (existent properties omitted):
.inner img {
-webkit-transition: opacity 0.5s ease;
opacity:0.5;
}
.inner img:hover{
opacity:0.15;
}
.inner img:hover + .description{
opacity:1;
}
.description {
-webkit-transition: opacity 0.5s ease;
opacity:0;
}
Here's a working demo for this.