Change div image with transition when hovering an other div (ONLY CSS) - html

I have a little problem that i can't resolve, cause i want use solo CSS. I just want to do the opposite of what my code does, but i couldn't found the way to do it. That's my code:
HTML:
<div class="central1">
<div id="central_imgl">
<img class="bottom" src="images/kostnic_central1.jpg" width="370px" height="400px"/>
<img class="top1 hover" src="images/kostnic.jpg" width="370px" height="400px"/>
</div>
<div id="central_imgr">
<img class="bottom" src="images/kostnic_central2.jpg" width="370px" height="400px"/>
<img class="top1 hover" src="images/kdata2.jpg"/>
</div>
</div>
CSS:
div.central1{
background: black;
display: block;
position: absolute;
width: 740px;
height: 400px;
top:190px;
left:350px;
color: white;
}
#central_imgl {
position:relative;
float: left;
width: 50%;
height: 100%;
margin:0 auto;
}
#central_imgl img {
position:absolute;
left:0;
width: 368px;
height: 400px;
-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;
}
#central_imgl img.top1:hover {
opacity:0;
}
(And the same for central_imgr with float:right)
Now I want to change the displayed img on 'central_imgr' when i hover central_imgl, keeping the frontal img of central_imgl, and vice versa.
Thanks all!

DEMO
css code:
*{
box-sizing:border-box;
}
div.central1{
background: black;
display: block;
position: absolute;
width: 740px;
height: 400px;
top:190px;
left:350px;
color: white;
border:4px solid black;
overflow:hidden;
}
[id^=central] {
position:relative;
float: left;
width: 50%;
height: 100%;
}
[id=hiddenDiv]{
position:absolute;
right: 0;
width: 50%;
height: 100%;
z-index:1;
}
img {
position:absolute;
left:0;
top:0;
width: 100%;
height: 400px;
transition: opacity 1s ease-in-out;
}
#central_imgl .top1:hover {
opacity:0;
}
#central_imgl:hover + [id=central_imgr] .hover{
opacity:0;
}
[id=hiddenDiv]:hover + #central_imgl .top1{
opacity:0;
}
html code:
<div class=central1>
<div id=hiddenDiv></div>
<div id="central_imgl">
<img class=bottom src="https://scontent-b-fra.xx.fbcdn.net/hphotos-frc3/l/t1.0-9/1604926_659171170797962_1284145215_n.jpg" width="370px" height="400px"/>
<img class="top1 hover" src="https://scontent-a-fra.xx.fbcdn.net/hphotos-frc1/t1.0-9/10154320_659171017464644_1223781208_n.jpg" width="370px" height="400px"/>
</div>
<div id=central_imgr>
<img class=bottom src="https://scontent-b-fra.xx.fbcdn.net/hphotos-prn2/t1.0-9/1234076_659170960797983_1698005470_n.jpg" width="370px" height="400px"/>
<img class="top1 hover" src="https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-ash3/t1.0-9/10156133_658968587484887_710971290_n.jpg"/>
</div>
</div>

Related

Changing 1 image to slide into many images when hovering

<div class ="tc-container">
<img src ="2.jpg" alt=""/>
<img style ="margin-top:342px;margin-left: 52px;"class ="top-img" src="3.jpg" alt=""/>
</div>
**CSS:**
/*image hover*/
.tc-container{
width:500px;
height:800px;
padding-right: 1800px;
}
.tc-container img{
width: 700px;
height: 500px;
}
.top-img{
position:absolute;
left:0;
top:0;
opacity: 0;
transition:all 0.7s ease;
}
.top-img:hover{
opacity:1;
}
I want to hover 1 image and can slide it into 4-5 images. That's what I am trying to do thank you for answering my question
Something like this you mean?
.tc-container {
position: relative;
height: 100px;
width: 100px;
--horizontal-spacing: 105px;
}
.tc-container img {
position: absolute;
left: 0;
top: 0;
z-index: -1;
transition: left 0.2s ease-in;
}
.tc-container:hover #img1 {
left: calc(3 * var(--horizontal-spacing));
}
.tc-container:hover #img2 {
left: calc(2 * var(--horizontal-spacing));
}
.tc-container:hover #img3 {
left: calc(1 * var(--horizontal-spacing));
}
<div class="tc-container">
<img id="img1" class="img" src="https://picsum.photos/id/1022/100">
<img id="img2" class="img" src="https://picsum.photos/id/1012/100">
<img id="img3" class="img" src="https://picsum.photos/id/1015/100">
<img id="img4" class="img" src="https://picsum.photos/id/102/100">
</div>

Incompatible css changes on children on parent hover

I have the following html code :
.logo {
display: inline-block;
width: 30px;
position: absolute;
top: 50%;
opacity: 0;
transition: 0.6s;
}
.container:hover .logo {
opacity: 1;
transition: 0.6s;
}
.container:hover .picture {
filter: brightness(0.7);
transition: 0.6s;
}
<div class="container">
<div class="element-header">
<div class="element">Foo</div>
<div class="element">Bar</div>
</div>
<div class="loader"> </div>
<img src="logo.png" alt="" class="logo">
<img src="picture.jpg" alt="" class="picture">
</div>
When .container is hovered, I want .logo to be at opacity:1 and .picture to be at filter: brightness(0.7).
When a try to apply those properties one-by-one at .container hover, each is working. But when both are set-up, only the filter one is working.
If you set the position to relative instead of absolute, both images will display. As the code stood, one image was getting lost. (I substituted my own images in and added a picture class to size the image)
The transition works fine though!
Try below:
.logo {
display: inline-block;
width: 100px;
//height:auto;
position: relative;
top: 50%;
opacity: 0;
transition: 0.6s;
}
.picture {
width: 500px;
height: auto;
float: left;
}
.container:hover .logo {
opacity: 1;
transition: 0.6s;
}
.container:hover .picture {
filter: brightness(0.7);
transition: 0.6s;
}
<div class="container">
<div class="element-header">
<div class="element">Foo</div>
<div class="element">Bar</div>
</div>
<div class="loader"> </div>
<img src="https://www.dcu.ie/sites/default/files/afu_logo2_1.jpg" alt="agefriendly" class="logo">
<img src="http://www.rachelgallen.com/images/mountains.jpg" alt="Mountains" class="picture">
</div>
Fiddle here

Image hover caption with zoom effect in bootstrap

I am unable to align image to the width of caption with maintaining the gutter width. I am using bootstrap and also the image is flowing outside the div on hover. Can anybody help me out ?
This is what i am trying to achive : https://awwapp.com/s/43b68655-83a6-4133-ab28-0ec9a4152316/
Pen : http://codepen.io/anon/pen/XbxOMq
HTML :
HOTSPOT TEXTf
<div class="col-md-4 hotspot-wrapper">
<img src="https://newevolutiondesigns.com/images/freebies/hd-widescreen-wallpaper-3.jpg" alt="..." class="img-responsive">
<div class="hotspot-text">
HOTSPOT TEXTf
</div>
</div>
</div>
<div class="col-md-4 hotspot-wrapper">
<img src="https://newevolutiondesigns.com/images/freebies/hd-widescreen-wallpaper-3.jpg" alt="..." class="img-responsive">
<div class="hotspot-text">
HOTSPOT TEXTf
</div>
</div>
</div>
CSS:
.hotspot-wrapper {
position: relative;
overflow: hidden;
margin-bottom:20px;
}
.hotspot-text {
width:100%;
height: 102px;
position: absolute;
bottom: -50px;
transition: all .2s linear;
background: rgba(0,0,0,.7);
color:#fff;
}
.hotspot-wrapper:hover .hotspot-text {
bottom: 0;
}
.hotspot-wrapper img {
-webkit-transition: all 0.7s ease;
transition: all 0.7s ease;
}
.hotspot-wrapper:hover img {
-webkit-transform:scale(1.3);
transform:scale(1.3);
}
You should make your CSS for these two classes like this, so the hotspot for the text will be aligned with the image :
.hotspot-text {
height: 102px;
position: absolute;
bottom: -50px;
right:0px;
left:0px;
transition: all .2s linear;
background: rgba(0,0,0,.7);
color:#fff;
}
.hotspot-wrapper:hover .hotspot-text {
bottom: 0;
left:0;
right:0;
}
And you should overwrite the padding on the left and on the right set there by default with bootstrap. Like that, the image will have the full width of the div.
.col-lg-4 ,.col-md-4,col-sm-4,col-xs-4{
padding-left:0px;
padding-right:0px;
}
Here's a Fiddle

CSS caption over hover?

I have a few div boxes on my page, and I'd like to make them display text when you hover over them. I was looking at a few tutorials but I can't seem to get it to work with mine, here is an example of one of my boxes.
html:
<div class="squar-1">
<div class="text-1">
<p>Hello</p>
</div>
</div>
CSS:
.squar-1 {
width: 50%;
height: 350px;
background-color: #e57373;
float: left;
}
.squar-1 .text-1 {
position:relative;
bottom:30px;
left:0px;
visibility:hidden;
}
.squar-1:hover .text {
visibility:visible;
}
That's working, you wrote .text instead of .text-1
.squar-1 {
width: 50%;
height: 350px;
background-color: #e57373;
float: left;
}
.squar-1 .text-1 {
position:relative;
left:0px;
visibility:hidden;
}
.squar-1:hover .text-1 {
visibility:visible;
}
<div class="squar-1">
<div class="text-1">
<p>Hello</p>
</div>
</div>
Edit: to transition text, you should used opacity instead of visibility like:
.squar-1 {
width: 50%;
height: 350px;
background-color: #e57373;
float: left;
}
.squar-1 .text-1 {
position:relative;
left:0px;
opacity: 0;
-webkit-transition: opacity 2s; /* For Safari 3.1 to 6.0 */
transition: opacity 2s;
}
.squar-1:hover .text-1 {
opacity: 1;
}
<div class="squar-1">
<div class="text-1">
<p>Hello</p>
</div>
</div>

Easy z-index challenge: making a sibling disappear behind another sibling?

This is what I want it to look like:
everything that is inside the red div, must go behind the green div.
The html:
<div style="height: 100px">some text blablablablablablabla
<br/>some text blablablablablablabla
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>
</div>
<nav class="navigation">
<div class="navfake"></div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title1</div>
<div class="titlepicture">some picture</div>
</div>
</div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title2</div>
<div class="titlepicture">some picture</div>
</div>
</div>
</nav>
The CSS so far and sadly not working:
nav {
width: 100%;
height: 60px;
position: relative;
}
.navfake {
width: 100%;
height: 100%;
background: green;
z-index: 10;
}
.singleelement {
display: inline-block;
width: 100px;
height: 60px;
text-align: center;
z-index: 0;
}
.container {
position: absolute;
top: 0px;
-webkit-transition: all .8s ease;
-moz-transition: all .8s ease;
-ms-transition: all .8s ease;
-o-transition: all .8s ease;
transition: all .8s ease;
height: 200px;
}
.titlepicture {
width: 100%;
height: 200px;
background-color: red;
}
.singleelement:hover .container {
top: -80px;
}
enter link description here
Credits also for: #Toskan, thank you
DEMO WORKING
Here's the new css
nav {
width: 100%;
height: 60px;
position: relative;
}
.navfake {
width: 100%;
height: 100%;
background: green;
z-index: 10;
position:relative;
}
.singleelement {
display: inline-block;
width: 100px;
height: 60px;
text-align: center;
}
.container {
position: absolute;
top: 0px;
-webkit-transition: all .8s ease;
-moz-transition: all .8s ease;
-ms-transition: all .8s ease;
-o-transition: all .8s ease;
transition: all .8s ease;
height: 200px;
}
.titlepicture {
position:absolute; /*THIS ADDED*/
width: 100%;
height: 200px;
background-color: red;
z-index:1; /*THIS ADDED*/
}
.singleelement:hover .container {
top: -80px;
}
.title{ /*THIS ADDED*/
z-index:555;
position:relative;
}
HTML:
<br><br>
<div style="height: 100px">some text blablablablablablabla
<br/>some text blablablablablablabla
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>some text
<br/>
</div>
<nav class="navigation">
<div class="navfake"></div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title1</div>
<div class="titlepicture">some picture</div>
</div>
</div>
<div class="singleelement">
<div class="container">
<div class="title">Some Title2</div>
<div class="titlepicture">some picture</div>
</div>
</div>
</nav>
http://jsfiddle.net/hL5gW/4/
Adding position absolute and doing some positioning this is incredibly simple.
I added these styles to the second element. You'll just have to add it to a seperate class for the second element, or just add it to singleelement if you want this to apply to both.
<div class="singleelement" style="z-index:-100;position:absolute;margin-top:-60px;">