Put a title property on image gallery - css

I need to create an image gallery as shown below. It's working fine but I need to put a title below the image (each and every image has a title). When I have tried like below - that title is not showing correctly. Can you show me how to do that?
Html
<ul id="thumbnailsList">
<li *ngFor="let image of datasource">
<img src="{{image.url}}" class="tn" data-toggle="modal" data-target="#selectedImageModal" (click)=setSelectedImage(image)>
<div class="myClass"><strong>{{image.title}}</strong></div>
</li>
</ul>
css
.myClass {
position: absolute;
}
Result :
Update :
When I removed the .myClass it shows like below.But I need to show images horizontally and text bottom of the image.

To make it work using position:absolute, you need to give a parent container a position property doing:
#thumbnailsList li
position: relative

I have done it using Bootstrap responsive design.
HTML
<div class="row">
<div *ngFor="let image of dataCollection" class="col-md-3 col-sm-4 col-xs-6">
<img class="img-responsive tn" src="{{image.blobFileUrl}}" data-toggle="modal" data-target="#selectedImageModal" (click)=setSelectedImage(image) />
<div class="desc">{{image.name}}</div>
</div>
</div>
CSS
div.desc {
padding: 15px;
text-align: center;
}
.tn {
margin: 2px 0px;
box-shadow: #999 1px 1px 3px 1px;
cursor: pointer;
width: 100% !important;
height: 200px !important;
}

Related

background image is not displayed

this is my html code inside the page
<style type="text/css">
.container{width:100%;}
.left{float:left;}
.right{float:right;}
.center{margin:0 auto;}
</style>
<ul class="invite container" >
<li class="container">
<span class="left">
<img src="images/main-bride.jpg" height="200px" />
</span>
<span class="frame right">
<img src="images/main-groom.jpg" height="200px" />
</span>
<!-- <span class="center" background="images/frame.png"> hello</span> -->
</li>
<!-- <li class="right">
<span class="frame"><img src="images/main-groom.jpg" height="200px" /></span>
</li> -->
</ul>
and this is the css code:
.frame {
display: block;
line-height: 0px;
background: url(../images/frame.png) no-repeat center center;
}
.frame img {border: 10px solid #fff;}
everything else is working is find but only the background image is not visible. any thing that I'm missing? plz help.
IF Your background should be 10px around the image, than the white border of the image and the image is hiding it.
Try to add:
.frame {display: block; padding: 10px; background-repeat: repeat;}
.frame img {border: 0px;}
And check if the background is visible "around" the image. Remember that frame.png can be small and still hidden under the image. You must be carefull to adjust all the sizes correct.
Few words of explanation: In that case, You are setting padding on the parent element, so there will be 10px space from each side of the image. In that case 10px frame will be seen from the .frame element, and the image will cover the center of it.
If You want the background to overwrite the image, use:
.frame img {display: none;}
.frame {display: block; height: ...px; width: ...px;}
Why downvote? It would be nice to write something, thx.
is that css for the background in a file one level up from the index page or inline on the index page ? your css for the background url says
background: url(../images/frame.png) no-repeat center center;
background: url(.. go up one level
/images/ down into images folder
frame.png find the file called frame.png
) no-repeat center center;
check your paths.

Div not properly wrapping around contents (image) - Includes margin, possible float/Bootstrap issues

How to size/wrap a div container around an image inside It? Where float: right and margin-left: auto are potentially causing issues.
I'm struggling to get a div to be sized by wrapping properly around the image inside it. Please have a look at the example I'm referring to here:
Link to Example
(Might be worth playing around with the window size to help explain my problem)
I'm practicing with Bootstrap for the first time. The red blocks on each side are grid blocks 1 and 12, with the blue, and green sections filling the remaining 10. The big orange rectangles are responsive images that I want to be kept central spaced 20px apart at all times.
Using Chrome's "Inspect Element" (or similar) - If you inspect the orange rectangle on the right hand side, and have a look at the container div (class="container-img-r") - This div is wrapping around the orange image exactly how I wanted (albeit including the invisible border). But I'm not having much luck achieving the same result with the div container for the orange image on the left side (it still fills the blue parent element)
I've played around with different options for float/margins/position but can't seem to crack it.
Here's the CSS I have for the relevent content:
.container-img-l {
/* float:right; ??? Nothing I tried here seemed to make a difference */
}
.container-img-r {
float:left;
}
.item-pos-l {
margin-left:auto;
border-right:10px solid transparent; /* Margins just collapsed when resizing window */
height:323px;
width:510px;
}
.item-pos-r {
float:left;
border-left:10px solid transparent;
height:323px;
width:510px;
}
The reason for me wanting the div to accurately wrap around the responsive images is that I want to overlay some more CSS content over the images, scaling/re-positioning automatically as the window/device size changes (Click here and you'll clearly see where I'm hoping to implement this responsive style).
Maybe there are clashes with the Bootstrap CSS at play but I'm out of ideas.
Your first link doesn't remotely look like the html you want to make responsive. It would be best to learn responsive and fluid (no pixels heights or widths if possible) css before attempting to modify a framework you are unfamiliar with. Also, you have an error in your html - validate it to make sure you've closed all your elements. Also indent and comment all your code and avoid the use of inline styles.
Demo: http://jsbin.com/wazanu/2/
http://jsbin.com/wazanu/2/edit -- edit link
CSS:
body {background:#eee}
.header {padding:20px;}
.portfolio-grid .col-sm-6 {
margin-bottom: 30px
}
.img-wrapper .title {
text-align:center;
}
#media (min-width:768px) {
.img-wrapper {
position: relative;
overflow: hidden;
}
.img-wrapper img {width:100%;}
.img-wrapper .title {
position: absolute;
text-align:left;
bottom: -90px;
padding: 0 20px 20px 20px;
height: 150px;
background: red;
transition: all .5s ease-in-out;
}
.img-wrapper .title h3 {
margin: 0;
height: 60px;
line-height: 60px;
}
.img-wrapper:hover .title {
bottom: 0
}
}
HTML:
<header class="header text-center">
My header
</header>
<div class="container">
<div class="row portfolio-grid">
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placekitten.com/g/400/300" class="img-responsive center-block" alt="">
<div class="title">
<h3>Title of Project</h3>
<p>Content about project goes here</p>
</div>
</div>
</div>
<!--/.col-sm-6 -->
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placebear.com/g/400/300" class="img-responsive center-block" alt="">
</div>
</div>
<!--/.col-sm-6 -->
<div class="clearfix visible-sm"></div>
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placekitten.com/g/400/300" class="img-responsive center-block" alt="">
</div>
</div>
<!--/.col-sm-6 -->
<div class="col-sm-6">
<div class="img-wrapper">
<img src="http://placekitten.com/g/400/300" class="img-responsive center-block" alt="">
</div>
</div>
<!--/.col-sm-6 -->
</div>
<!--/.row-->
</div>
<!--/.container-->

Making a div with an image + header + P inside all linkable without javascript

I'm trying to get a div that when hovered shows a hidden h2 + P (using CSS), and i want the entire div (including h2 + p) to be linkable to X.
The only way so far i've managed to make it work is by making the A wrap everything, but this is of course only HTML5 valid, so some browsers (IE) will not like it.
<a href="#">
<div class="one">
<img src="#">
<p>one</p>
</div>
</a>
I also can't give each block a separate <a> as I want to change the color on hover, so the whole div needs to be hoverable. And even if i went that way, surely giving a post excerpt (the <P>) would surely be bad for seo?
Essentially this is what I want the final result to be:
<div class="one">
<img src"#">
<p>test</p>
</div>
and on one:hover, to have the entire div be a link (href="#").
There must be a way to do this!
Wrap both the link and content within a DIV:
<div class="wrapper">
<div class="one">
<img src="#">
<p>one</p>
</div>
</div>
Make it relative, and then put a transparent link on top that spans across the entire content area:
.wrapper a{
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 5;
background: transparent;
}
.wrapper a:hover{
border: 1px solid #d33;
}
.wrapper{
position: relative;
border: 1px solid #ccc;
}
Kind of ugly, but I don't see any other alternatives without js :)

Add an Image on top of another image

The UI of my page currently shows an Image in backgroud and text on left hand top corner of the page. Following is the code I am using for the image.
<div>
<div style= "z-index: 1; position: absolute; text-align: left; border: 1px solid black;">
<img src="slide1.jpg" alt="alt text" style="height:220px;width:500px;border-width:0px;" />
</div>
<div id="curtain" style="z-index: 2; position: absolute; padding-left: 10px;">
<div style="background-color: transparent; font-weight: bold; font-size: 1.8em; padding-top: 5px;">
Profile
</div>
<div style="font-size: 1em; width: 215px; color: #cccccc;">
He is a good citizen and a great teacher.
</div>
</div>
</div>
I want to add 2 small icons aligned vertically on the right hand side of this image.
Can someone help me with the css ?
Something like this?
http://jsfiddle.net/7KTEQ/
Just add <div id="smallImages"><img src='ONE' /> <img src='two' /></div> inside second div
and css for it is:
#smallImages {
position:absolute;
margin-left:400px;
}​
change margin-left for css depending on second div width and image sizes..

How to layout a image gallery?

I am making an image gallery, and I need to display images in a grid like layout. I don't want to use any frameworks, and would prefer to do things from scratch. Also, I would prefer not to use tables for the layout, since it will be a pain to add images to the table dynamically.
The layout consists of divs, like:
<div id="gallery">
<div class="uPic">
<img src="1.png">
<p> description </p>
</div>
<div class="uPic">
<img src="2.png">
<p> description </p>
</div>
....
......
....
</div>
to achieve the grid look, I simply "float"-ed all .uPics to left....and given some padding and margin to the #gallery. So far everything works great.
The PROBLEM starts, when I try to give a hover effect to the images. initially the <p> is hidden, and I use jQuery to show it on hover. but on doing so, the images below the one I am hovering over, shifts towards the right instead of moving down. Any ideas?
If the height of your divs is variable then I would recommend either using clear:both on the first element of each new row OR putting each row in its own container div. Otherwise, as you've noticed, the divs under the selected one will probably be pushed to the side of the higher div instead of shifting down.
I'd also consider Matt's solution as divs moving around on mouseover imho gives a very chaotic look to a page.
But if you're set on doing it this way, check out this example:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$('#gallery .image p').hide();
$('#gallery .image').hover(
function() { $(this).find('p').show() },
function() { $(this).find('p').hide() }
);
});
</script>
<style>
#gallery {
width: 800px;
}
#gallery .image {
width: 200px;
float: left;
background: #eee;
margin-bottom: 10px;
}
#gallery .image.newline {
clear: both;
}
#gallery .image .placeholder {
width: 180px;
height: 200px;
margin: 10px;
background: #ccf;
}
#gallery .image p {
margin: 10px;
background: #fcc;
}
</style>
</head>
<body>
<div id="gallery">
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<!-- NOTE the added "newline" class where the new line starts! -->
<div class="image newline">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
</div>
</body>
</html>
The w3schools has a sample image gallery all in CSS. They add a border on hover of the image.
I would maybe set the width and height of the paragraph, and fix it using absolute positioning relative to the enclosing uPic div. That way you can have the paragraph of description appear "above" the image on hover without disturbing the flow. So, add position: relative; to the uPic, add something along the lines of position: absolute; left: 0px; top: 0px; to the <p>, and then adjust other things to suit.
I suggest that you choose a fixed height and width for your div :
It may fix your problem
It is not convenient for the user when a whole part of the grid is moving just to show up a little description, whether it is downward or to the right
I think this may be helpful
<style type="text/css" ><!--
#gallery_box{
width:728px;
height:545px;
border:solid #cccccc 1px;
margin:20px auto 0px;
padding:5px;
-moz-box-shadow:0px 18px 40px #ccc;
-webkit-box-shadow:0px 14px 40px
#ccc;
box-shadow:0px 5px 30px #ccc;
}
#thumbnail{
width:160px;
height:160px;
background:#f6f6f6;
border:solid #cccccc 1px;
border:solid #cccccc 1px;
margin:5px;
padding:5px;
float:left;
text-align:center;
position: relative;
line-height: 156px;
-moz-box-shadow:4px 4px 4px
#ccc;n-webkit-box-shadow:4px 4px 4px #ccc; box-shadow: 4px 4px 4px #ccc; } img {
border:none;
-moz-box-shadow:0px 8px 10px #ccc;
-webkit-box-shadow:0px 8px 10px #ccc; box-shadow: 0px 8px 10px #ccc; }
a{
color:#0066FF; text-decoration:none;
} a:hover{
color:#0099FF; }
--></style><pre>
<div id="gallery_box" >
<div id="thumbnail">
<a href="" ></a>
</div>
</div>

Resources