how to hide HTML element with CSS - html

I have two images, but I just want to show one of them. if I hover, it will change the image.
.sidenav {
height: 100%;
/* 100% Full-height */
width: 100px;
position: fixed;
/* Stay in place */
z-index: 2;
top: 0;
left: 0;
background-color: #fff;
overflow: hidden;
/* Disable horizontal scroll */
padding-top: 20px;
transition: 0.8s;
opacity: 0.8;
box-shadow: 0px 20px 50px black;
}
.sidenav:hover {
width: 215px;
transition: 0.8s;
overflow: hidden;
}
.sidenav img {
height: 10%;
width: auto;
padding-left: 13px;
transition: 0.8s;
}
.hovered {
visibility: hidden;
opacity: 0;
height: 13% !important;
transition: 0.5s;
}
.sidenav:hover img:first-child {
visibility: hidden;
opacity: 0;
}
.sidenav:hover .hovered {
visibility: visible;
opacity: 1;
}
<div class="sidenav">
<img src="../img/10.png">
<img src="../img/logo1.png" class="hovered">
</div>
My question is, how to hide the second image element? i can hide the image but it create a blank space. I dont used display: none; because I used transition. Any suggestion for me? thanks before

You should go for CSS as long as its possible. And fortunaterly for your requirement the use of CSS is totally possible.
I did that earlier for one of my similar requirement.
HTML :
<a class="foo" href="#">
<img src="http://lorempixel.com/400/200/food/1/" />
<img src="http://lorempixel.com/400/200/food/2/" />
</a>
CSS :
.foo img:last-child {
display: none
}
.foo:hover img:first-child {
display: none
}
.foo:hover img:last-child {
display: inline-block
}
JSFiddle : http://jsfiddle.net/nikdtu/9zcvsewr/

hovered image add position: absolute; with top: ...; left: ...
And second image will be above first image. You can manipulate positioning with top, left parameters.

you can use position:absolute for second image.
below is an example, I have used dummy images in this snippet
.sidenav {
height: 100%; /* 100% Full-height */
width: 100px;
position: fixed; /* Stay in place */
z-index: 2;
top: 0;
left: 0;
background-color: #fff;
overflow: hidden; /* Disable horizontal scroll */
padding-top: 20px;
transition: 0.8s;
opacity: 0.8;
box-shadow: 0px 20px 50px black;
}
.sidenav:hover{
width: 215px;
transition: 0.8s;
overflow: hidden;
}
.sidenav img{
height: 10%;
width: auto;
padding-left: 13px;
transition: 0.8s;
}
.hovered {
visibility: hidden;
opacity: 0;
height: 13% !important;
transition: 0.5s;
position:absolute;
top:20px;
left: 0;
}
.sidenav:hover img:first-child{visibility: hidden; opacity: 0;}
.sidenav:hover .hovered{visibility: visible; opacity: 1;}
<div class="sidenav">
<img src="https://dummyimage.com/qvga">
<img src="https://dummyimage.com/skyscraper/f0f/f" class="hovered">
</div>

Avoid the overhead of jquery if all you need is this small change.
Modify the given CSS definitions to these definitions. Then modify the HTML as show.
.sidenav {
height: 100%;
/* 100% Full-height */
width: 100px;
position: fixed;
/* Stay in place */
z-index: 2;
top: 0;
left: 0;
background-color: #fff;
overflow: hidden;
/* Disable horizontal scroll */
padding-top: 20px;
transition: 0.8s;
opacity: 0.8;
box-shadow: 0px 20px 50px black;
}
.sidenav:hover {
width: 215px;
transition: 0.8s;
overflow: hidden;
}
.sidenav .hover_image {
height: 10%;
width: 90px;
padding-left: 13px;
background-image: url('https://dummyimage.com/90x20/1b0/242499.png&text=Regular');
background-position: left top;
background-repeat: no-repeat;
}
.sidenav:hover .hover_image {
height: 13% !important;
width: 205px;
background-image: url('https://dummyimage.com/205x28/cb0/242499.png&text=Hovered');
}
<div class="sidenav">
<div class="hover_image"> </div>
</div>
Adjusting the height and width for the proper image size and checking the proper path is something you'll need to do. This must be the 'real' image size since it will not be scaled by the browser. (You are using pre-scaled, compressed images already, right?)

Related

Why is overflow in css working with a delay?

I'm trying to achieve a drop down cover effect (Not sure how it's really called) with the following code:
.new_events_list {
position: absolute;
width: 26%;
height: 28vh;
background-color: #323642;
cursor: pointer;
}
#new_events_list_effect {
background-color: #ee5f95;
width: 100%;
opacity: 0.5;
top: -100%;
transition: 0.5s;
}
div.new_events_list:hover #new_events_list_effect {
top: 0%;
transition: 0.5s;
}
div.new_events_list:hover img {
filter: grayscale(0.5);
transition: 1s;
}
<div class="new_events_list" style="overflow: hidden;border-radius: 10px;">
<img class="new_events_list" id="photo1" src="https://www.dpreview.com/files/p/articles/7395606096/Google-Photos.jpeg" alt="event_list_1" style=" object-fit: cover; width: 100%;border-radius: 10px;">
<div class="new_events_list" id="new_events_list_effect">
</div>
</div>
The problem that I'm facing is that once you hover over the photo the pink block drops down with the corners visible which only disappear after a second or so. Could anyone explain to me how I could possibly drop down the pink coloured div without the corners being visible?
Thank you very much for your help in advance.
The following code should work:
.new_events_list {
position: relative;
width: 26%;
backgorund-color: black;
border-radius: 10px;
overflow: hidden;
}
.image {
width: 100%;
}
.new_events_list_effect {
position: absolute;
height: 100%;
width: 100%;
background-color: #ee5f95;
opacity: 0.5;
top: -100%;
transition: 0.5s;
border-radius: 10px;
}
.new_events_list:hover .new_events_list_effect {
top: 0%;
transition: 0.5s;
}
<div class="new_events_list">
<img src="https://www.dpreview.com/files/p/articles/7395606096/Google-Photos.jpeg" class="image">
<div class="new_events_list_effect"></div>
</div>

How can I make a div cover the entirety of a div behind it?

I am trying to have a square-shaped div (the red box) on the page by default. When the user hover the mouse over it, a second div should display with a semi-transparent black background and some text/content. I'm trying to imitate Devon Stank's project section on his website.
The code I have right now increases the height of the default square red box and the second div doesn't cover the whole of the red box. What's wrong with the code?
Fiddle
.project-box {
position: relative;
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
-webkit-transition: 0.5s;
-moz-transition: 0.5s;
-o-transition: 0.5s;
-ms-transition: 0.5s;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
<div class="default-box project-box">
<div class="default-hover hover-content">hello</div>
</div>
height: 100%; won't work on the element if the parent's height isn't defined.
Also, if you stick with position: relative with a padding on the parent, you won't be able to cover it all.
If you want to cover all the .project-box (parent) no matter its padding values,
I suggest you to use an absolute positioning on its child:
(I've done it by adding the new class .veil, but it could be done within your existing class)
.project-box {
position: relative; /* ADDED so that the absolute positioning refers to this parent */
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
/* REMOVED position and sizes */
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
/* ADDED this class */
.veil {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<div class="default-box project-box">
<!-- Added a class for the child here -->
<div class="default-hover hover-content veil">hello</div>
</div>
Hope it helps.
Here, it may help you, try it.
.project-box {
position: relative;
width: 30%;
height:100%
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
text-align:center;
padding-top: 30%;
}

Link after visiting not clickable

I have added an overlay dialog box to my homepage.
When I click on the tag the dialog box becomes visible.
The problem now is that when I close the dialog box
the link is disabled for clicking for about 7 seconds.
After doing nothing or clicking around it becomes enabled again.
I have created that fiddle of my source code.
The Css of the overlay dialog looks like that:
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
z-index: 20;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
color: #000;
text-align:left;
border-radius: 5px;
width: 80%;
height: 80%;
position: relative;
transition: all 5s ease-in-out;
}
.popup h2 {
margin-top: 0;
color: #333;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .content {
height:95%;
overflow: scroll;
overflow-x: hidden;
}
#media screen and (max-width: 700px){
.box{
width: 70%;
}
.popup{
width: 70%;
}
}
In the fiddle my problem is not reconstructed.
Even with all the other stuff the fiddle works correct
but the problem still appears at my page though the code is the same in the fiddle and on my page.
I am using a fullPageSlider of Alvarotrigo.
Perhaps the issue has something to deal with it?

Hover on div(1) to show div(2), if mouseout continue to show div(2) for x seconds

When I hover on the image, div(2) appears.
But I want div(2) to remain about x seconds even on mouse out.
I only want to use PURE CSS.
How can I do it?
jsFiddle
#basarilar {
float: right;
margin: 7px 357px;
width: 140px;
height: 24px;
position: relative;
z-index: 9999;
}
.yildiz {
height: 24px;
width: 24px;
background: url("http://www.kelimelerbenim.com/wp-content/themes/kelimelerbenim/images/yildiz.png") 0 0 no-repeat;
margin-left: 10px;
float: right;
transition: .50s all;
transition-delay: 5s;
}
.yildiz:hover {
background: url("http://www.kelimelerbenim.com/wp-content/themes/kelimelerbenim/images/yildiz-2.png") 0 0 no-repeat;
}
.aciklama {
display: none;
position: absolute;
width: 200px;
height: 70px;
z-index: 9999;
top: 48px;
right: 0px;
padding: 15px 15px;
font-weight: bold;
text-align: center;
}
#bumerang1 {
color: #ffffff;
background: #76ab01;
}
#bumerang:hover + #bumerang1 {
display: block;
}
#bumerang1:hover {
display: block;
}
<div id="basarilar">
<div id="bumerang" class="yildiz"></div>
<div id="bumerang1" class="aciklama">This is my DIV</div>
</div>
Christopher Pearson was right about using transition-delays, but you'll need to change a couple of other things as well.
#basarilar {
float:right;
margin:7px 357px;
width: 140px;
height: 24px;
position: relative;
z-index: 9999;
}
.yildiz {
height:64px;
width:64px;
background:url("http://i.stack.imgur.com/vNQ2g.png?s=64&g=1") no-repeat;
margin-left:10px;
float:right;
transition: .50s all;
transition-delay: 5s;
}
.yildiz:hover {
background:url("http://i.stack.imgur.com/vNQ2g.png?s=64&g=1") 0 0 no-repeat;
}
.aciklama {
visibility: hidden; /* use visibility rather than display */
position:absolute;
width: 200px;
height: 70px;
z-index: 9999;
top:48px;
right:0px;
padding: 15px 15px;
font-weight: bold;
text-align: center;
transition-delay: 3s; /* Set transition-delay to 3s, so the mouse out is delayed */
}
#bumerang1 {
color:#ffffff;
background: #76ab01;
}
#bumerang:hover + #bumerang1 {
visibility: visible; /* use visibility rather than display */
transition-delay: 0s; /* Set transition-delay to 0s, so the mouse over is still immediate */
}
#bumerang1:hover {
display:block;
}
<div id="basarilar">
<div id="bumerang" class="yildiz"></div>
<div id="bumerang1" class="aciklama">This is my DIV</div>
</div>
You will have to use transitions with the .transition-duration. See this thread for a similar application. You can also see the W3 schools transitions pages here.

How to slide a div over an image with CSS?

On a webpage I am working on, I have a div which contains an image and another div. The inner div is initially set to
opacity: 0;
so that it's not visible. The inner div should appear over my image when hovered. I have achieved this, but now I want to improve upon it further by having the 'overlay' div (which appears with an opacity of 0.5) slide down gradually over the image. I could do it theoretically with JavaScript but on this occasion it must be a pure CSS solution. So far my solution just makes the overlay div appear gradually (it fades in) but does not slide down as I have never done this in CSS alone.
See the image below to understand further:
The HTML:
<div class="img"> <img class="squareImg" src="img1.jpg"/><div class="overlay"> tweet This <br> Buy This</div></div>
<div class="img"> <img class="squareImg" src="img3.jpg"/></div>
<div class="img"> </img></div>
CSS
.overlay{
position: absolute;
width: 200px;
overflow-y: hidden;
transition-property: all;
transition-duration: .5s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
height: 200px;
background-color: red;
border: 1px solid white;
top: 10px;
left: 10px;
opacity: 0;
} .overlay:hover{
cursor:pointer;
opacity: 0.5;
z-index: 1;
}
.img{
position: relative;
margin-bottom: 10px;
border: 2px solid yellow;
background-color: black;
width: 200px;
height: 200px;
left: 50%;
margin-left: -110px;
padding: 10px;
}
Here it is with a slide down thanks to a height transition.
Improvements:
Instead of opacity, use background: rgba(255,0,0,0.5) so that the contents of the overlay remain fully opaque.
The transition property has been simplified to transition: all .5s
The outside border is created with box-shadow and the black border is now created with the border property instead of padding.
.overlay has a height of 0 and on hover it is given a height of 100%. It is stretched accross the image with the combination of left: 0 and right: 0
There is no set image size, the size of the <img> now controls the size of the border and overlay, allowing different image sizes.
Complete Example
.img {
position: relative;
border: 10px solid black;
box-shadow: 0 0 0 2px yellow;
display: inline-block;
vertical-align: top;
cursor: pointer;
margin: 10px;
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
transition: all .5s;
overflow: hidden;
height: 0;
background: rgba(255, 0, 0, 0);
}
.img:hover .overlay,
.overlay:hover {
height: 100%;
background: rgba(255, 0, 0, 0.5);
}
.img > img {
display: block;/* Prevent inline gap under image*/
}
<div class="img">
<img src="http://www.placehold.it/200" />
<div class="overlay">tweet This <br>Buy This</div>
</div>
<div class="img">
<img src="http://www.placehold.it/300" />
<div class="overlay">tweet This <br>Buy This</div>
</div>
You can just use simple transitions for this, rather than a keyframe animation
Example:
http://jsfiddle.net/realseanp/c4e08hy7/9/
HTML:
<div class="holder">
<div class="info">
<span>All your info</span>
<div class="overlay"></div>
</div>
</div>
CSS:
.holder{
position:relative;
height:200px;
width: 200px;
overflow: hidden;
border:1px solid #000;
z-index:3;
}
.info {
box-sizing: border-box;
height: 100%;
padding: 20px;
position: absolute;
top: -100%;
transition: top 0.5s ease 0s;
width: 100%;
z-index: 4;
}
.overlay {
background: none repeat scroll 0 0 #000;
height: 100%;
left: 0;
opacity: 0;
position: absolute;
top: 0;
width: 100%;
z-index: -1;
transition: 1s all;
}
.holder:hover .info{
top:0;
}
.holder:hover .overlay{
opacity: .85
}
Just a simple approach using the image as background:
.img{
position: relative;
background: none 50% / cover;
width: 200px;
height: 200px;
margin: 0 auto;
border: 10px solid #000;
box-shadow: 0 0 0 2px yellow;
}
.overlay{
position: absolute;
width: 100%;
height: 0%;
overflow: hidden;
transition: all .5s cubic-bezier(0, 1, 0.5, 1);
box-shadow: inset 0 0 0 1px white;
background: rgba(255,0,0,0.4); /* Don't use opacity but rgba on bg */
}
.img:hover .overlay{
height: 100%;
}
<div class="img" style="background-image:url(//placehold.it/300x300/aba)">
<div class="overlay">Tweet This <br> Buy This</div>
</div>
If you need to slide it down, you should use #keyframes:
.overlay:hover{
-webkit-animation: slide 5s; /* Chrome, Safari, Opera */
animation: slide 5s;
}
#keyframes slide {
from {height: 0px;}
to {height: 200px;}
}
/* Chrome, Safari, Opera */
#-webkit-keyframes slide {
from {height: 0px;}
to {height: 200px;}
}
You can achieve this by setting the .overlay with a negative top position and then you can target the sibling element with the + selector and change the top position to positive.
Also you can change the transition timing by setting the transition-duration: 2s; to 2 sec.
.overlay{
position: absolute;
width: 200px;
overflow-y: hidden;
transition-property: all;
transition-duration: 2s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
height: 200px;
background-color: red;
border: 1px solid white;
top: -200px;
left: 10px;
opacity: 0;
z-index:-1;
}
.squareImg:hover + .overlay, .overlay:hover {
cursor:pointer;
top:10px;
opacity: 0.5;
z-index: 1;
}
.img{
position:relative;
height:200px;
width: 200px;
overflow: hidden;
border:1px solid #000;
z-index:3;
margin-bottom: 10px;
border: 2px solid yellow;
background-color: black;
left: 50%;
margin-left: -110px;
padding: 10px;
}
DEMO http://jsfiddle.net/a_incarnati/c4e08hy7/8/