I provide a JSFiddle: https://jsfiddle.net/om83Ljtm/
It contains of a div, img, and span element. The img acts as a background-image to the div. I do not use CSS background-property for the background-image because I want to change the opacity when hovering the div. The span contains text which overlaps the background image. When hovering the div, I want to change the opacity of the image. This works, however, when the mouse hovers the text (span), the opacity of the img changes back to the initial value 0.6. But I want the image to not (!) change back its opacity when I hover over the text. How can this be achieved?
To sum up: In the JSFiddle, if I hover over the div, the opacity changes to 1. This should remain, even if I hover over the text in the span. This does not work, yet.
Use .event:hover img instead of .event img:hover
.event {
width: 200px;
position: relative;
border: 1px solid #dddddd;
height: auto;
}
.event .titel {
float:left;
font-size: 20px;
background-color:white;
padding:3px;
position:absolute;
top:50px;
left:5px;
}
.event img {
opacity: 0.6;
width: 100%;
}
.event img {
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
.event:hover img {
opacity: 1;
}
<div class="event">
<img src="https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI=w300">
<span class="titel">text text text text text text text text text </span>
</div>
you can achieve this by giving hover to div not on img here you go: https://jsfiddle.net/om83Ljtm/2/
.event:hover img {
opacity: 1;
}
Just like this ;)
.event {
width: 200px;
position: relative;
border: 1px solid #dddddd;
height: auto;
}
.event .titel {
float:left;
font-size: 20px;
background-color:white;
padding:3px;
position:absolute;
top:50px;
left:5px;
}
.event img {
opacity: 0.6;
width: 100%;
}
.event img {
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
.event:hover img { /* Just change this */
opacity: 1;
}
<div class="event">
<img src="https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI=w300">
<span class="titel">text text text text text text text text text </span>
</div>
Related
super beginner here. I'm trying to get an image caption to show on hover so I've set the opacity to 0 on the .caption class then 100% on the .caption:hover (not sure if this is best practice but it's the only way i could get it to work...)
Anyway, I'm now trying to get the caption to ease in & out on hover. I've tried adding transition: 0.5s ease-in-out; to both the .caption and the .caption:hover class. Adding it to the .caption:hover class makes it so it only eases in (then jumps straight back to its original state when i move my cursor away). Adding it to the .caption class works, however the caption shows briefly when I reload the page as well as when I hover over the image. I only want it to show on hover.
Any help would be appreciated!
CSS
.caption {
opacity: 0%;
position: absolute;
top: 20px;
left: 20px;
width: 318px;
height: 318px;
background: white;
transition: 0.5s ease-in-out;
}
.caption:hover {
opacity: 100%;
}
HTML
<div class="caption">
<h2 class="artname">Caption 1</h2>
<h3 class="artcategory">Caption2</h3>
</div>
p {
width: 100px;
height: 100px;
background: red;
opacity:0;
transition: opacity 2s;
transition-timing-function: ease-in-out;
visibility:hidden;
}
div:hover > p {
opacity:1;
visibility:visible;
}
div{
height:100px;
}
<div>
<p></p>
</div>
I am currently working on this JSFiddle but I am not sure how I can arrange the text on several lines as a paragraph instead of on Just one line, I find that when I insert more text, as I have overflow hidden, it seems to just carry on in one line out of the div. I would like to be able to have a paragraph in my spinning div.
I have tried < p > tags and < br > tags but neither of these work.
HTML
<div class="hover-img">
Text Goes Here
</div>
CSS
.hover-img {
position: relative;
width: 200px;
height: 200px;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
background:url(http://www.wholesaleforeveryone.com/content/images/blank/600/solid_color.gif);
-webkit-transform:rotateY(180deg);
-webkit-transform-style: preserve-3d;
line-height:200px;
text-align:center;
font-size:0;
}
.hover-img:hover{
-webkit-transform:rotateY(0deg);
font-size:14px;
color:white;
}
Use css property word-wrap: break-word; and reduce the line-height:200px; to value like 15px;
.hover-img {
position: relative;
width: 200px;
height: 200px;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
background:url(http://www.wholesaleforeveryone.com/content/images/blank/600/solid_color.gif);
-webkit-transform:rotateY(180deg);
-webkit-transform-style: preserve-3d;
line-height:15px;
text-align:center;
font-size:0;
word-wrap:break-word;
}
demo http://codepen.io/krish4u/pen/sijrC
Remove the line-height on .hover-img
Add display: table to .hover-img
Wrap the text in another div (.text) and use display: table-cell and vertical-align: middle on that div to align the text vertically in the centre.
Have a fiddle!
HTML
<div class="hover-img">
<div class="text">
Text Goes Here
<br />And Here
<br />And Here
<br />And Here
<br />And Here
</div>
</div>
CSS
.hover-img {
width: 200px;
height: 200px;
text-align:center;
display: table;
background: /* whatever value */
}
.hover-img:hover {
font-size:14px;
color:white;
}
.text {
display: table-cell;
vertical-align: middle;
}
I currently have a rotating image that flips around and has writing on the back using animated css, however what I want is that when the image flips around it changes with another image so it has a solid colour instead of a reversed version of the image.
CSS
.hover-img {
position: relative;
width: 400px;
height: 300px;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
background:url(bbclike/topright.png);
-webkit-transform:rotateY(180deg);
-webkit-transform-style: preserve-3d;
line-height:200px;
text-align:center;
font-size:0;
}
.hover-img:hover{
-webkit-transform:rotateY(0deg);
font-size:14px;
color:white;
background-color:#FF0;
}
HTML
<div class="hover-img">
Text Goes Here
</div>
Just put in hover section whatever you want when user hovers the div... E.g. :
.hover-img:hover{
background:url(---HERE IMAGE 2---);
font-size:14px;
color:white;
background-color:#FF0;
}
Working fiddle demo here
you may want to try this out
http://jsbin.com/tejiduq/1/edit?html,css,output
change the container class, so that you can manipulate DOM class.
//html
<div>
<i class="icon"></i>
</div>
<br>
<input class="button" type="button" value="flip">
//css
div{
}
.icon {
display: inline-block;
width: 30px;
height: 30px;
transition: all 0.5s;
}
div .icon {
background: url("https://www.w3schools.com/images/compatible_chrome.gif") no-repeat;
}
div.ie .icon{
background: url("https://www.w3schools.com/images/compatible_edge.gif") no-repeat;
transform: scaleX(-1)
}
//javascript
$(".button").click(function() {
$("div").toggleClass("ie");
});
Hope this will find you useful.
Probably not the first time you see this question... but I can't solve this problem.
Here is live version
http://jsfiddle.net/LndEh/
If you change height for .projectwrap, you will see what I am trying to achieve. I have tried add clearfix etc.
HTML
<div class="projectwrap">
<img src="http://www.vectortemplates.com/raster/superman-logo-012.png">
<div class="inner"><span>sometext</span></div>
</div>
<div class="projectwrap">
<img src="http://www.vectortemplates.com/raster/superman-logo-012.png">
<div class="inner"><span>some text</span></div>
</div>
<div class="projectwrap">
<img src="http://www.vectortemplates.com/raster/superman-logo-012.png">
<div class="inner"><span>some text</span></div>
</div>
CSS
.projectwrap
{
position: relative;
width: 28%;
height:auto;
float:left;
}
.projectwrap img
{
position: absolute;
width: 100%;
}
.inner
{
width: 100%;
height: 100%;
background-image: url(http://goodlogo.com/images/logos/batman_logo_2574.gif);
background-size: cover;
position:absolute;
z-index: 11;
opacity: 0;
-webkit-transition: opacity 400ms linear;
-o-transition: opacity 400ms linear;
-moz-transition: opacity 400ms linear;
transition: opacity 400ms linear;
}
.inner a
{
float:left;
text-align: center;
display:table;
width: 100%;
height:100%;
}
.inner a span
{
display: table-cell;
vertical-align: middle;
width:100%;
height:100%;
color:#fff;
text-align: center;
text-transform: uppercase;
}
.inner:hover
{
opacity: 1;
-webkit-transition: opacity 400ms linear;
-o-transition: opacity 400ms linear;
-moz-transition: opacity 400ms linear;
transition: opacity 400ms linear;
}
Since the containers are floated and contain absolutely positioned images, they have no height and will float over each other.
If you want all three logos to appear, change the CSS for the images to position:relative
.projectwrap img {
position: relative;
width: 100%;
}
http://jsfiddle.net/LndEh/1/
EDIT:
Another method, if you need to use position:absolute on the images:
Set a minimum height for the .projectwrap divs so that they don't collapse to zero height.Then they will float as expected.
.projectwrap {
position: relative;
width:28%;
float:left;
min-height:5px;height:auto!important;height:5px;
}
http://jsfiddle.net/LndEh/2/
EDIT:
For the additional three (hidden) images, I have changed from using a background image to using the same 100% width method you used for the superman logos. I placed the links over the image by positioning them absolutely.
.inner {
position:relative;
width: 100%;
...
}
.inner a {
position:absolute;
...
}
http://jsfiddle.net/LndEh/3/
EDIT:
I think I see now what you're going for.
I switched from using background-image on .inner to using <img /> and kept your elements positioned absolutely. Does that work better?
http://jsfiddle.net/LndEh/7/
I have applied:
-webkit-transition:background-image 0.4s ease-in-out;
background-image: url('http://www.clementinekeithroach.co.uk/wpcontent/uploads/2013/09/about.jpg');
background-position:initial initial;
background-repeat:initial initial;
border-bottom-left-radius:0px;
border-bottom-right-radius:0px;
border-top-left-radius:0px;
border-top-right-radius:0px;
clear:both;
color:#DDDDDD;
cursor:pointer;
display:block;
font-size:1.8rem;
height:80px;
line-height:80px;
margin:2em auto 0;
text-align:center;
transition:background-image 0.4s ease-in-out;
width:80px;
}
To the "about" image on:
http://www.clementinekeithroach.co.uk/home/
However, unlike all the other images on the site, which fade naturally, and then increase in their darkness when hovered over, this one refused to budge.
Can someone explain where I've gone wrong?
replace your that holds the background for "about" with this code:
remember to remove the background-image attribute from the span's css. Also remove filter and opacity from the span to make this work.
<span class="sidebar-link">
<img src="http://www.clementinekeithroach.co.uk/wp-content/uploads/2013/09/about.jpg" id="myimg">
<style>
#myimg{
height: 100%;
opacity: 0.6;
transition: all 0.3s ease-in-out 0s;
width: 100%;
z-index: 1;
}
#myimg:hover{
height: 100%;
opacity: 1;
transition: all 0.3s ease-in-out 0s;
width: 100%;
z-index: 1;
}
</style>
</span>