Re: How to center a list when display:block?




SM wrote:

I have a list (<ul>) that contains images... sort of a thumbnail. I
want the images to display in center.

Here's a sample of my code:

In the future, post a URL instead. It's a lot easier for us to work with
than code snippets, plus snippets often do not provide all the necessary
info.

<ul class="nav_cd_imgs">
<li><a href="#"><img src="images/1.jpg" /></a></li>
<li><a href="#"><img src="images/2.jpg" /></a></li>
<li><a href="#"><img src="images/3.jpg" /></a></li>
</ul>

Simple, really. Don't float anything, or use display:block. That will
make those elements left-aligned. Just set text-align:center on the <ul>
and make the li's inline.

ul.nav_cd_imgs {
text-align: center;
list-style: none;
}
ul.nav_cd_imgs li {
display: inline;
}

Set margins and padding to taste on the ul, li and img as needed.

--
Berg
.



Relevant Pages

  • Re: E-mail Security
    ... It display an inline preview for simply image attachments. ... involve any HTML. ... No images are rendered. ...
    (alt.computer.security)
  • Re: Image stacking
    ... Just put the slices in a table. ... The gaps are because img is display: inline and so sits on the text ... just set display: block on the images. ... this works nicely for where there is no inline text involved. ...
    (alt.html)
  • Re: A div in text flow
    ... The suggestion has more problems than I care to list down, like the use of alt="" for images that are a link. ... side-by-side images in an a tag. ... Because the designers of HTML wanted to make the p element correspond to the concept of text paragraph that contains only text and, in less common cases, other inline elements. ... If display: inline-block worked in WWW terms, you could of course use instead of there. ...
    (comp.infosystems.www.authoring.html)
  • Re: Images in a combobox
    ... the code snippets were very helpful. ... now I can display the images in combobox correctly. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regarding VM
    ... It tries to display the images inline. ... and decide whether I want an inline display or an external program ...
    (comp.emacs.xemacs)