Solved

float left align bottom

Posted on 2010-09-14
4
218 Views
Last Modified: 2012-06-27
The included code is a simple layout of 3 images lined up left to right across the screen. Each image is a different size and they are vertically aligned to the bottom by default. The problem I am having is when I try to add some text centered below each image, such as a description of the image. The text will break the flow of the images or the images and text will end up being aligned to the top.

I have tried added a line break after the image followed by some text:
<a href="#"><img src="item1.jpg"><br/>Item 1</a>
This will break the flow.

I have tried adding the float directly to the link:
 #item1 {float:left;}
<a id="item1" href="#"><img src="item1.jpg"><br/>Item 1</a>
This works except the 3 images end up aligned to the top.

How can I add a description centered below each image and still keep the flow aligned to the bottom.  The size of the images and the length (number of lines) of the description will vary so I can not use absolute positioning. Please do not answer unless you have tested the results.
<!DOCTYPE HTML>
<head>
<STYLE type="text/css">
   #section1 {}
   #item1 {float:left;}
   #item2 {float:left;}
   #item3 {float:left;}
   .description{}
   .clear{clear:both;}
   
</STYLE>

</head>

<body>

<div id="section1">
<a id="item1" href="#"><img src="http://farm5.static.flickr.com/4152/4990291568_9fd50bed0f_m.jpg"><br/>Item 1</a>
<a id="item2" href="#"><img src="http://farm5.static.flickr.com/4086/4989684949_49fee2bf45_m.jpg"><br/>Item 2</a>
<a id="item3" href="#"><img src="http://farm5.static.flickr.com/4153/4990291660_7f53b3958e_m.jpg"><br/>Item 3</a>
</div>
<div class="clear">&nbsp;</div>

</body>
</html>

Open in new window

<!DOCTYPE HTML>
<head>

<STYLE type="text/css">
   #section1 {float:left;}
   #item1 {}
   #item2 {}
   #item3 {}
   .description{}
   .clear{clear:both;}   
</STYLE>

</head>
<body>

<div id="section1">

<a id="item1" href="#">
<img src="http://farm5.static.flickr.com/4152/4990291568_9fd50bed0f_m.jpg"></a>

<a id="item2" href="#">
<img src="http://farm5.static.flickr.com/4086/4989684949_49fee2bf45_m.jpg"></a>

<a id="item3" href="#">
<img src="http://farm5.static.flickr.com/4153/4990291660_7f53b3958e_m.jpg"></a>

</div>
<div class="clear">&nbsp;</div>

</body>
</html>

Open in new window

0
Comment
Question by:Gary Samuels
  • 3
4 Comments
 
LVL 6

Expert Comment

by:UsamaFoad
ID: 33674252
You can try to add table for the description

<!DOCTYPE HTML>
<head>

<STYLE type="text/css">
   #section1 {float:left;}
   #item1 {}
   #item2 {}
   #item3 {}
   .description{}
   .clear{clear:both;}  
</STYLE>

</head>
<body>

<div id="section1">

<a id="item1" href="#">
<img src="http://farm5.static.flickr.com/4152/4990291568_9fd50bed0f_m.jpg"></a>

<a id="item2" href="#">
<img src="http://farm5.static.flickr.com/4086/4989684949_49fee2bf45_m.jpg"></a>

<a id="item3" href="#">
<img src="http://farm5.static.flickr.com/4153/4990291660_7f53b3958e_m.jpg"></a>

</div>
<div class="clear">
  <table width="100%" border="0">
    <tr>
      <td width="16%"><div align="center">item1</div></td>
      <td width="27%"><div align="center">item2</div></td>
      <td width="31%"><div align="center">item3</div></td>
      <td width="26%"><div align="center"></div></td>
    </tr>
  </table>
</div>

</body>
</html>
0
 
LVL 6

Expert Comment

by:UsamaFoad
ID: 33674272
Sorry for posting the Code as text, Here the code in right format
<!DOCTYPE HTML>

<head>



<STYLE type="text/css">

   #section1 {float:left;}

   #item1 {}

   #item2 {}

   #item3 {}

   .description{}

   .clear{clear:both;}   

</STYLE>



</head>

<body>



<div id="section1">



<a id="item1" href="#">

<img src="http://farm5.static.flickr.com/4152/4990291568_9fd50bed0f_m.jpg"></a>



<a id="item2" href="#">

<img src="http://farm5.static.flickr.com/4086/4989684949_49fee2bf45_m.jpg"></a>



<a id="item3" href="#">

<img src="http://farm5.static.flickr.com/4153/4990291660_7f53b3958e_m.jpg"></a>



</div>

<div class="clear">

  <table width="100%" border="0">

    <tr>

      <td width="16%"><div align="center">item1</div></td>

      <td width="27%"><div align="center">item2</div></td>

      <td width="31%"><div align="center">item3</div></td>

      <td width="26%"><div align="center"></div></td>

    </tr>

  </table>

</div>



</body>

</html>

Open in new window

0
 

Author Comment

by:Gary Samuels
ID: 33676365
Please notice in the above question: " The size of the images and the length (number of lines) of the description will vary".  The images are for example only. The real images will vary in size. There is no way to know the given width of any image so setting table widths in pixel or percent will not work.
0
 
LVL 6

Accepted Solution

by:
UsamaFoad earned 500 total points
ID: 33772005
Ok, I get the point, let us make the table without any spific size.
<!DOCTYPE HTML>

<head>



<STYLE type="text/css">

   #section1 {float:left;}

   #item1 {}

   #item2 {}

   #item3 {}

   .description{}

   .clear{clear:both;}   

</STYLE>



</head>



<body>



<div id="section1" align="center">

    <table width="100%" border="0">

      <tr>

        <td valign="bottom"><div align="center"><a id="item1" href="#"><img src="http://farm5.static.flickr.com/4152/4990291568_9fd50bed0f_m.jpg"><br/>

        Item 1: A smal image with  long description </a></div></td>

        <td valign="bottom"><div align="center"><a id="item2" href="#"><img src="http://farm5.static.flickr.com/4086/4989684949_49fee2bf45_m.jpg"><br/>

        Item 2</a></div></td>

        <td valign="bottom"><div align="center"><a id="item3" href="#"><img src="http://farm5.static.flickr.com/4153/4990291660_7f53b3958e_m.jpg"><br/>

        Item 3</a></div></td>

      </tr>

    </table>

  </div>



</body>

</html>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS grid style change 2 34
Help cleaning out CSS 2 50
Problem to page 4 72
CSS Question 5 38
"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now