Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

Dynamic images with filename as caption displayed inline

This will hopefully be easy for someone who knows CSS better than I do.

I'm loading all of the pictures in a folder to an update panel dynamically.
I want to add the name of the image directly below the image.
These should display inline.

When the image/filenames exceed the width available, I want them to wrap and create a new row of image/filenames.

In other words, display the image as it would typically display, but put the corresponding filename under each image.

I thought this would be as easy as:

.div1 {
display:inline;
}

.div2{
text-align:center;
width:80;
}

<div1>
<div2>(pic) <br/> (name)</div> <div2>(pic) <br/> (name)</div>...etc
</div>

but that isn't working.

CSS is my ultimate time killer. Can anyone tell me what I'm doing wrong?

This is for an intranet application where users will be on IE 7 (I know), but i'm interested in cross browser friendly solutions.

Thanks everyone... I'm two days in and running out of ways to Google my problem.
0
Jared_S
Asked:
Jared_S
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
Kyle HamiltonData ScientistCommented:
html:
<div class="imagesContainer">
<div class="image"><img src="image.png"/><br/>image name</div>
<div class="image"><img src="image.png"/><br/>image name</div>
<div class="image"><img src="image.png"/><br/>image name</div>
...etc..
</div>

Open in new window


css:
.imagesContainer{
   overflow:hidden;
}
.image{
   float:left;
}

Open in new window


that's the layout part of it. after that,you can style it any way you like...
0
 
Scott Fell, EE MVEDeveloperCommented:
I would add to @kozaiwaniec and instead of the br tags use a span for text and update a little style
.imagesContainer{
   overflow:hidden;
   padding:10px;
}
.image{
   float:left;
   margin-right:5px;
   margin-left:5px;
   margin-bottom:10px;
}

.image img{
   text-align:center;
   width:100px;
}

.image span{
   display:block;
   text-align:center;
   padding:10px;
}

Open in new window


But I would also check out the masonry project https://github.com/desandro/masonry it  will give you the "pintrest" look with a little javascript.  The key is the margins on left and right can always be equal.   Using above code you if you knew the image width and hight are always going to be the same specific sizes, and you only allowed the container to be a specific size, you can get the similar effect without javascript.  I have used masonry and it is very easy.
0
 
COBOLdinosaurCommented:
It is unfortunate that you are committed to obsolete browsers and can't use the very straight forward and simple solution of the new html5 tags.

If you ever decide to move to modern development, these captioning techniques become available.

Cd&
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Scott Fell, EE MVEDeveloperCommented:
I don't particularly like <div class="image"><img src="image.png"/><br/>image name</div>  because of the br tag and prefer <div class="image"><img src="image.png"/><span>image name</span></div>.   This works perfectly fine in all browsers.  Cd brings up a good point about remembering to use html5.  While you personally may prefer "modern" browsers, there are probably still 15% to 20% or more of your viewers on  ie8 and below where this may not work without using a fall back or add on.

I saw Cd's sample but would suggest using css rather then inline css
css
figure {
  float:left;
  text-align: center;
  width:130px;
  background-color:#423189;
  padding-top:10px;
  margin:15px;
}
img{
  display: inline;
 
  background-color:#fff;
  
}
figcaption {
  text-align:center;
  font-weight:bold;
  font-style:oblique;
  
}

Open in new window

 <figure>
  
   <img src="image.png" width="100px" height="100px"/>
    <figcaption>
    This is a caption
   </figcaption>
</figure>
  
   <figure>
  
   <img src="image.png" width="100px" height="100px"/>
    <figcaption>
    This is a caption
   </figcaption>
</figure>
  
   <figure>
  
   <img src="image.png" width="100px" height="100px"/>
    <figcaption>
    This is a caption
   </figcaption>
</figure>
  
   <figure>
  
   <img src="image.png" width="100px" height="100px"/>
    <figcaption>
    This is a caption
   </figcaption>
</figure>
  
   <figure>
  
   <img src="image.png" width="100px" height="100px"/>
    <figcaption>
    This is a caption
   </figcaption>
</figure>

Open in new window


I left out the code I would have used that goes with my original css post.  Very similar to the html5 version and very valid.

<div class="imagesContainer">
<div class="image"><img src="image.png"/><span>image name</span></div>
<div class="image"><img src="image.png"/><span>image name</span></div>
<div class="image"><img src="image.png"/><span>image name</span></div>
<div class="image"><img src="image.png"/><span>image name</span></div>

</div>

Open in new window

0
 
Kyle HamiltonData ScientistCommented:
Like I said in my original post, you can style this layout to your heart's content, whether you use spans, divs, figures, or the "cat in the hat" ('cause you can do that in html5).

But the layout remains.
0
 
Jared_SAuthor Commented:
I learned something from all of the posts, but utilized these the most.
Thanks everyone.
0
 
COBOLdinosaurCommented:
but would suggest using css rather then inline css

Agree! With snippets I sometimes put the code inline to make it easier to follow.

Cd&
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now