I created the jsfiddle, to show you what i mean exactly.
When hovering over the text, it should also be possible that the background takes the effect like when hovering over the img/div. Currently the hover effect only works when hovering over the div/img and not when hovering over the text in the middle of the image.. The "a" link should work on the div and text aswell.
https://jsfiddle.net/o5sxhssv/
HTML:
<!--First image-->
<div class="category_images_item">
<a href="">
<span>Watches</span>
<div class="category_images_img" style="background:url(https://static.pexels.com/photos/1279/fashion-wristwatch-time-watch.jpg)no-repeat center;background-size:cover;">
</div>
</a>
</div>
</div>
CSS:
.category_images{
margin: 0 auto
}
.category_images_item{
width: 400px;
height: 400px;
position: relative;
background-color: black;
overflow: hidden;
transition: all .8s ease;
margin: 10px;float: left
}
.category_images_item span{
color: white;
font-weight: bold;
font-size: 50px;
font-style: italic;
z-index: 100;
position: absolute;
width: 100%;
text-align: center;
top: 150px
}
.category_images_img{
background-size: cover;
width: 400px;
height: 400px;
transition: all .8s ease;
opacity: 0.7
}
.category_images_img:hover{
transform: scale(1.03) rotate(-1deg);
opacity: 0.5
}
Thanks alot!! :))
just have to change your hover css rule to this:
.category_images_item:hover .category_images_img{
transform: scale(1.03) rotate(-1deg);
opacity: 0.5
}
put the hover event on your container and apply the css to the child!
EDIT: updated fiddle: https://jsfiddle.net/o5sxhssv/1/
Try this, the anchor tags container both the text and image, so you want the hover on that:
.category_images_item a:hover .category_images_img{
transform: scale(1.03) rotate(-1deg);
opacity: 0.5
}
You can use pointer-events: none on .category_images_item span
Using pointer-events: none says that the cursor does not interact with that element.
Then to make the whole area clickable, make the a element display as a block, this will make the a cover the entire area of it's parent element.
.category_images_item a {
display: block;
}
https://jsfiddle.net/o5sxhssv/2/
If you only want to change the markup, then you could rearrange your code like this:
<div class="category_images">
<!--First image-->
<div class="category_images_item">
<a href="">
<div class="category_images_img" style="background:url(https://static.pexels.com/photos/1279/fashion-wristwatch-time-watch.jpg)no-repeat center;background-size:cover;">
<span>Watches</span></div>
</a>
</div>
</div>
https://jsfiddle.net/tung3yx2/
Related
I'm trying to show a link that appears when I hover over the image. The goal is to fade the image and bring out the link with its background. I tried to do this but I'm doing something wrong. The background of the div comes out of the container. Also I don't know if the opacity method is the right one for hiding and showing.
Also I can't center the link in the image vertically or horizontally
Sorry, I'm new and just don't know how to fix. Someone show me the right way and tell me what I'm doing wrong?
I appreciate any response. Thank you.
.container_left {
width: 20%;
}
.boxItems_first {
display: flex;
flex-direction: column;
}
.boxItems_first a {
position: absolute;
opacity: 0;
}
.boxItems_first:hover a {
position: absolute;
background: black;
width: 100%;
bottom: 60%;
color: #fff;
opacity: 1;
transition: 0.3s;
}
.boxItems_first:hover img {
opacity: 0.3;
transition: 0.3s;
}
<div class="container_left">
<div class="boxItems_first">
Product Page
<img width="auto" height="200" src="https://c.wallhere.com/photos/e5/d3/vertical_animation_fantasy_art-1693403.jpg!d" class="attachment-full size-full" alt="" loading="lazy">
</div>
</div>
You're not too far off. The main thing you're missing is position:relative on the container, otherwise your position:absolute elements will be positioned based on the entire viewport.
You will also want to make sure your transition rules are not just applied on hover - the fade in/out looks quite janky otherwise. As a general rule, put your styles in the base class and only apply changes on hover.
Definitely more than one way to solve this problem but the approach of using position:absolute on the link element and transitioning the opacity on hover is fine. You just need to make the link 100% height and width and then use flex to align its children. Put a <span> around the link text so you can style that for the black background if you want it.
I've made some assumptions based on your post but this snippet should get you started:
.container_left {
width: 20%;
}
.boxItems_first {
display: flex;
position: relative;
flex-direction: column;
}
.boxItems_first img {
transition: all 0.3s linear;
}
.boxItems_first a {
position: absolute;
opacity: 0;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
transition: all 0.3s linear;
color: white;
}
.boxItems_first a span {
background: black;
text-align: center;
padding: 3px;
display: inline-block;
}
.boxItems_first:hover a {
opacity: 1;
}
.boxItems_first:hover img {
opacity: 0.3;
}
<div class="container_left">
<div class="boxItems_first">
<span>Product Page</span>
<img width="auto" height="200" src="https://placedog.net/600" class="attachment-full size-full" alt="" loading="lazy">
</div>
</div>
I have a button with a link inside it, and an animated underline for said link. Code used from here, (example).
To make sure the underline was not huge and far below the text, I applied the animation to the text itself. The problem with this is the hover radius is to small, and I would like the entire button to be able to trigger the animation.
Here is my css and html:
.menuButtonText {
display: inline-block;
position: relative;
padding-bottom: 3px;
}
.menuButtonText:after {
content: '';
display: block;
margin: auto;
height: 2px;
width: 0;
background: transparent;
transition: width .5s ease, background-color .5s ease;
}
.menuButtonText:hover:after {
width: 100%;
background: #E0E0E0;
}
.menuButton {
width: 200px;
height: 100px;
margin: 20px;
background-color: red;
}
<div class="menuButton"><a class="menuButtonText">MenuButton</a>
</div>
<div class="menuButton"><a class="menuButtonText">MenuButton</a>
</div>
<div class="menuButton menuButtonSelected"><a class="menuButtonText">MenuButton</a>
</div>
The "menuButton" class is the parent and much larger than the space the text takes up, which is the trigger I wanted, I can't seem to get other solutions to work, and I'm assuming thats because of the ":after".
This what you're after?
http://jsfiddle.net/19mdzLdk/
I added this css:
.menuButton:hover .menuButtonText:after {
width: 100%;
background: #E0E0E0;
}
Now on div hover, the text underlines.
I want to display images as circle on my webpage. For that, I have an image set as background wrapped inside a div container. Both the divs (outer and inner) have been given a border radius of 50% to achieve this. I also want the image to zoom in oh hover, for which I have applied transform:scale on the inner div.
The image is getting clipped a bit from left and right sides so it doesn't appear as a perfect circle. However, when the image gets scaled up on hover, the image forms a perfect circle. I have tried re-positioning it with background position, tried using a bigger image, increased/decreased size of both divs, but no method is working.
Further, when the image gets zoomed in on hover (using transform:scale), it gets re-positioned slightly after the transformation is complete. Strangely, if I remove the transition effect (transition duration and transition-timing-function), then this re-positioning doesn't happen.
Can anybody figure out why this is happening and what is the solution?
I am using bootstrap (I know it has a class img-circle which draws circle, but I wish to use my own code).
You can see the code running here: http://jsfiddle.net/dk49/h9KZr/
Observe the clipping of image on left and right sides of the circle and how it gets into correct shape on hovering over it. You can also see the jittering of image on zooming when hovering over it.
<div class="container-fluid page-content-wrapper">
<div class="col-xs-12 col-sm-4">
<div class="circle-container">
<h2 class="img-header">Men</h2>
<div class="inner-circle img-men"></div>
</div>
</div>
</div>
CSS:
.page-content-wrapper {
max-width: 980px;
margin-left: auto;
margin-right: auto;
background-color: #000;
}
.circle-container {
max-width: 325px;
max-height:325px;
border-radius: 50%;
overflow: hidden;
position: relative;
margin: 20px auto 0 auto;
z-index: 5; /* for fixing chrome bug */
}
.inner-circle {
width: 100%;
height: 100%;
padding-bottom: 100%;
border-radius: 50%;
overflow: hidden;
position: relative;
transition: transform 0.15s ease-in-out;
}
.inner-circle:hover, .inner-circle:active {
transform: scale(1.1);
}
.circle-container:hover .img-header, .circle-container:active .img-header{
bottom: 30%;
background-color: rgba(255,255,255,0.9);
}
.img-header {
color: #fff;
bottom: 10%;
position: absolute;
width: 100%;
color: #000;
background-color: rgba(255,255,255,0.7);
font-size: 25px;
font-weight: 500;
padding: 7px;
text-align: center;
height: 43px;
vertical-align: middle;
z-index: 1;
transition: bottom 0.15s ease-in-out, background-color 0.15s ease-in-out;
}
.img-header:hover ~ .inner-circle, .img-header:active ~ .inner-circle {
transform: scale(1.1);
}
.img-men {
background: url(http://s8.postimg.org/qohfig4md/men.png) center center no-repeat;
background-size: contain;
}
When I set .header's opacity to something less than one, it overlays the image in .banner, but when I set .header's opacity to one or don't set it at all, the image in .banner overlays .header. Why?
<div>
<div>
<div class="header">
</div>
<div class="subHeader">
</div>
</div>
<div>
<div>
<img class="banner" src="./images/foo.jpg" />
</div>
<div class="footer">
</div>
</div>
CSS:
.header {
background-color: #cbd8e4;
height: 70px;
}
.subHeader {
background-color: #007934;
height: 35px;
opacity: .4;
}
.banner {
width: 1180px;
margin-top: -105px;
}
.footer {
background-color: #007934;
height: 40px;
}
as opposed to:
.header {
background-color: #cbd8e4;
height: 70px;
opacity: .9; /*this displays over the image in .banner */
}
Changing the opacity to anything other than 1 changes the element's z-index.
MDN explores this a bit.
If it's a problem, you could try using ...
filter: alpha(opacity=x);
or
background-color: rgba(r, g, b, a);
... but the latter only changes the opacity of the background.
I have two elements in a div, an image that fades in and some text that changes color, but I am unable to get them to transition at the same time. In other words, the mouse can only be over one or the other.
I tried to put the properties in the div that contains them, but that did not help.
JSFiddle example
HTML:
<div id="selectors">
<div id="omselector">
<a href="stills.html">
<img class="noglow" src="images/stills/oldcog.png" alt="Old Work!">
<img class="glow" src="images/stills/oldcogglow.png" alt="Old Work">
<p class="button">OLD WORK</p>
</a>
</div>
</div>
CSS:
.button
{
float: bottom;
width: 350px;
font-size: 20pt;
text-align: center;
font-weight: 900;
color: #FFFFFF;
left: 0;
top: 200px;
-webkit-transition: color 1s;
-moz-transition: color 1s;
-o-transition: color 1s;
transition: color 1s;
z-index: 6:
}
.button:hover
{
color: #0df400;
}
#omselector
{
position: absolute;
height: auto;
width: 300px;
top: 40%;
left: 25%;
z-index: 7;
}
.glow, .noglow
{
width: 250px;
height: 250px;
position: absolute;
left: 70px;
}
To simultaneously change the styling of both elements on a mouse event, you can take advantage of the parent element's mouse event and use #omselector and its :hover pseudo class in the selectors.
For example:
#omselector:hover .button {/*...*/}
#omselector:hover .glow, .noglow {/*...*/}
See JSFiddle demo based on your own.
Try this fiddle
One thing to note is that, try to position the images and the text inside the #omselector so they both receive the hover event. (Notice this wouldn't work of you hover over from the left side.