Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Images inside Inline list items

Featured Replies

Hi,

 

I'm getting some layout behaviour that I don't quite understand and was wondering if someone could help me out.

 

I've got a bunch of image thumbnails that I'm displaying inside an unordered list. I want the items to be listed inline, aligned to the right. Floating to the right causes the images to appear in reverse order, so I chose to set the li items display to 'inline'.

 

Funny thing is, the li elements don't seem to be sized according to their contained images, and there's a mysterious 3px extra gap underneath.

 

Here's the CSS:

 

.eslidegallery-thumbnails
{
position: relative;
text-align: right;
}

.eslidegallery-thumbnails *
{
	padding: 0;
	margin: 0;		
}

.eslidegallery-thumbnails li
{
	list-style: none;
	display: inline;
}

.eslidegallery-thumbnails img
{
	margin: 5px 0 0 5px;
}

 

and I've attached a FireBug screen grab. Note the highlighted li element and the box model dimensions.

 

The images are all 50px x 50px and as you can see, I've added a top and left margin of 5px.

 

I noticed that even when I was floating the li elements, the 3px gap underneath was still present.

 

Thanks guys!

post-24093-077995700 1290707123_thumb.jpg

I would use float: right instead of display: inline and code the images in the reverse order in the html markup.

 

Another possible problem is that you are trying to apply a margin-top to an inline element, but I think margins should only be applied to block elements which is another reason to use float: right; display: block; (in fact I have been told that the float automatically makes the element block). Read this explanation

http://www.maxdesign.com.au/articles/inline/

 

If you continue to use display: inline, add line-height to equal the image height for the li style and the img style and delete the margins and see if that helps.

Try display:inline-block; -- best of both worlds! and float the ul not the list elements.

 

Oh and if you need to support IE6 and 7 then you'll need to add:

 

li {
display:inline;
zoom:1;
}

 

as they don't support 'inline-block' on elements with a natural display of block.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.