css not working on :hover - html

first of all, here's a Reference to what I want to do, based my code off that one.
I'm having a bit of trouble using css, I have a php file that returns a table with images:
echo '<td valign="bottom">
<div class="profile-image">
<figure>
<img src="'.$image.'" width="250px" height="200px" />
<figcaption>'.$nombreAlmno.'<br>'.$semestre.' semestre</figcaption>
</figure>
<span class="overlay"></span>
</div>
</td>';
It does work, this is what I get:
So my problem is I'm trying to display another image on hover using the <span class="overlay"> which I call on my css file:
.profile-image:hover .overlay {
position:absolute;
width: 800px;
height: 800px;
z-index: 100;
background: transparent url('http://farm4.static.flickr.com/3261/2538183196_8baf9a8015.jpg') no-repeat;
cursor: pointer;
}
I know my css is working (part of it at least) because when I put the cursor over an image, it changes to the pointer cursor, yet the span is not showing at all.
Any tips or tricks would be appreciated.

You need the parent element (the one that the absolute positioning is being set relative to) to have a set position (in this case, position:relative is probably best). Also, be sure to set the top, bottom, left, or right properties to control where the image appears!
http://jsfiddle.net/gztLspL3/4/
HTML:
<table>
<td valign="bottom">
<div class="profile-image">
<figure> <a href="#">
<img src="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_s.jpg" width="250px" height="200px" />
</a>
<figcaption>'.$nombreAlmno.'
<br>'.$semestre.' semestre</figcaption>
</figure> <span class="overlay"></span>
</div>
</td>
CSS:
.profile-image {
position: relative;
}
.profile-image:hover .overlay {
position: absolute;
width: 800px;
height: 800px;
z-index: 100;
background: transparent url('http://farm4.static.flickr.com/3261/2538183196_8baf9a8015.jpg') no-repeat;
cursor: pointer;
left: 100%;
top: 0;
}
Also, if you want it to appear directly next to the image:
http://jsfiddle.net/gztLspL3/6/

Add jquery like this
$( "div.profile-image>a>img" ).hover(
function() {
$( "#bigOne").first().css("display", "block").css("background", "transparent url('" + $(this).prop("src").replace("_s.jpg", ".jpg") + "') no-repeat");
}, function() {
$( "#bigOne" ).css("display", "none").css("background", "");
}
);
and change your css name
#bigOne {
position:absolute;
width: 800px;
height: 800px;
z-index: 100;
cursor: pointer;
display:none;
}
and change <span class="overlay"></span> to <span id="bigOne"></span>
dont forget adding jquery your page
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

Related

Add width="200" height="200" to onmouseover

So, I currently have an image that is 400x400 pixels. When scaled externally to 200x200 it looks pixilated. I've therefore added it to Wordpress as 400x400 but scaled it down as follows:
However, I'm now trying to add an onmouseover event, with the scaled down image.
It works fine for the normal image, like this:
https://y.png'" onmouseout="this.src='https://x.png'" />
But if I try and scale the image, as follows, it doesn't work:
https://y.png' width="200" height="200"" onmouseout="this.src='https://x.png'" />
Please note I've left the source of the image out and replaced with 'x' and 'y'.
Does anyone know how to resolve this please?
Thanks all.
You could use the :before pseudo selector to show a background image. This will let you shrink down the 400x400 image in CSS. Run this and hover over the element.
.item {
position: relative;
overflow: hidden;
display: inline-block;
}
.item:hover:before {
content: "";
background-image: url(http://placehold.it/400x400);
background-size: 200px;
background-repeat: no-repeat;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<a href="#" class="item">
<img src="http://placehold.it/200x200/8B0AB3/ffffff" />
</a>
You should be able to accomplish this without JavaScript.
Here's a Codepen demo: http://codepen.io/hellojason/pen/GZjpQE
In CSS:
img {
width: 200px;
transition: width 1s;
}
img:hover, img:focus {
width: 400px;
}
<img src="http://placehold.it/400x400" />
Is this what you're after?
Two way for this task you can use
First way using Javascript.
Script :
function bigImg(x) {
x.style.height = "400px";
x.style.width = "400px";
}
function normalImg(x) {
x.style.height = "200px";
x.style.width = "200px";
}
Html :
<img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="http://placehold.it/400x400" alt="Smiley" width="32" height="32">
You can call your own function from onmouseover or onmouseout function.
Second way using CSS :
CSS :
#image{
width:200px;
height:200px;
}
#image:hover{
width:400px;
height:400px;
}
Html :
<img border="0" src="http://placehold.it/400x400" alt="Smiley" id="image">

CSS notification style badge over image

I'm attempting to place a 'notification' style badge over an images. I am using Twitters Bootstrap as a base framework and creating a custom CSS class called notify-badge. But I cannot get anything to line up properly.
Through the magic of Photoshop, here is what I am trying to accomplish.
Here is my CSS code.
.notify-badge{
position: absolute;
background: rgba(0,0,255,1);
height:2rem;
top:1rem;
right:1.5rem;
width:2rem;
text-align: center;
line-height: 2rem;;
font-size: 1rem;
border-radius: 50%;
color:white;
border:1px solid blue;
}
I would like to be able to place any small about of text in the badge and it expand the red circle to fit.
Here is my HTML code.
<div class="col-sm-4">
<a href="#">
<span class="notify-badge">NEW</span>
<img src="myimage.png" alt="" width="64" height="64">
</a>
<p>Some text</p>
</div>
Bunch of different ways you can accomplish this. This should get you started:
.item {
position:relative;
padding-top:20px;
display:inline-block;
}
.notify-badge{
position: absolute;
right:-20px;
top:10px;
background:red;
text-align: center;
border-radius: 30px 30px 30px 30px;
color:white;
padding:5px 10px;
font-size:20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-sm-4">
<div class="item">
<a href="#">
<span class="notify-badge">NEW</span>
<img src="https://picsum.photos/200" alt="" />
</a>
</div>
</div>
Addendum (from the Asker #user-44651)
(moved from the question)
Here is the result of applying this answer.
Adding margin-top:-20px; to .item fixed the alignment issue.
The idea here is to overlay an absolute container on top of a relative one. Here's a similar example:
<div class="image">
<img src="images/3754004820_91a5c238a0.jpg" alt="" />
<h2>A Movie in the Park:<br />Kung Fu Panda</h2>
</div>
The CSS:
.image {
position: relative;
width: 100%; /* for IE 6 */
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
This is going to put our text right up on top of the image nicely, but it doesn't accomplish the box we want to achieve behind the text. For that, we can't use the h2, because that is a block level element and we need an inline element without an specific width. So, wrap the h2 inside of a span.
<h2><span>A Movie in the Park:<br />Kung Fu Panda</span></h2>
Then use that span to style and text:
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
For ideas on how to ensure proper spacing or to use jQuery to cleanup the code a bit by allowing you to remove some of the tags from the code and jQuery them back in, check the source.
Here's a fiddle I made with the sample code:
https://jsfiddle.net/un2p8gow/
I changed the notify-badge span into a div. I saw no reason it had to be a span.
I changed the position to relative. Edit - you could actually keep the attribute position: absolute; provided you know what you're doing with it. Guy in the comments was right.
You had the attribute right: 1.5rem; and I simply changed it to left because it was being inset in the opposite direction of your example.
You can tweak it further but in a vacuum this is what you want.

Image hover function (css) doesn't find image

I want to have a button with an image and a link. Here is my style-code:
<style>
twitter{
display:block;
background-image: url('CIMA/Social/Twitter.png');
width: 30%;
height: 30%;
}
</style>
and my body code:
<twitter href="#"> </twitter>
But it doesnt show any image. I tried a lot of different image-paths, but it just will not show...
oh. why not
<img src= "cima/social/twitter.png" />
<style>
a img {width:30%;height:30%;}
</style>
You HTML is invalid as you are using custom (non-valid) elements. Try
HTML
<a class="twitter" href="#"> </a>
CSS
.twitter{
display:block;
background-image: url('CIMA/Social/Twitter.png');
width: 30px; /* or whatever value */
height: 30px;
}

How to place an img on top of another img

I am trying to place one on top of another at my website finegra.in. Here is a screenshot of the site right now:
I just want the "visit our kickstarter project" img to go right here:
Here are the html and stylesheets:
<div id="page" class="hfeed">
<header id="branding" role="banner">
<!--
<nav id="access" role="navigation">
<h3 class="assistive-text">Main menu</h3>
<div class="skip-link"><a class="assistive-text" href="#content" title="Skip to primary content">Skip to primary content</a></div>
<div class="skip-link"><a class="assistive-text" href="#secondary" title="Skip to secondary content">Skip to secondary content</a></div>
<div class="menu"><ul><li class="current_page_item">Home</li></ul></div>
</nav><!~~ #access ~~>
-->
<hgroup>
<div>
<a href="http://www.finegra.in"><img id="logo" alt="fine grain Logo" src="http://www.finegra.in/wp-content/uploads/2012/04/fineGRAINlogoGOOD-WEB.png">
</a>
<img id="headerimg" alt="The Sheffield Case" src="http://www.finegra.in/wp-content/uploads/2012/04/headerimg2.jpg">
<a href="http://www.kickstarter.com/projects/finegrain/17408941?token=364cb635"><img id="branding" alt="The Sheffield Case" src="http://www.finegra.in/wp-content/uploads/2012/04/checkOurProject.png">
</a>
</div>
<div id="site-generator">
FineGrain LLC Copyright 2012. All Rights Reserved
</div>
</hgroup>
</header><!-- #branding -->
style.css:
#branding {
border-top: 0px solid #BBBBBB;
padding-bottom: 10px;
position: relative;
z-index: 9999;
background: none repeat scroll 0 0 #DADAD2;
}
#headerimg {
width: 30% !important;
width: 100% !important;
}
#branding img {
margin-bottom: 20px;
width: auto;
}
.one-column #page {
max-width: 1500px;
}
.one-column #content {
margin: 0;
width: auto;
}
Assuming you are using jQuery, you may create the watermarks for your images at the DOM ready function and make theirs position absolute and calculated relative to the images.
<script type="text/javascript">
// Watermark image, change the src with your image's url
var watermark = '<img src="watermark.png" border="0" style="border:none; background-color:transparent; position:absolute; ';
// Position relative to image inside:
var insideTop = 20;
var insideLeft = 50;
$(document).ready(function () {
$("img").each(function (ix, el) {
var top = $(this).offset().top + insideTop;
var left = $(this).offset().left + insideLeft;
var imgWatermark = watermark + 'top:' + top + 'px; left:' + left + 'px;"/>';
$("body").append(imgWatermark);
});
});
</script>
If you have images that will have the watermark and images that won't, add an attribute class="withWatermark" to the images that will have and replace the $("img") in the script with $(".withWatermark").
<img src="myimage.jpg" class="withWatermark" />
$(".withWatermark").each(function (ix, el) {
How about something like this? http://jsfiddle.net/UtKbC/
CSS:
.visit_project {
position: absolute;
top: 250px;
left: 400px;
}
HTML:
<a href="http://www.kickstarter.com/projects/finegrain/17408941?token=364cb635" class="visit_project"><img id="branding" alt="The Sheffield Case" src="http://www.finegra.in/wp-content/uploads/2012/04/checkOurProject.png">
</a>
It might be wiser to wrap the header image in it's own div and set the checkOurProject.png image to the absolute value based on that div wrapper.
I think you can do this easily by simple css with the help of float :-
CSS
#header {
background: url("http://i.imgur.com/1nrC6.jpg");
width:1040px;
height:402px;
}
.logo {
float:right;
margin-top:200px;
}
HTML
<div id="header">
<img class="logo" src="http://i.imgur.com/17oqa.png"border="0"/>
</div>
see the demo:- http://jsfiddle.net/UtKbC/6/

Suggestion for gallery thumbnail on click?

I'm trying to build an image gallery with thumbnails and a display for a larger image. At present, its working when the the mouse hovers over the thumbnail which displays the larger image. However I wish to replace the hover feature with an on click so that the larger image does not disappear when the mouse leaves the thumbnail. From a bit of research I'm lead to believe that this can not be done with css as with the hover feature and that I would need to include some script. As I'm new to web development after this I'm a bit lost and would appreciate some help. Below is the html code for the gallery container and the corresponding css code......where do I start from here?
Thanks
A
html code
<div class="gallerycontainer">
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/101.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/101.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/102.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/102.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/103.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/103.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/104.jpg" width="56px" height="80px"border="0" /><span><img src="images/gallery/1one/104.jpg" width="405px" height="585px"/></span></a>
<br />
</div>
css code
.gallerycontainer{
position: absolute;
/*Add a height attribute and set to largest image's height to prevent overlaying*/
}
.thumbnail img{
border: 1px solid white;
margin: 0 5px 5px 0;
}
.thumbnail:hover{
background-color: transparent;
}
.thumbnail:hover img{
border: 1px solid grey;
}
.thumbnail span{ /*CSS for enlarged image*/
position: absolute;
background-color: #000000;
padding: 5px;
left: -1000px;
border: none;
visibility: hidden;
color: black;
text-decoration: none;
}
.thumbnail span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 2px;
}
.thumbnail:hover span{ /*CSS for enlarged image*/
visibility: visible;
top: 0;
left: 300px; /*position where enlarged image should offset horizontally */
z-index: 50;
}
Heres a simple start with jquery.
http://jsfiddle.net/8GKXM/
$('.thumbnail').each(function(){
$(this).click(function() {
$('.thumbnail span').hide();
$(this).find('span').show('slow');
});
});
This is what the jquery says basically:
On every individual .thumbnail click:
hide .thumbnail span ( as in every span it finds )
then
find clicked .thumbnail's span and show that
I would probably move the bigger images into their own container though...
You can use jQuery along with blockUI plugin:
<div class="gallerycontainer">
<a class="thumbnail" href="#thumb" class="imgthumb"><img src="images/gallery
/1one/101.jpg" width="56px" height="80px" border="0" /></a>
<a class="thumbnail" href="#thumb" class="imgthumb"><img src="images/gallery
/1one/102.jpg" width="56px" height="80px" border="0" /></a>
</div>
And then you can use the window onload event to attach the onclick event to fire the large image with blockUI:
$(function(){
$(".imgthumb").onclick(function() {
$.blockUI({
message: "<div><img src=" + $(this + " > img").attr("src") + " width='405' height='585' /></div>";
css: { border: '1px solid grey'}
});
});
});