.profile__change-image-button should appear on hover (while the image changes opacity to 0.8) and clicking on it is supposed to open a form. With my current code, opacity is applied on hover and the icon does appear, but it disappears with every move of the mouse, which it makes it difficult to open the popup form. The end result should be- opacity changed to 0.8 on hover + icon appear and disappear only when the mouse moves outside the borders of the image. Thank you very much in advance!
.profile__user {
max-width: 583px;
display: flex;
position: relative;
}
.profile__image {
background-size: cover;
background-position: center;
width: 120px;
height: 120px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.profile__change-image-button {
width: 26px;
height: 26px;
background: transparent;
border: none;
position: absolute;
left: 47px;
bottom: 56px;
}
.profile__change-image-button-hide {
display: none;
}
.profile__image:hover {
opacity: 0.8;
}
.profile__image:hover + .profile__change-image-button-hide {
display: block;
}
<div class="profile__user">
<div
class="profile__image"
title="An image of the French oceanographer- Jacques Cousteau"
></div>
<div class="profile__change-image-button-hide">
<button type="button" class="profile__change-image-button">
<img
src="<%=require('./images/edit-profile-icon.svg')%>"
alt="A vector image of a pen inside the profile image"
class="profile__change-image-icon"
/>
</button>
</div>
<div class="profile__info">
<h1 class="profile__title"></h1>
<button type="button" class="profile__edit-button">
<img
src="<%=require('./images/button-edit.svg')%>"
alt="A vector image of a pen inside the edit button"
class="profile__edit-icon"
/>
</button>
<p class="profile__subtitle"></p>
</div>
</div>
There is a lot of html and css rules going on so I simplified the code to give what I believe you are looking to do. Also I've imported an icon font to get the button image you described. It's not a vector graphic but it can be with a simple change.
#import url("https://cdn.jsdelivr.net/npm/bootstrap-icons#1.9.1/font/bootstrap-icons.css");
.profile__user {
position: relative;
display: inline-block;
}
.profile__image {
background-image: url("https://picsum.photos/id/1027/120");
height: 120px;
width: 120px;
border-radius: 50%;
border: none;
opacity: 1;
transition: opacity .5s;
}
.profile__change-image-button {
position: absolute;
height: 24px;
width: 24px;
bottom: 16px;
right: 16px;
padding: 4px;
border-radius: 5px;
border: none;
opacity: 0;
transition: opacity .5s;
}
.profile__image:hover {
opacity: .8;
}
.profile__image:hover .profile__change-image-button {
opacity: 1;
}
<div class="profile__user">
<div class="profile__image" title="An image of the French oceanographer- Jacques Cousteau">
<button type="button" class="profile__change-image-button">
<i class="bi bi-pencil-square"></i>
</button>
</div>
</div>
Related
I am making a gallery of imgage as a feature on my website, the gallery will represent the images as a grid.
I would like to be able to hover over a grid item and have the image turn to complete black and have text overlay on top in white but struggling to structure this effect using CSS.
I am targeting 'post_feature_outer' and effecting the colour of the text within that div from transparent to white.
The text is appearing white when hovering on the square as expected. I would also like the image to turn completely black as well
CSS filter does not work as this also removes the text, does anyone know how to get the effect?
Below is an example of what I mean when no hovering vs hovering on the tile.
Thank You
NO HOVER:
HOVER:
Thank you!
.post_feature_outer {
color: rgba(0, 0, 0, 0);
}
.post_feature_outer:hover {
color: white;
}
/* added by community for clarity */
body {
background: #222;
}
<div class='post_feature_outer'>
<h1 class="post_feature_title">VOGUE ITALIA – JUNE 2022 ISSUE</h1>
<img class="post_feature_img" src="https://via.placeholder.com/300x200" />
</div>
i think this helps:
.post_feature_outer {
width: 600px;
height: 200px;
position: relative;
}
.post_feature_title {
margin: 0;
align-items: center;
justify-content: center;
background-color: black;
color: white;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
display: none;
}
.post_feature_img {
width: 100%;
height: 100%;
}
.post_feature_outer:hover .post_feature_title {
display: flex;
}
<div class='post_feature_outer'>
<h1 class="post_feature_title">VOGUE ITALIA – JUNE 2022 ISSUE</h1>
<img class="post_feature_img" src="https://upload.wikimedia.org/wikipedia/commons/8/84/Flag_of_Uzbekistan.svg" />
</div>
I think I'd use absolute positioning to layer the heading and image, along with opacity for the show/hide effect.
.post_feature_outer {
background-color: #000;
display: inline-block;
position: relative;
}
.post_feature_title {
position: absolute;
top: 50%;
left: 0;
width: 100%;
transform: translateY(-50%);
text-align: center;
transition: all 0.3s;
color: white;
opacity: 0;
}
.post_feature_img {
transition: all 0.3s;
font-size: 0;
display: block;
}
.post_feature_outer:hover .post_feature_title {
opacity: 1;
}
.post_feature_outer:hover .post_feature_img {
opacity: 0;
}
<div class='post_feature_outer'>
<div class="post_feature_title">
<h1>VOGUE ITALIA – JUNE 2022 ISSUE</h1>
</div>
<img class="post_feature_img" src="https://via.placeholder.com/300x200" />
</div>
I have an image of width: 1260, height: 709.
I want to set opacity to 0.4 AND a clickable link to appear in the centre of the image on hover, preferably only when the user hovers over the centre of the image (pixel co-ordinates 420, 230, 850, 510).
I can create an overlay to satisfy the opacity. And using map I can get the co-ordinates to link to another page. But I can't see how to get both conditions satisfied at the same time. To be as clear as I can, I want the image co-ordinates (or just the centre of the image in general) to link with a text that appears on hover while the opacity of the image as a whole is also down at 0.4. Here's my work so far.
HTML
<div class="image-container fade" data-text="Shop Processors">
<img src="images/shop/cpu.png" alt="" usemap="#processorMap">
<map name="processorMap">
<area shape="rect" coords="420, 230, 850, 510" href="index.html" alt="">
</map>
</div>
CSS
main {
text-align: center;
}
.image-container {
height: 709px;
width: 1260px;
position: relative;
text-align: center;
}
.fade::after {
content: attr(data-text);
color: white;
font-size: 40px;
background: black;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity 0.3s ease;
white-space: pre-wrap;
}
.fade:hover::after {
opacity: 0.8;
}
This should do what you want, and is a simpler approach at the same time.
.image-container {
width: 240px;
height: 160px;
position: relative;
}
.image,
.link-container {
transition: opacity 0.3s ease;
}
.link-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
}
.link {
display: block;
background-color: rgba(0,0,0,0.8);
color: #fff;
padding: 8px;
}
.image-container:hover .link-container {
opacity: 1;
}
.image-container:hover .image {
opacity: 0.4;
}
<div class="image-container fade">
<img class="image" src="https://placekitten.com/240/160" alt="">
<div class="link-container">
<a class="link" href="#">Shop Processors</a>
</div>
</div>
We put a .link-container on top of the image with opacity: 0 and position: absolute and stretch it to all sides so it covers the whole image.
Then inside that container we include our link. The container has display: flex and two properties which center the link horizontally and vertically inside of it.
Lastly we add transitions to both the link-container and to the image, and trigger both opacities with .image-container:hover
I would like to add a link to an image that has an overlay applied to it. When users hover over the image they get an opaque overlay and text appear. This works great, however I also need users to be able to click that image and taken to a link.
I have pasted my code below - the overlay works but the link portion does not. I believe it's because the overlay is interfering. I tried changing the placement of the link but was unable to do so. I am able to make the '+' be the link, but ideally the entire image should link.
Any thoughts?
JSFiddle
.roomphoto:hover .img__description { transform: translateY(0); }
.roomphoto .img__description_layer { top: 30px; }
.roomphoto:hover .img__description_layer { visibility: visible; opacity: 1; }
.img__description_layer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
color: #cdcbca;
visibility: hidden;
opacity: 0;
display: flex;
align-items: center;
justify-content: center;
transition: opacity .2s, visibility .2s;
}
.roomphoto {
height: 166px;
}
.img__description {
transition: .2s;
transform: translateY(1em);
z-index: 999;
}
.overlay {
position: relative;
}
.overlay:after {
position: absolute;
content:"";
top:0;
left:0;
width:100%;
height:100%;
opacity:0;
}
.overlay:hover:after {
opacity: .8;
}
.blue:after {
background-color: #1a3761;
}
.img__description a {
color: #fff;
}
.roomselect {
clear: both;
float: none;
width: 100%;
max-width: 1000px;
margin: 0px auto;
padding-top: 20px;
}
.roomselect img {
width: 100%;
margin-bottom: -10px;
}
.room3 {
width: 32%;
text-align: left;
float:left;
}
<div class="roomselect"><div class="room3">
<div class="roomphoto overlay blue">
<a href="http://www.google.com">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
</a>
<div class="img__description_layer">
<p class="img__description">
<span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span>
</p>
</div>
</div>
</div>
You need to rearrange your html in such a way that when you click on image, you are actually clicking on the anchor tag. I have made some changes to your html, let me know if these work. You might have to increase roomphoto height.
<div class="roomselect">
<div class="room3">
<a href="http://www.google.com">
<div class="roomphoto overlay blue">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
<div class="img__description_layer">
<p class="img__description"><span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span></p>
</div>
</div>
</a>
</div>
</div>
Hello I'm trying to hide / display an absolute positioned text on image hover with transform scale effect and shadowing background I had some problems with z-index and div containers. What I'm trying to achive is:
Before hover:
On hover:
I know I could wrap text into div and then change visibility or display css property on hover but it doesn't work for me. Here is my code:
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-lg-4 column" *ngFor="let clientProject of clientProjects; let i= index">
<button class="btn button-modal" data-toggle="modal" [attr.data-target]="'#' + i">
<span class="hidden-text">TEXT</span>
<img src="{{clientProject.clickImageButtonPath}}" class="img-fluid image">
</button>
</div>
</div>
</div>
css:
.image {
width: 100%;
height: 400px;
transition: all 0.3s ease-in-out;
z-index: 1;
opacity: 0.35;
}
.button-modal {
padding: 0 !important;
overflow: hidden;
background-color: black;
}
.button-modal:hover {
padding: 0 !important;
}
.hidden-text:hover + .image,
.image:hover {
transform: scale(1.2);
}
.column {
margin: 0 !important;
border: none;
padding: 0 !important;
}
.hidden-text {
display: block;
z-index: 2;
color: white;
font-size: 2rem;
border: none;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin: 0;
position: absolute !important;
}
Could someone help with this please?
I'm not sure what you're trying to do exactly, so I think it would be good to figure out what element you want to trigger the action on, then tell that element to hide and show the text. I'm also not sure if you're trying to do this all CSS or not, but I would typically do something like this. Be aware that this is jQuery, which I assume you're using if you're using bootstrap, and this is just an example of what you can do with a simple bit of jQuery code in this example. Here's a link to a working fiddle http://jsfiddle.net/aq9Laaew/110775/ and here's the code I used to achieve the result:
$('.button-modal').hover(function(event){
$(this).find('.hidden-text').show();
},function(){
$(this).find('.hidden-text').hide();
});
jQuery hover handler is actually 2 functions inside, one for mouseover (hover start) and one for mouseout (hover end), and it makes this easy, so you can do one thing on the start (show your text) and another on the end (hide your text) all in a nice little packaged function. You can also split these out and do mouseover and mouseout individually. I would also edit your CSS a little if you're going to use this approach, like this:
.button-modal:hover {
padding: 0 !important;
transform: scale(1.2);
}
.column {
margin: 0 !important;
border: none;
padding: 0 !important;
}
.hidden-text {
display: none;
z-index: 2;
color: white;
font-size: 2rem;
border: none;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin: 0;
position: absolute !important;
}
Try this:
<style type="text/stylesheet">
.container:hover #cts {
display: block;
}
</style>
<div class="container">
<div class="img" style="position: absolute; width: 500px; height: 500px; z-index:0;">
<img src="https://i.stack.imgur.com/Az76Y.png"></img>
</div>
<div id="cts" class="text-box" style="display: none; position: absolute; display: table; margin-left: auto; margin-right: auto; background: rgba(0,0,0,0.4); text-align: center; height: 500px; width: 500px; z-index: 1; transition: all .3s ease;">
<div class="text-box-inner" style="display: table-cell; height: 500px; width: 500px; vertical-align: middle; margin-left: auto; margin-right: auto;">
<span class="text" style="color: #fff;">ANY TEXT</span>
</div>
</div>
</div>
<script type="text/javascript">
I am trying to achieve two hover effects on an image.
First, when the user hovers over an image a plus icon on the top right corner of the image appears.
Second, when the user hovers over the plus the icon changes to: “Add to collection”.
All these events need to be smooth transitions.
My first problem is I can't get any smooth transitions going for the first hover.
My second problem is I have no idea how to achieve the second hover - I've done a lot of Google searches but this doesn't seem to be a common effect.
Here is the code I have tried so far (with fill murray placeholder image):
HTML:
<div class="item">
<a href="#" class="item-link">
<img src="https://www.fillmurray.com/g/582/580" alt="dimsum">
</a>
</div>
CSS:
.item-link:hover:before {
content: '';
display: block;
position: absolute;
width: 58px;
height: 58px;
background-image: url('http://i.imgur.com/bWcylV3.png');
border-radius: 50%;
top: 10px;
right: 10px;
}
And here is the js fiddle
Here is the screenshots for what I want to achieve with the second hover:
Just did a little bit changes in your mark up and and find a solution for your issue. Yes, It's not possible to :hover a pseudo-element. Added a new div btn-plus and a span text for convenience. This is done using pure css. Hope this helps :)
.btn-plus:before {
content: '';
display: block;
position: absolute;
width: 58px;
height: 58px;
background-image: url('http://i.imgur.com/bWcylV3.png');
border-radius: 50%;
top: 0px;
right: 30px;
z-index: 1;
}
.btn-plus{
position: absolute;
display: block;
width: 200px;
height: 58px;
top: 30px;
right: 0;
opacity : 0;
transition: all ease .5s;
}
.item-link{
width: 100%;
height: 100%;
display: block;
}
.item-link img{
width: 100%;
}
span.text{
position : absolute;
top: 0px;
right: 0px;
color: #fff;
padding: 15px;
width: 150px;
height: 30px;
border-radius: 30px;
background: rgba(0, 0, 0, 0.5);
z-index: 0;
transition: all ease .5s;
opacity : 0;
}
.item-link:hover .btn-plus{
opacity : 1;
}
.btn-plus:hover span{
opacity : 1;
right: 30px
}
<div class="item">
<a href="#" class="item-link">
<img src="https://www.fillmurray.com/g/582/580" alt="dimsum">
<div class="btn-plus">
<span class="text">Add to list</span>
</div>
</a>
</div>