I have a div and I want that on click an other div slides in. I want to achieve this with css3 :target.
Like you can see in the code snippet the :hover works. When hovered an animation start to fade some info in. When you click on the image I want that an other div fades in on the top by calling the same animations as used on hover.
Can somebody help with getting the :target working?
body{
margin: 0px;
}
.image{
position: relative;
width:300px;
height:auto;
}
.image img{
width:100%;
}
.download{
position: absolute;
top:0px;
left:0px;
height:80%;
width:100%;
background-color: gray;
display:none;
}
.info{
position: absolute;
bottom:0px;
left:0px;
height:20%;
width:100%;
background-color: green;
opacity: 0;
}
.info p{
padding: 5px;
margin: 0px;
}
.image:hover .info{
-webkit-animation: show 0.5s; /* Chrome, Safari, Opera */
animation: show 0.5s;
opacity: 1;
}
.image:target .download{
-webkit-animation: show 0.5s; /* Chrome, Safari, Opera */
animation: show 0.5s;
opacity: 1;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes show {
from {opacity: 0;}
to {opacity: 1;}
}
/* Standard syntax */
#keyframes show {
from {opacity: 0;}
to {opacity: 1;}
}
<div class="image"><!-- I detect everything on this div-->
<img src="http://3.bp.blogspot.com/-gaBTIWFTWOo/UTeneLuwWyI/AAAAAAAABJE/E1GQBY4TJ8k/s1600/post-apocalypse-new-york.jpg">
<div class="download"><!-- this div should fade in on click (:target)-->
download
</div>
<div class="info"> <!-- this div should fade in on hover-->
<p>Image 1</p>
</div>
</div>
This can be achieved via jquery: http://jsfiddle.net/swm53ran/13/
$('.image').on('click', function(){
$(this).find('.download').fadeIn(500);
});
i know you want to achieve this with :target, but you can do both animations through jquery to keep consistent if you would like. just another option...
i think i got it the way you wanted with css:
added anchor tag surrounding image, added id #dl to download div...heres the fiddle http://jsfiddle.net/swm53ran/14/
:target {
display:block;
-webkit-animation: show 0.5s; /* Chrome, Safari, Opera*/
animation: show 0.5s;
opacity: 1;
}
<div class="image"><!-- I detect everything on this div-->
<a href="#dl">
<img src="http://3.bp.blogspot.com/-gaBTIWFTWOo/UTeneLuwWyI/AAAAAAAABJE/E1GQBY4TJ8k/s1600/post-apocalypse-new-york.jpg"/>
<div class="download" id="dl"><!-- this div should fade in on click (:target)-->
download
</div>
<div class="info"> <!-- this div should fade in on hover-->
<p>Image 1</p>
</div>
</a>
</div>
Related
I'm working on an overlay on top of a full-frame google docs iframe. I want the top section of the docs to be covered by an 100% width div which fades on hover, revealing the docs options which become clickable.
I've got the fade transition working but the invisible div blocks the iframe from been clicked. If I use pointer-events:none, change the z-index or display:none I get a nasty flickering effect when the cursor is moved.
Is there a work around?
https://github.com/plasticplant/miscresearch/tree/master/miscresearch
#background-site {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
}
#background-site iframe {
width: 100%;
height: 100%;
border: none;
overflow: scroll;
}
#header {
position: absolute;
width: 100%;
z-index: 30;
font-size: 55px;
font-family: 'Sporting_Grotesque-Bold';
padding: 5px;
text-align: center;
transition: 0.3s;
background: white;
}
#header:hover {
opacity: 0;
}
<div id="header">
miscresearch
</div>
<div id="background-site"><iframe name="backgrnd" id="backgrnd" scrolling="yes" src="https://docs.google.com/document/d/16_jikyP9LfNibSOvM4XPeuB2jhf8YEYES1p8xhTBBDM/edit?usp=sharing"></iframe></div>
Try this, should work -- i replicated your problem using some divs, but it gets the point across.
First, use the style "pointer-event:none;" to make the upper level div able to be selected through. The lower div has mouseover and mouseout events that call javascript to change the opacity of the overlay.
You can try applying the mouseover and mouseout functions to the div containing the iframe
function hidefunc(){
document.getElementById("test").style.opacity = '0';
}
function showfunc(){
document.getElementById("test").style.opacity ="1"
}
#test{
position:absolute;
top:0px;
width:300px;
height:300px;
background-color:#000000;
transition: opacity .5s;
pointer-events:none;
z-index:2;
}
#base{
position:absolute;
top:0;
z-index:0;
height:50px;
width:600px;
background-color:red;
}
<div id="test">
</div>
<div onmouseover="hidefunc()" onmouseout="showfunc()" id="base">
Link
</div>
Maybe using z-index is a better approach because when you do display:none; on :hover you are not hovering any element so the nasty effect happens.
#header:hover {
opacity: 0;
z-index: -1;
}
Iframes have a load event, which fire once they have loaded.
Simply create your overlay, and remove it once the iframe's onload event fires.
HTML:
<div id="background-site" class="showOverlay">
<iframe name="backgrnd" id="backgrnd" scrolling="yes" src="https://docs.google.com/document/d/16_jikyP9LfNibSOvM4XPeuB2jhf8YEYES1p8xhTBBDM/edit?usp=sharing"></iframe>
</div>
CSS:
#background-site {
position: relative;
}
#background-site.showOverlay:before {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background-color: red;
z-index: 2;
}
JS :
document.getElementById("backgrnd").addEventListener("load", function() {
document.getElementById("background-site").classList.remove('showOverlay')
});
Fr the current code you could also use the parentElement, to achieve the same result, as the event fires on the iframe:
document.getElementById("backgrnd").addEventListener("load", function(e) {
e.target.parentElement.classList.remove('showOverlay')
});
Hi I've a working solution (see below).
Unfortunately it requires (vanilla) JavaScript; I hope you don't mind. I tried several CSS solutions like animations and all but to no avail.
Anyways, the trick is to use separate mouse in and mouse out event listeners on the iframe and overlays respectively.
document.getElementById("overlay").addEventListener("mouseover", overlayDisappear);
document.getElementById("theiframe").addEventListener("mouseout", overlayAppear);
function replaceAll(str, toFind, toReplace){
return str.replace(new RegExp(toFind.toString(),"g"), toReplace.toString());
}
function overlayAppear(){
//console.log("Appear", document.getElementById("overlay").className);
document.getElementById("overlay").className = replaceAll( document.getElementById("overlay").className, "_disappear","_appear");
}
function overlayDisappear(){
//console.log("Disappear", document.getElementById("overlay").className);
document.getElementById("overlay").className = replaceAll( document.getElementById("overlay").className, "_appear","_disappear");
}
#theiframe, #overlay{
width:200px;
height:200px;
position:fixed;
top:0;
left:0;
}
#theiframe{
border: 2px solid black;
}
#overlay{
background:red;
transition:all 0.3s ease;
}
#overlay._appear{
opacity:1;
z-index:1;
}
#overlay._disappear{
opacity:0;
z-index:-1;
}
/*
#overlay:hover{
animation-name: disappear;
animation-duration: 0.3s;
animation-fill-mode: forwards;
}
#keyframes disappear{
0% { opacity:1; }
50% { opacity:0.5; }
99% { opacity:0; z-index:1; }
100% { opacity:0; z-index:-1; }
}*/
<iframe id="theiframe" src="https://samleo8.github.io/web"></iframe>
<div id="overlay" class="_appear"></div>
hi i want to make a effect like this to my div on a hover:
website with the effect, hover over the people div's to see
I have tried to make a grid but I am strugling to get the hover effect on top of the div.
my codepen link, need the hover on the blocks
You'll need a container div and at least one foreground div to cover the background (could be just an image). Then you'll want to target the parent on hover and change the foreground child. I used transform instead of animating a position property because it's more performant.
.card{
position:relative;
width:200px;
height:200px;
border:1px solid blue;
overflow:hidden;
}
.card > div{
height:100%;
width:100%;
}
.card .foreground{
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
transform:translateX(100%);
background-color:blue;
transition:.5s ease;
}
.card:hover .foreground{
transform:translateX(0);
}
<div class="card">
<div class="foreground"></div>
<div class="background"></div>
</div>
You can attach styles to a div by using the :hover keyword.
Example, you want to change some effect on the div on hover:
div:hover {
background-color: black;
}
You want to change some effect on a child, on parent hover
div:hover .child {
background-color: black;
}
EDIT
Ok, check the class changes when you force hover on their page, their original element has these styles:
z-index: 200;
content: "";
height: 263px;
width: 102px;
background-color: #91c6c2;
display: inline-block;
position: absolute;
top: 0px;
right: -50px;
-webkit-transform: skew(21deg);
transform: skew(21deg);
-webkit-backface-visibility: hidden;
-webkit-transition: right 0.5s;
transition: right 0.5s;
On hover, they just change the elements "right", to 80px, which makes it float in via the mentioned transition, "transition: right 0.5s".
you require a overlay effect on hover of a div.
Please refer this link
<div id="overlay">
<span id="plus">+</span>
</div>
CSS
#overlay { background:rgba(0,0,0,.75);
text-align:center;
padding:45px 0 66px 0;
opacity:0;
-webkit-transition: opacity .25s ease;
-moz-transition: opacity .25s ease;}
#box:hover #overlay {
opacity:1;}
#plus { font-family:Helvetica;
font-weight:900;
color:rgba(255,255,255,.85);
font-size:96px;}
Found this in google search and also lots of plugins are avila
This may not be the most efficient way but it was most definitely the easiest that I've found. You can add the absolute position to the hidden div to make it on top of the image if you so choose!
HTML:
<div id='backgroundImg' onmouseover="hoverOver('show');" onmouseout="hoverOver('hide');">
<div id='hiddenDiv'>
</div>
<img src='myImage.png'>
</div>
Javascript:
<style>
function hoverOver(type) {
if (type=='show') {
document.getElementById('hiddenDiv').style.display='inherit';
} else {
document.getElementById('hiddenDiv').style.display='none';
}
}
</style>
Ok I tried to set the text in a span and when the div (consisting of the image and the text in it) was scrolled over it would set the span opacity to 0. It is not working though, and here is my code.
HTML
<div id="phild">
<td class="bio"> <img class="bio" src="phil.jpg" />
<span id="phils"><h2 id="philh">Phil</h2></span>
</td>
</div>
CSS to make the image opacity:1 when hovered
div#phild :hover{
opacity: 1;
transition: all .2s linear;
}
CSS to make the text opacity:0 when the entire thing (image and text) is hovered over
div#phild:hover span#phils{
opacity:0;
}
If the text is on top of the image, you can't use img:hover for your desired effect because when your cursor is on the text, it doesn't register as hovering the image. You could put the image and text inside something, and then have the text disappear when the parent is hovered
.bio {
position:relative;
float:left;
}
.bio img {
display:block;
}
.bio span {
position:absolute;
bottom:0;
left:0;
transition: all .2s linear;
}
.bio:hover span {
opacity:0;
}
<div class="bio">
<img src="http://placehold.it/100x100" />
<span>Text</span>
</div>
So long as youselectors are correct, the following should work all the way back to IE 6:
img.bio:hover{
opacity: 1; /* css standard */
filter: alpha(opacity=100); /* internet explorer */
}
There a number of ways to do this. Assuming your text follows your img element, you can use the hover pseudo-class and adjacent sibling selector to target the text and apply your CSS.
div {
position: relative;
display: inline-block;
}
.bio {
position: absolute;
top: 50%;
text-align: center;
width: 100%;
}
img:hover + .bio {
opacity: 0;
}
<div>
<img src="http://placehold.it/200x200" />
<span class="bio">Text Here</span>
</div>
I'm building a small website and would like to get the text (and an image when I add one) to fade in when someone accesses the website?
Thanks!
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<style>
body {
background-color: lightgrey;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
</style>
<style>
p.one {
border: 1px lightgrey;
background-color: lightgrey;
padding-top: 50px;
padding-right: 30px;
padding-bottom: 40px;
padding-left: 0px;
}
IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>Our Routes</li>
<li>Contact</li>
<li>About</li>
</ul>
<img class="displayed" src="E:\Users\PC\Documents\Image" alt="...">
<h1 align="center"> HOME </h1>
<p class="one" , align="center"> Text Goes here
</p>
</body>
</html>
http://codepen.io/JTBennett/pen/GorVRL [your site w/ fade and motion]
http://codepen.io/JTBennett/pen/BjpXRo [example of the following instructions]
Here's an example. The HTML requires a div to be wrapped around the whole of the body content if you want it to fade in all at once. Look for this:
<div class="wrapper fade-in">
There's a lot of stuff you can do with CSS, I've been using it for years and I still learn something new every once in a while.
All the animation commands will appear in your CSS like so:
#keyframes fadeIn
to {
opacity: 1; }
Then your divs are going to have a class that calls the animation (#keyframes):
.fade-in {
animation: fadeIn 1.0s ease forwards;
[other div properties can be included here]
}
The HTML will look like this:
<div class="fade-in">
[content]
</div>
Finally, you'll need to make sure you include the vendor codes to make it compatible with all browsers [which adds a fair amount of code, which is why jQuery can be a better option for this stuff]:
#keyframes fadeIn{
0% {
opacity:0;
}
100% {
opacity:1;
}
}
#-moz-keyframes fadeIn {
0% {
opacity:0;
}
100% {
opacity:1;
}
}
#-webkit-keyframes fadeIn {
0% {
opacity:0;
}
100% {
opacity:1;
}
}
#-o-keyframes fadeIn {
0% {
opacity:0;
}
100% {
opacity:1;
}
}
#-ms-keyframes fadeIn {
0% {
opacity:0;
}
100% {
opacity:1;
}
}
The vendor codes will have to be duplicated again in your div class in the CSS:
.fade-in {
animation: fadeIn ease 5s;
-webkit-animation: fadeIn ease 5s;
-moz-animation: fadeIn ease 5s;
-o-animation: fadeIn ease 5s;
-ms-animation: fadeIn ease 5s;
}
The effect can be achieved with jQuery much quicker, as you can see in one of the other answers here.
After you've learned to do it by hand, I suggest playing around with this CSS3 animation generator if you want to save a bit of time:
http://cssanimate.com/
Just make sure you understand it first though.
Lastly, this is an example of jQuery performing similar functions (though using SVGs instead of divs this time, same process though):
http://codepen.io/JTBennett/pen/YwpBaQ
I don't know what element you have but you can do a few things.
If you are using javascript, or jquery you can make an element fade in easily.
Jquery:
$(document).ready(function(){
$('.myItemClass').fadeIn();
});
You can also do it with just CSS
CSS:
/* The animation code */
#keyframes example {
from {opacity: 0;}
to {opacity: 1;}
}
.myClass {
animation-name: example;
animation-duration: 1s;
}
You can fade in elements when the document loads by loading the page with the elements hidden (opacity : 0;) in CSS. Then on document ready you can remove the class, so long as it has a transition for that css property—you'll have an effect.
CSS
div {
transition: opacity 2s;
opacity: 1;
}
.hidden {
opacity: 0;
}
JS
$(document).ready(function(){
$('.hidden').removeClass('hidden');
});
It is very simple don't need even jqyery, pure CSS and pure Javascript.
CSS
body {
opacity:0;
transition: 300ms opacity;
}
Javascript
function pageLoaded() {
document.querySelector("body").style.opacity = 1;
}
window.onload = pageLoaded;
I like pretty much the slow auto zoom in and out effect on that site : http://watchingtheworldcup.com/ for banner images such as the very top one.
I tired to replicate it, by looking at developer tools wihtin browser, but have some trouble implementing it as in developper tool some mentions are stroked etc.
here is my html :
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#">
<article class="article_container">
<img class="article_image_hompage5" src="#">
<h2 class="article_title_hompage3"> a favourite thai soup</h2>
</article>
</a>
</div>
</div>
and my css for the image :
.article_image_hompage5{
width: 100%;
border-radius: 2px 2px 2px 2px;
position:relative;
display:block;
margin-left:auto;
margin-right:auto;
margin-top:15px;
z-index:0;
}
Can someone help with with finding the right css settings ?
cheers,
Use css animation you can get the similar result.
/* Chrome, Safari, Opera */
#-webkit-keyframes zoom {
from {
-webkit-transform: scale(1,1);
}
to {
-webkit-transform: scale(1.5,1.5);
}
}
/* Standard syntax */
#keyframes zoom {
from {
transform: scale(1,1);
}
to {
transform: scale(1.5,1.5);
}
}
img {
-webkit-animation: zoom 50s; /* Chrome, Safari, Opera */
animation: zoom 50s;
}
<img alt="" src="http://watchingtheworldcup.com/photos/worldcup1.jpg" />
If you want to also zoom out you need to define the the milestones in your keyframes as such:
#-webkit-keyframes zoominout {
0% {
-webkit-transform: scale(1,1);
}
50% {
-webkit-transform: scale(1.5,1.5);
}
100% {
-webkit-transform: scale(1.1,1.1);
}
}
Use css transform:scale();
like:
JavaScript:
window.onload=function(){
$("#content").fadeOut(4000);
$("#background").addClass("zoom");
setTimeout(function(){
$("#background").removeClass("zoom");
},5000);
}
body{
margin:0px;
padding:0px;
width:100%;
height:100%;
}
#background{
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%;
background:url("http://watchingtheworldcup.com/photos/worldcup1.jpg") center center no-repeat;
background-size: 100% 100%;
display:inline-block;
z-index:2;
transition:all ease 4.1s;
/* transform:scale(1,1);*/
}
#content{
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%;
z-index:3;
background-color:rgba(0,0,0,0.5);
color:#ffffff;
font-size:50px;
}
.zoom{
transform:scale(1.2,1.2);
}
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<div id="background">
</div>
<div id="content">
<center><br /><br /><br /><br /><br /><br />
Watching...
</center>
</div>