0

I am trying to align some text in the middle of an image, and I've tried a few different ways of vertical-align, but I can't seem to get it to work.

Currently, layout looks so: Current layout

and the HTML/CSS used for this is:

<p id="searchresults">Search Results</p>
 <ul id="posted_results">
 <?php
 foreach($search_result['movies'] as $sr){
 echo '<li class="search_item"><a href="/ug10/cs10aer/screening/movie.php?title=' . $sr['title'] . '" alt="' . $sr['title'] . ' (' . $sr['year'] . ')"><img src="' . $sr['posters']['thumbnail'] . '" title="' . $sr['title'] . ' poster" alt="' . $sr['title'] . ' poster" /></a><a href="/ug10/cs10aer/screening/movie.php?title=' . $sr['title'] . '" alt="' . $sr['title'] . ' (' . $sr['year'] . ')">' . $sr['title'] . ' (' . $sr['year'] . ')</a></li>';
 }
 ?>
 </ul>

Current CSS

UPDATE Just for further guidance, I'm wanting to get the text for each list object to display thus: Wanted layout

UPDATE 2 As requested, here's the HTML code as seen by Firefox:

<div id="content">
 <p id="searchresults">Search Results</p>
 <ul id="posted_results">
 <li class="search_item"><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode III - Revenge of the Sith 3D" alt="Star Wars: Episode III - Revenge of the Sith 3D (2005)"><img src="http://content8.flixster.com/movie/10/94/47/10944718_mob.jpg" title="Star Wars: Episode III - Revenge of the Sith 3D poster" alt="Star Wars: Episode III - Revenge of the Sith 3D poster" /></a><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode III - Revenge of the Sith 3D" alt="Star Wars: Episode III - Revenge of the Sith 3D (2005)">Star Wars: Episode III - Revenge of the Sith 3D (2005)</a></li>
 <li class="search_item"><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode II - Attack of the Clones 3D" alt="Star Wars: Episode II - Attack of the Clones 3D (2002)"><img src="http://content7.flixster.com/movie/10/94/47/10944721_mob.jpg" title="Star Wars: Episode II - Attack of the Clones 3D poster" alt="Star Wars: Episode II - Attack of the Clones 3D poster" /></a><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode II - Attack of the Clones 3D" alt="Star Wars: Episode II - Attack of the Clones 3D (2002)">Star Wars: Episode II - Attack of the Clones 3D (2002)</a></li>
 <li class="search_item"><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode IV - A New Hope" alt="Star Wars: Episode IV - A New Hope (1977)"><img src="http://content9.flixster.com/movie/10/94/47/10944715_mob.jpg" title="Star Wars: Episode IV - A New Hope poster" alt="Star Wars: Episode IV - A New Hope poster" /></a><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode IV - A New Hope" alt="Star Wars: Episode IV - A New Hope (1977)">Star Wars: Episode IV - A New Hope (1977)</a></li>
 <li class="search_item"><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode VI - Return of the Jedi" alt="Star Wars: Episode VI - Return of the Jedi (1983)"><img src="http://content7.flixster.com/movie/10/94/47/10944709_mob.jpg" title="Star Wars: Episode VI - Return of the Jedi poster" alt="Star Wars: Episode VI - Return of the Jedi poster" /></a><a href="/ug10/cs10aer/screening/movie.php?title=Star Wars: Episode VI - Return of the Jedi" alt="Star Wars: Episode VI - Return of the Jedi (1983)">Star Wars: Episode VI - Return of the Jedi (1983)</a></li>
 </ul>
 </div>
asked Dec 8, 2012 at 18:44
6
  • how you want ?? could you show image Commented Dec 8, 2012 at 18:45
  • 1
    could you provide us with a link? Commented Dec 8, 2012 at 18:47
  • I've just added an image at the bottom of the post showing what I'm trying to achieve. Commented Dec 8, 2012 at 18:58
  • Please provide the HTML, not the php code. We need to see what the browser sees, not what the server sees. Commented Dec 8, 2012 at 19:00
  • @ChrisHerbert I've added the HTML code at the bottom of the post. The contents of the ul, including the li, img, href, title and alt tags are all being generated dynamically from the PHP foreach from $search_results array. Commented Dec 8, 2012 at 19:08

3 Answers 3

1

Remove the float from the image and use vertical-align:

.search_item img {
 vertical-align: middle; 
 margin-right: 30px;
}

http://jsfiddle.net/tNhyj/

answered Dec 8, 2012 at 19:17
Sign up to request clarification or add additional context in comments.

Comments

0

You may add vertical-align:middle to the image.

li img {
 vertical-align:middle;
padding-right:10px; 
}

Check this jsfiddle to see if it is what you want. http://jsfiddle.net/3ETDj/

For me it is working in Firefox, IE8, Chrome and Opera.

answered Dec 8, 2012 at 19:17

Comments

0

if the image is always the same height + descriptions lenght is always gonna be similar, you could hack it with line-height or/and margin-top, or using vertical-align on image eample using vertical-align can be found here: https://stackoverflow.com/a/13780959/1134615

simple fiddle using line height:

http://jsfiddle.net/BrFga/

html

 <ul>
 <li>
 <img src=""/> 
 <p>Sample text</p>
 </li>
 </ul>​

css

ul {
 height: 120px;
 width: 600px;
 outline: red 1px solid; 
}
img {
 height: 120px;
 width: 120px;
 float: left;
}
p {
 height: 120px;
 line-height: 120px;
}

answered Dec 8, 2012 at 19:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.