tags:

views:

99

answers:

3

Hi all,

I have a problem with alignment of image and content in a list. Here is what my code is:

 <li> 
   <div class="small-view-image">
       <img src="../images/xyz.png" height="41" width="34" alt="Test" title="Test"/>
   </div>
   <div class="small-view-content">
     <a href='../xyz.html'>XYZ</a>
   </div>                        
 </li>

The problem is I cannot use float left to align the image on left and the content on right. alt text

This is the output I am expecting. I cannot use the float:left because, the page is multilingual. Any suggestions or ideas welcome.

A: 
<li>
  <div>img src="../images/xyz.png" height="41" width="34" alt="Test" title="Test"/></div> 
  <a href='../xyz.html'>XYZ</a>

Note you can still apply specific style to the two elements above:

li > div {display:inline-block; width:?px}
li > a { ... }

Edited as per comments.

R. Hill
The prob with this format is, the text is displayed aligned on the right side, but not vertically aligned!
Abdel Olakara
I see, that means your images are not all the same width if I understand properly. In such case, putting the image in a <div> makes sense, although no need to put your <a> in a <div>. As you were told by others, set the 'display' property of the <div> used as a container for your image as 'inline-block', in which case you can control its width in pixel using the 'width' property.
R. Hill
+1  A: 

You could set the li to have position: relative and position the image and text absolutely within it.

dylanfm
+2  A: 

Expanding on dylanfm's answer with a tweak, your CSS would be:

li {
    position: relative;
    min-height: 50px;
}

.small-view-image {
    position: absolute;
    left: 0;
    top: 0;
}

.small-view-content {
    position: relative;
    left: 40px; /* Makes room for the image */
}

This will make sure that you <li> properly pushes down other page elements if the text is taller than the image.

Pat
@Pat, thanks.. but, the problem is when I change direction of the page, the list gets spoiled. I think the only way is to change the CSS and floatings for RTL language.
Abdel Olakara