Two divs to display on image mouseover - css

finally figured out the result , used both js and css together to work,
thanks guys :)
FINAL JSFIDDLE CODE
find codes below
i have made an example with using other codes, to display 'info <DIV>' to show up when mouseover on image, but i m having problem when i try to show "caption <DIV>" over the image. i have tried to add codes in the css but anything i do stops "info <DIV>" to show up :(
can some one please look into this set of code :jsfiddle
and if the "info <DIV>" can be displayed in a separate <div> it would be great help.
thanks
regards.
code html
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols-Critical-icon.png" class="team"/>
<div class="info">"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR></div>
<div class="caption">SYMBOL</div>
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols-Favourite-1-icon.png" alt="" class="team"/>
<div class="info">and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR></div>
<div class="caption">STAR</div>
​
CSS code
.team , .info{
background: #151515;
height: 150px;
width: 150px;
}
.info{
background:white;
height: 50%;
width: 20%;
display:none;
position: absolute;
top: 10px;
right: 10px;
}
.team:hover + .info {
display:block; }
.team {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.team:hover {
opacity: 0.5;
}​

Its unbelievable what CSS is capable of doing - but don't abuse it too much. There has been some really fancy widgets and templates I have seen done entirely in CSS (which is great) but I would suggest to be careful when you "hack" CSS vs. using javascript. IMHO this is a css hack:
.team:hover + .info {
display:block;
}
It is OK to use CSS to change the style/display of an element NESTED within that element for instance:
<div>
<a class="close" href="#">Close me</a>
</div>
When you hover over <div then a.close should show up (display: block;).
In your specific case - you are using css to change a NON-NESTED element's display. Using javascript is recommended instead of a css hack because if you ever (and most likely you will) want to enable a user to move their mouse away from the picture and hover over the caption div and highlight text, click on link... etc. you will HAVE to use javascript. CSS is limited in its capabilities and its complexity greatly increases when you use transcend beyond its intended purposes.
As such, I recommend javascript (w/ jquery or other library).

I added the caption class in the css and styled the caption.
In your code the caption would stay under the image. Then i set the position:relative and set the position of 20px from the bottom. I gave it a background-color:red in order to let you see where it is located. I also gave the caption a width of 150px as the width of the images. You used the classes team, info and caption. In order to target the mouseover function separetely in every image i created 2 different kind of classes for every image, so: team1, team2, info1, info2, caption1, caption2. If you use want to use 3 images on your webpage you'll have to add team3, info3, caption3 and so on, in your html, css and jquery function. (You can just copy and paste and rename). i added a parent div with id image that wraps every image and gives relative positioning. You can edit the code as you want.
Here is the edited HTML:
<div id="image">
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols- Critical-icon.png" class="team1"/>
<div class="info1">"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol" <BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol" <BR>"this is a symbol"<BR></div>
<div class="caption1">SYMBOL</div>
</div>
<div id="image">
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols- Favourite-1-icon.png" alt="" class="team2"/>
<div class="info2">and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR></div>
<div class="caption2">STAR</div>
</div>​
​
Here's the edited CSS:
.team1 {
background: #151515;
height: 150px;
width: 150px;
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.info1{
background: white;
height: 150px;
width: 150px;
visibility:hidden;
position: absolute;
top: 10px;
right: 10px;
}
.team2{
background: #151515;
height: 150px;
width: 150px;
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.info2 {
background: white;
height: 150px;
width: 150px;
visibility:hidden;
position: absolute;
top: 10px;
right: 10px;
}
.team1:hover {
opacity: 0.5;
}
.team2:hover {
opacity: 0.5;
}
.caption1 {
position:relative;
background-color:red;
width:150px;
bottom:20px;
visibility:hidden;
}
.caption2 {
position:relative;
background-color:red;
width:150px;
bottom:20px;
visibility:hidden;
}
#image {
position:relative;
}
​
Then i added some jquery functions that you can put in the body of your html page after the other html code:
$(".team1").mouseout(function () {
$(".caption1").css("visibility","hidden");
$(".info1").css("visibility","hidden");
});
$(".team1").mouseover(function () {
$(".caption1").css("visibility","visible");
$(".info1").css("visibility","visible");
});
$(".team2").mouseout(function () {
$(".caption2").css("visibility","hidden");
$(".info2").css("visibility","hidden");
});
$(".team2").mouseover(function () {
$(".caption2").css("visibility","visible");
$(".info2").css("visibility","visible");
});
​In order to use the jquery functions you have to include the jquery library in your page by inserting: <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script> in the head of your HTML page, like this:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
</head>
Here's a demo on jsfiddle

Final code
html
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
<style type='text/css'>
.team img {
width: 100%;
height: 100%;
position: absolute;
z-index: 1;
}
.team .caption {
position: absolute;
bottom: 1px;
right: 0px;
width: 100%;
height: 25%;
display: none;
z-index: 2;
text-align: right;
color: #ffffff;
padding: 10px;
background: rgba(0, 0, 0, .75);
}
.team .caption a {
color: #ffffff;
}
</style>
<body>
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$('.team').mouseover(function() {
$(this).find('.caption').fadeIn(100);
});
$('.team').mouseleave(function() {
$(this).find('.caption').fadeOut(100);
});
});//]]>
</script>
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$('.team').hover(function() {
$(this).find('.info').fadeIn(100);
});
$('.team').mouseleave(function() {
$(this).find('.info').fadeOut(100);
});
});//]]>
</script>
<div class="team">
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols-Critical-icon.png" >
<div class="caption">SYMBOL</div>
<div class="info">"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR>"this is a symbol"<BR></div></div>
<div class="team">
<img src="http://icons.iconarchive.com/icons/tpdkdesign.net/refresh-cl/256/Symbols-Favourite-1-icon.png">
<div class="caption">STAR</div>
<div class="info">and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR>and this is a star<BR></div></div>
</body>​
css
.team {
background: #151515;
height: 150px;
width: 150px;
position: relative;
}
.info{
background:white;
height: 100%;
width: 100%;
display:none;
position:fixed;
float:right;
top: 0px;
left: 70% ;
z-index: 99;
}

Related

Making rollover between 2 images by hover

I'm using React and try to change 2 images by hovering them.
This is what I have done so far:
Card.js
<div className="image-wrapper">
<img src={sprites.front_default} className="image" alt="normal" />
<img src={sprites.back_default} className="image-hover" alt="hover" />
</div>
style.css
.image-wrapper {
position: relative;
}
.image-hover {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 1s ease-out;
}
.image-hover:hover {
opacity: 1;
}
The main problem is that i want to make the front image opacity to 0 when im hovering the div, how can i make it?
I can make it without the fade changing but its important to make it with transition.
This is how I make it without transition
<img
className="figure"
src={sprites.front_default}
onMouseOver={(e) => (e.currentTarget.src = sprites.back_default)}
onMouseOut={(e) => (e.currentTarget.src = sprites.front_default)}
alt={"pokemon"}
/>
You can use just HTML & CSS. In the Card:
<div className="image-wrapper">
<img
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png"
className="pokemon-image"
alt="normal"
/>
<img
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/2.png"
className="pokemon-image pokemon-image--back"
alt="normal"
/>
</div>
Here, I've used one class pokemon-image to position the two images at the center of the image-wrapper element, and pokemon-image--back as the class that is showed when hovering over the image-wrapper element.
The CSS:
.image-wrapper {
width: 200px;
height: 150px;
background-color: #f7f7f7;
position: relative;
}
.pokemon-image {
position: absolute;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
.pokemon-image--back {
opacity: 0;
transition: opacity 1s ease-out;
}
.image-wrapper:hover .pokemon-image--back {
opacity: 1;
}
Hope this helps. You can try it in this codesandbox.

Responsive background image - bootstrap grid - Scroll bar issue

I want to create full screen background image within a bootstrap-grid so that it can be responsive.
I created a row and made it to 100% height so that it can fit the entire screen.
Added a 1024*768px resolution image , it perfectly appeared in background but with scroll bars.
I just want to get rid of the scroll bars so that it fit in screen. Here is my html
html,body,.container-fluid{
height:100%;
}
.row{
height:100%;
}
img {
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
width: 100vw;
height: 100vh;
}
<div class="container-fluid">
<div class="row" >
<img src="retail.jpg">
<div class="col-md-12">
</div>
</div>
</div>
Can someone help me ?
Here is something.
The picture is full screen, and the content is on bottom.
If you remove the content, the scrollbar wont appears.
Bootply: http://www.bootply.com/sFNwejI4ow
CSS:
html,body,.container-fluid{
height:100%;
}
.full{
height:100%;
}
img {
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
width: 100%;
height: 100%;
}
HTML:
<div class="container-fluid">
<div class="row full">
<img src="//placehold.it/640x480">
</div>
<div class="row">
<div class="col-md-12">
Custom content
</div>
</div>
</div>
This should by default remove both horizontal and vertical scrollbars:
<style type="text/css">
body {
overflow:hidden;
}
</style>
Sadly, this will also disable scrolling on page.
Alternatively, you can implement Fancy Scrolling. The scrollbar is thinner, looks better on page and has smooth scrolling.
Try this:
Here's the script: Link
Implementation:
First call the plugin on a container.
<script>
$(function() {
$( "#demo" ).customScroll();
});
</script>
Here's the CSS:
.phancy-scrollbar {
width: 5px;
border-radius: 4px;
top: 0;
position: absolute;
background: #ccc;
-moz-transition: opacity .2s;
-webkit-transition: opacity .2s;
-o-transition: opacity .2s;
-ms-transition: opacity .2s;
transition: opacity .2s;
-webkit-transition-delay: 1s;
opacity: 0;
}
.phancy-scroller .phancy-scrollbar:active, .phancy-scroller:hover .phancy-scrollbar {
opacity: 1;
-webkit-transition-delay: 0s;
}
.phancy-scrollbarbutton {
width: 100%;
border-radius: 4px;
top: 0;
position: absolute;
background-color: #999;
}
Hope this helps. Cheers!!
/* attributes overflow, background-size modified */
html,body,.container-fluid{
height:100%;
overflow: hidden; // -> newly added
}
.row{
height:100%;
}
img {
background-position: center center;
background-repeat: no-repeat;
background-size: contain cover; // modified here
width: 100vw;
height: 100vh;
}
plunker demo

rollover over image, different image appears below

I'm trying to make a grid of images that once you hover over one, it's webpage title appears below it, as well as the other images around it changing in opacity.
I have managed to create the opacity mouseover effect I want, but now I'm having trouble making the page heading images appear as you hover over the corresponding image. I hope that makes sense
Hope someone can help. Here is my code
HTML:
<div style="position: relative; left: 140px; top: 0px;">
<img src="window.jpg" style="position: relative; top: 0; left: 0;"/>
<div id="windowimages">
<a class="image-one"></a><a href="https://example-site.com/music/">
<img src="pic1.jpg/>
<a class="image-two"></a><a href="https://example-site.com/dance/">
<img
src="pic2.jgp"/>
<a class="image-three"></a><a href="https://example-site.com/art/">
<img
src="pic3.jpg" />
<a class="image-four"></a><a href="https://example-site.com/aboutus/">
<img
src="pic4.jpg"/>
</div>
CSS:
body {
}
#windowimages {
position: absolute;
left: 3px;
top: 4px;
font-size: 0;
width: 198px;
margin: 0 auto;
padding:1px;
overflow:hidden
}
#windowimages img {
width:90px;
height:90px;
margin: 3px;
cursor:pointer;
-webkit-transition:opacity 0.26s ease-out;
-moz-transition:opacity 0.26s ease-out;
-ms-transition:opacity 0.26s ease-out;
-o-transition:opacity 0.26s ease-out;
transition:opacity 2s ease-in-out;
}
#windowimages:hover img {
opacity:0.55;
}
#windowimages:hover img:hover {
opacity:1;
}
If I understood you correctly, it seems like what you want to do is add a title to each image on hover.
Check out this example I wrote: http://jsfiddle.net/arthurcamara/chbsL3pq/
The key part to adding the title was .image:hover:after as you can see above and in the code below:
.grid:hover .image:hover:after {
display: block;
position: absolute;
top: 5px;
width: 90px;
padding: 5px;
content: attr(data-title);
text-align: center;
background-color: #333;
color: #fff;
}
I changed your markup a bit as well to make it more semantic. Check out the example and let me know if that helped :)

CSS3 :target not working?

I have the following code :
<!DOCTYPE html>
<html>
<head>
<title>Void Museum</title>
<meta charset="utf-8">
<style type="text/css">
html * {
margin: 0;
padding: 0;
}
#panel,
#content {
position: absolute;
top: 0;
bottom: 0;
}
#panel {
left: -220px;
width: 250px;
background: #030;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
#content {
left: 250px;
right: 0;
background: #003;
}
#panel:target {
left: 0;
background: red;
}
#content:target {
background: yellow;
}
</style>
<script type="text/javascript">
</script>
</head>
<body>
<div id="panel">
LEFT PANEL
</div>
<div id="content">
CONTENT
</div>
</body>
</html>
And two questions :
Why isn't the panel coming out when i click on it ?
How could i force the #content block's left property to 250px when #panel is targeted ? Should i change all this to use relative positions ? If so, how would i force #content not to overflow of the right side of the page ?
This code does work when i use :hover instead of :target so i assume there's something i don't understand about :target.
Thanks in advance :)
The reason it isn't working is because you are using :target as "is-clicked" or similar, which doesn't exist. In CSS, something that can mimic that behaviour is the following:
You make a href to an id (e.g. #panel) and then click it. Now you have a #panel on your url and can start using :target
See here
The text links to #panel, activating :target and allowing it to work as if it was "clicked".

Make image visible on div:hover but not if another image in that div is hovered?

On my photography portfolio, I have thumbnails set up so that when you hover over the thumbnail (which are actually divs with background-image set to the thumbnail), a magnifying glass icon (which is an absolute-positioned img) is set via CSS to opacity:1.0.
However, for some images I'll have wallpapers available for download (the first image in the top-left is an example). To indicate this, I'll have a monitor icon (also absolute-positioned) inside this div as well (in the opposite corner). When this image is hovered over, I don't want the magnifying glass icon to appear.
EDIT:
Here is the actual HTML as generated by PHP:
<div class="thumbnail" style="width:240px; height:160px;">
<a href="gallery/01_CONSTRUCTS/Steam.jpg" class="shadowbox[CONSTRUCTS]" title="Steam">
<span class="rounded_corners thumb_back" style=" background-image:url('gallery/01_CONSTRUCTS/thumbs/Steam_thumb.jpg');"> </span>
<span class="rounded_corners hover_dim"> </span>
<img class="zoom" src="images/zoom.png" alt="Zoom" />
</a>
<img class="thumb_new" src="images/new.png" alt="New" />
<a class="wall_hover" href="gallery/01_CONSTRUCTS/wallpaper/Steam.jpg">
<img class="wallpaper" src="images/monitor.png" alt="DownloadWallpaper" />
</a>
</div>
And the relevant CSS:
.thumbnail {
display: block;
position: relative;
float: left;
}
.thumbnail:hover, .thumbnail:hover .zoom {
opacity: 1.0;
-webkit-opacity: 1.0;
-moz-opacity: 1.0;
}
.thumbnail a.wall_hover + a .zoom {
display: none;
}
.thumb_new {
position: absolute;
top: 2px;
left: 2px;
z-index: 100;
}
.zoom {
position: absolute;
bottom: 3px;
right: 3px;
opacity: 0;
-webkit-opacity: 0;
-moz-opacity: 0;
transition: opacity .25s ease-in;
-webkit-transition: opacity .25s ease-in;
-moz-transition: opacity .25s ease-in;
}
.hover_dim {
background-color: rgba(0,0,0,0.5);
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
transition: background-color .25s ease-in;
-webkit-transition: background-color .25s ease-in;
-moz-transition: background-color .25s ease-in;
}
.thumbnail:hover .hover_dim {
background-color: rgba(0,0,0,0);
}
.wallpaper {
position: absolute;
bottom: 3px;
left: 3px;
}
.rounded_corners {
padding: 0;
margin: 0 5px 5px 0;
border: 0;
border-radius: 6px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
}
This should work if your structure is now correct. It is similar to Jane's answer, only it needs to be .wall_hover:hover not .wallpaper:hover.
.thumbnail:hover > .wall_hover:hover + .zoom {
opacity: 0;
-webkit-opacity: 0;
-moz-opacity: 0;
}
Update Do to Your Break
You really need to learn some about what css selectors are actually doing, else you could break things again. So, let me help that education along. First, your "new" (current as of now) html structure is this:
<div class="thumbnail" style="width:240px; height:160px;">
<a class="shadowbox[CONSTRUCTS]" title="Steam" href="gallery/01_CONSTRUCTS/Steam.jpg">
<span class="rounded_corners thumb_back" style=" background-image:url('gallery/01_CONSTRUCTS/thumbs/Steam_thumb.jpg');"> </span>
<span class="rounded_corners hover_dim"> </span>
<img class="thumb_new" alt="New Image" src="images/new.png">
<img class="zoom" alt="Zoom In" src="images/zoom.png">
</a>
<a class="wall_hover" href="gallery/01_CONSTRUCTS/wallpaper/Steam.jpg">
<img class="wallpaper" alt="Download Wallpaper" src="images/monitor.png">
</a>
</div>
That will not work to achieve the effect you want (through pure css, anyway). You have to "swap" positions on the a tags. Short example (some code removed for brevity):
<a class="wall_hover">
<img class="wallpaper" >
</a>
<a class="shadowbox[CONSTRUCTS]">
<img class="zoom" />
</a>
The reason for this is that css can make selections within elements or in certain cases of following elements, but not preceding elements or parent elements. So that is why the html order must change, because you want to affect .zoom with .wall_hover. We are doing that using the adjacent sibling selector + which selects only the element immediately following. So now, to get your css to work, you need:
.thumbnail:hover > .wall_hover:hover + .shadowbox[CONSTRUCTS] .zoom {
opacity: 0;
-webkit-opacity: 0;
-moz-opacity: 0;
}
Note the change is because you wrapped .zoom in a parent element shadowbox[CONSTRUCTS]. What the above is saying is:
When .thumbnail is being hovered, then go to its immediate child (>)
that is a class of .wall_hover, and if it is being hovered, then move
to its immediately adjacent sibling and if that is a
.shadowbox[CONSTRUCTS] class, then select its child element of
.zoom. You could add a > before .zoom, but it is not necessary in
your case (actually, it is really not necessary before .wall_hover in
your case either, but I kept it for illustration purposes.
Place .zoom after .wallpaper in your html
<div class="thumbnail" style="background-image:url('img.jpg'); position:relative">
<img src="monitor.jpg" class="wallpaper" />
<img src="magnifying.jpg" class="zoom" />
</div>
so css will
.thumbnail:hover > .wallpaper:hover + .zoom {
opacity: 0;
-webkit-opacity: 0;
-moz-opacity: 0;
}
You can do it with CSS with the sibling selector, but only if you switch the order of the images:
.thumbnail .wallpaper + .zoom {
display: none;
}
As I can see in your website you have a more complex structure. The images are contained inside a tags. You will need to apply the sibling selector to the a tag like this:
.thumbnail a.wall_hover + a .zoom {
display: none;
}
Note that for this to work you will need to put a.wall_hover as the first link in the div.
There is another alternative using jQuery, just put this line on document load:
$(".thumbnail").has(".wallpaper").find(".zoom").hide();

Resources