I have a php file, where I had made some querys to a phpbb database, obtaining some variables (like topic_title and a image link)
I know how to show the image in php, but now I want to make them bigger on hover, and, when the image is big, show the topic title below, is this posible?
here is the code:
echo '<table cellspan="4">';
echo "<tr>\n";
while ($fila = $resultado->fetch_assoc()) {
preg_match('/\[r?img:(.*?)\](.*?)\[\/r?img:(.*?)\]/', $fila['post_text'], $fila_contenido);
$sololink = preg_replace('[^a-zA-Z0-9_+.-]','',#$fila_contenido[2]);
$fila2 = $fila["post_subject"];
echo "<th><img src=$sololink></th>";
}
echo "</tr>\n";
then I want to grow $sololink (the image) on hover, and show $fila2 (the title) below the grew image
thanks
Here's an example only using CSS.
HTML:
<div class="container">
<img class="image" src="http://lorempixel.com/400/200/" />
<div class="title">Title of this image is here</div>
</div>
CSS:
.image {
-webkit-transition: width 2s, height 2s;
transition: width 2s, height 2s;
width: 400px;
height: 200px;
}
.title {
-webkit-transition: opacity 2s;
transition: opacity 2s;
font-size: 30px;
opacity: 0;
}
.container:hover .image {
width: 600px;
height: 300px;
}
.container:hover .title {
opacity: 1;
}
Example
Related
Dears,
I'm using the code below to show list of images from database and showing some text (also from DB) over the images when hover.
I need to keep the current settings but to also add one more text (from DB) but to be shown always (static) over the image:
CSS:
.wrapper {
position: relative;
padding: 0;
width:100px;
display:block;
}
.text {
position: absolute;
top: 0;
color:#333;
background-color:rgba(255,255,255,0.2);
width: 500px;
font-size:18px;
height: 100%;
line-height:100px;
text-align: center;
z-index: 10;
opacity: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.text:hover {
opacity:1;
}
.img {
z-index:1;
}
.grid {
position:relative;
float:left;
width: 500px;
height:333px;
margin-bottom: 10px;
margin-right: 10px;
border: 0;
text-align:center;
vertical-align:middle;
}
Code:
foreach($dbrow as $row) {
?>
<div class="grid">
<a href="<?php echo $row['hotel_url']; ?>" class="wrapper">
<span class="text">
<b><?php echo $row['name']; ?></b>
<br/>
<?php echo $row['desc_en']; ?>
<br/>
<i>Book Now</i>
</span>
<img align="center" src="<?php echo $row['photo_url']; ?>">
</a>
</div>
<?php
}
You could change a bit your HTML using HTML5 so the span remains the same (although I would change it as well without using br) and both the image and the caption are wrapped under the HTML5 figure tag.
<a href="#">
<span class="text">Hover text</span>
<figure>
<img src="#" alt="foo" width=500 height=400>
<figcaption>
Text underneath
</figcaption>
</figure>
</a>
Why not simply:
.text { display: none; }
.text:hover { display: block }
What I have is a standard form in HTML that allows the user to select a "Width" option and a "Height" option (each with values ranging from 1 to 10). When they send the form, it sends it to a PHP/HTML page where PHP grabs the "Width" and "Height" variables and assigns it to a width and height of a DIV.
But what I'm trying to do is just use the "Width" and "Height" variables to assign an aspect ratio to that DIV, and then have that DIV auto-resize to 100% of the container it is inside, but while keeping that same aspect ratio.
Example:
User selects a Width of 4 and a Height of 2, then sends the form. On the receiving PHP page, that DIV (the one receiving the width and height ratios) is inside a container that's 1000px width and 600px height. So now, that DIV resizes to 1000px wide and 500px tall (that would be the aspect ratio of 4 to 2)
Any ideas, codes, scripts would be extremely helpful, thank you very much!
Aaron
Since percentage values of the padding-* properties are calculated with respect to the width of the generated box's containing block, you could:
Add a dummy element with no content but with a percentage in a vertical padding (padding-top or padding-bottom), corresponding to the desired aspect ratio.
Use absolutely positioning to remove all contents from the normal flow of the element, in order to prevent them from increasing the height. Then, make it grow to fill the container.
This idea is taken from http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio
#container {
position: relative;
width: 50%;
}
#dummy {
padding-top: 75%; /* 4:3 aspect ratio */
}
#element {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: silver;
}
<div id="container">
<div id="dummy"></div>
<div id="element">
some text
</div>
</div>
Note vertical margin could be used instead of vertical padding, but then there would be margin collapse. To prevent it, add
#container {
display: inline-block;
}
#container {
display: inline-block;
position: relative;
width: 50%;
}
#dummy {
margin-top: 75%; /* 4:3 aspect ratio */
}
#element {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: silver;
}
<div id="container">
<div id="dummy"></div>
<div id="element">
some text
</div>
</div>
Using ::before pseudo element, there's no need to use a dummy element:
#container:before {
padding-top: 75%; /* 4:3 aspect ratio */
content: ''; /* Enable the pseudo-element */
display: block;
}
#container {
position: relative;
width: 50%;
}
#container:before {
padding-top: 75%; /* 4:3 aspect ratio */
content: ''; /* Enable the pseudo-element */
display: block;
}
#element {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: silver;
}
<div id="container">
<div id="element">
some text
</div>
</div>
You could take advantage of the fact that replaces elements may have an intrinsic aspect ratio.
According to the spec,
Otherwise, if 'height' has a computed value of 'auto', and the element
has an intrinsic ratio then the used value of 'height' is:
(used width) / (intrinsic ratio)
Therefore, you could
Create a replaced element with the desired intrinsic ratio, and then set width:100% to it.
Use absolutely positioning to remove all contents from the normal flow of the element, in order to prevent them from increasing the height. Then, make it grow to fill the container.
Then, the container container will have the aspect ratio that you want.
The replaced element could be an image. You could create images of the desired aspect ratio in PHP, or using a third party web service like http://placehold.it/
In the following snippet, I use a 2px width and 1px height image ():
.container {
border: 3px solid blue;
position: relative;
}
.container > img {
width: 100%;
display: block;
visibility: hidden;
}
.container > .content {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: auto;
}
<div class="container">
<img src="http://i.stack.imgur.com/Lfmr6.png" />
<div class="content">
<p>01</p><p>02</p><p>03</p><p>04</p><p>05</p>
<p>06</p><p>07</p><p>08</p><p>09</p><p>10</p>
<p>11</p><p>12</p><p>13</p><p>14</p><p>15</p>
<p>16</p><p>17</p><p>18</p><p>19</p><p>20</p>
</div>
</div>
You can also use a <canvas> element instead of an image. This way you don't need to create images, but it doesn't work on old browsers (like IE 8 and earlier):
<div class="container">
<canvas height="1" width="2"></canvas>
<div class="content">...</div>
</div>
.container {
border: 3px solid blue;
position: relative;
}
.container > canvas {
width: 100%;
display: block;
visibility: hidden;
}
.container > .content {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: auto;
}
<div class="container">
<canvas height="1" width="2"></canvas>
<div class="content">
<p>01</p><p>02</p><p>03</p><p>04</p><p>05</p>
<p>06</p><p>07</p><p>08</p><p>09</p><p>10</p>
<p>11</p><p>12</p><p>13</p><p>14</p><p>15</p>
<p>16</p><p>17</p><p>18</p><p>19</p><p>20</p>
</div>
</div>
So i have this problem. I want to center my flyout but here is the catch. I do not know what the size of the picture will be since it is a picture uploaded by a user. I also don't what the picture disappearing if i make the screen smaller. I tried to set position to be relative but then it pushes my images / texts behind the flyout down.
<div id="imageFlyout<?=$step['order']+1?>" class="popUpWrapper" style="display:none;position:absolute;top:100px;left:<script type="text/JavaScript">
int w = screen.width;
<?php $tempSize=getimagesize("guidebook_images/".$step['attachment']); if($tempSize[0] > 935){?>w/2<?php }else{?>w-<?php echo($tempSize[0]/2);}?></script>px;">
Centering in HTML is an easy two step process:
Give the parent:
text-align:center;
Give the element:
margin:auto;
Demo: http://jsfiddle.net/uriahjamesgd_73/kNFGj/22/
I used the CSS values VW (viewer width) & VH (viewer height) to specify that the flyout be a percentage of whatever the viewport is at a given instance. Hopefully this allows resizing of the viewport in mobile devices.
<!-- HTML -->
<div class="wrap">
<div class="product">
<span class="flyOut"></span>
</div>
</div>
/* CSS */
body { margin: 50px; }
.wrap { position: relative; }
.product { background-color: #555; position: relative; width: 100px; height: 75px; }
span.flyOut { display: none; background-color: #ddd; position: absolute; width: 50vw; height: 37.5vh; left: 100%; }
.product:hover > span.flyOut { display: inline-block; }
I want to know how to show a zoom button over an image in html when mouse hovers over it.
till now i have tried this
<img src="images/zoom.jpg" width="40" height="40" border="0" style="background:URL(http://news_image/<?php echo $getrs['image']; ?>) ;" />
But here the main problem is that how to set size of the background image and how to show the zoom.jpg when only mouse hovers it otherwise not. Also how to place the zoom.jpg in the lower right hand side of the background image when mouse hovers the background image.
I had asked this question before but i was not specific at that time but now i had tried to be specific.
Please help me in this matter.
Thanks
Somdeb
Consider this simple, clean and elegant example using minimal markup:
HTML:
<a href="#" class="zoom">
<span></span>
<img src="/path/to/image.jpg" />
</a>
CSS:
.zoom {
border: 5px solid #000;
display: inline-block;
position: relative;
}
.zoom span {
background: url(http://i.imgur.com/T7yFo.png) no-repeat;
bottom: 0;
display: block;
height: 20px;
position: absolute;
right: 0;
width: 20px;
}
img {
height: auto;
max-width: 100%;
}
If you'd rather only show the magnifying glass on :hover, change the CSS to reflect:
.zoom span {
...
display: none;
...
}
.zoom:hover span {
display: block;
right: center;
top: center;
}
This will place the zoom image in the middle of the image on :hover.
As an added bonus, you can change the mouse cursor to a custom image (e.g. a magnifying glass), further suggesting to the user that the image can be enlarged.
.zoom img:hover {
cursor: url(http://i.imgur.com/T7yFo.png), -moz-zoom-in;
}
This should do the trick:
<style>
a.image {
display: block; /* So that you can set a size. */
width: 100px;
height: 100px;
} a.image div.zoom {
display: none;
width: 100px;
height: 100px;
background-image: url(URL_TO_ZOOM_PICTURE);
background-repeat: no-repeat;
background-position: center center;
} a.image:hover div.zoom {
display: block;
}
</style>
<a class="image" href="<?php echo $getrs['image']; ?>"
style="background:URL(http://news_image/<?php echo $getrs['image']; ?>);">
<div class=".zoom"><!-- --></div>
</a>
The a tag holds the URL and the image. The zoom button is placed within the tag, and I have left it as a simple empty div tag which holds the image. Once the a tag gets hovered over, the tag will appear showing the image. The best about using this is that the zoom button can be transparent, and be placed simply in the middle of the image, and you don't have to worry about any JavaScript.
CSS:
img {
transition: -webkit-transform 0.25s ease;
transition: transform 0.25s ease;
}
img:active {
-webkit-transform: scale(2);
transform: scale(2);
}
This is correct in CSS http://jsfiddle.net/8c7Vn/301/ || UP
also this CSS Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.pic{
width:50px;
height:50px;
}
.picbig{
position: absolute;
width:0px;
-webkit-transition:width 0.3s linear 0s;
transition:width 0.3s linear 0s;
z-index:10;
}
.pic:hover + .picbig{
width:200px;
}
</style>
</head>
<body>
<img class="pic" src="adam_khoury.jpg" alt="Adam">
<img class="picbig" src="adam_khoury.jpg" alt="Adam">
<img class="pic" src="heart.png" alt="heart">
<img class="picbig" src="heart.png" alt="heart">
<img class="pic" src="hardhat.jpg" alt="hardhat">
<img class="picbig" src="hardhat.jpg" alt="hardhat">
</body>
</html>
Edit: Just realized you don't want to resize the image on the page.
You will probably want something like:
<a class="ImageZoom" href="news_image/<?php echo $getrs['image']; ?>">
<img src="yourimage.ext" height="40" width="40" />
<div class="Zoom"><img src="images/zoom.jpg" /></div>
</a>
<style>
.ImageZoom{
display:block;
position:relative;
}
.ImageZoom:hover .Zoom {
display:block;
}
.Zoom {
display:none;
position:absolute
bottom:0;
right:0;
}
</style>
I want to center an image in an area, without resizing... I am using HTML.
Example:
I have an image <img src='img1.png' width='64' height='64'> - the image is actually 64x64. It displays perfectly.
Now, I have another image <img src='img2.png' width='64' height='64'> however, the image is not as big as it should be, its 32x32 - what happens here is it resizes the image to 64x64 and makes it look like $%^&.
How do I make images smaller then the desired width and height centered in the 'img' area without any resizing what so ever?
What you will need is something like this:
<div class="box">
<img src="whatever size image you'd like" />
</div>
And for the styling (in an external stylesheet, natch) you'd apply:
/* Image centering */
div.box {
border: 1px black solid;
height: 64px;
width: 64px;
background: #444;
display: table-cell;
vertical-align: middle;
}
.box img {
display:block;
margin: 0px auto;
}
This works for images with dimensions <= 64x64px, and is easily modifiable to work with larger pics. The key elements here are
set dimensions on the div
display as a table-cell (allows vertical align)
vertical align (aligns on the Y-axis w/out weird hacks)
display:block on the img element
margin: auto centers the image laterally
Solution without IE-unfriendly display:table-cell:
<!DOCTYPE html>
<style>
div {
line-height:64px; /* that's the secret sauce */
text-align:center;
width:64px; height:64px;
}
img {vertical-align:middle}
</style>
<div><img …></div>
You could try putting the image inside a DIV that is 64x64 and not specifying the image dimensions. Then you could style the div so its contents are centered and any overflow is hidden.
You can dynamically get an image size using the getimagesize() php function:
<?php
$size = getimagesize('imgX.png');
$height = $size[1];
$width = $size[0];
?>
<div style="text-align: center">
<img src="imgX.png" width="<?php print($width) ?>" height="<?php print($height) ?>" />
</div>
I've had to do something similar with 36x36 images. Users were able to upload any size but the thumbnails were only to show the center 36 square pixels.
Markup:
<li><div><span></span>
<img src="_media/objects/jessica-bowman.png" alt="Jessica Bowman" /></div>
<p>Jessica Bowman</p>
</li>
The span was just there to get rounded corners on the image, it's not necessarily needed.
CSS:
ul.recent-list li div {
position: relative;
float: left;
width: 36px;
height: 36px;
overflow: hidden;
}
ul.recent-list li div span {
position: relative;
z-index: 100;
display: block;
width: 36px;
height: 36px;
background: url("../_media/icons/icon-overlay.png") top left no-repeat;
}
ul.recent-list li div img {
position: relative;
top: -36px;
z-index: 0;
float: left;
}
JavaScript:
$(window).load(function() {
$("ul.recent-list div img").each(function() {
var moveX = ($(this).width() / 2 * -1) + 18;
var moveY = ($(this).height() / 2) * -1 - 18; // 18 is 1/2 the default offset of 36px defined in CSS
$(this).css({'top' : moveY, 'left' : moveX});
});
});
The solution is a simple bit of CSS + HMTL
<img src="transparentpixel.gif"
width="64"
height="64"
style="
background-image:url('path/to/image.jpg');
background-repeat:no-repeat;
background-position:center center;
" />
the transparentpixel.gif is a simple 1x1px transparent gif image
An img tag with width and height attributes is saying "stretch or shrink the image to this size regardless of its actual size". use something like:
<div style="text-align:center;">
<img src="x.jpg">
</div>
and no i don't know why text-align would work, but it appears to in my experience.
Use CSS to render the image using background:
<div style="background: url(img1.png) no-repeat center center; height: 64px; width: 64px;"></div>
This will show the image in the center, without scaling it.