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.

Spacing Images

Featured Replies

I need to space some images that need to be on the same line, I'll give an example. Right now they are being space using &nbsp but I'm sure there is a more efficient way of doing it, right?

 

Example

 

Thanks in advance!

Edited by MikeP

This is what you have now:-

<p>                                               <a href="uk-virtual-servers.html" title="United Kingdom"><img src="images/uk-flag.png" width="120" height="120" alt="United Kingdom" /></a>                       <a href="usa-virtual-servers.html" title="United States of America"><img src="images/us-flag.png" width="120" height="120" alt="United States of America" /></a></p>

which as you say uses a lot of   because img is an inline element and cannot use side padding or side margin, so make them block elements with side margins and float: left:-

<p>
<a class="image" href="uk-virtual-servers.html" title="United Kingdom"><img src="images/uk-flag.png" width="120" height="120" alt="United Kingdom" /></a>
<a class="image" href="usa-virtual-servers.html" title="United States of America"><img src="images/us-flag.png" width="120" height="120" alt="United States of America" /></a>
</p>

CSS:-

.image { display: block; float: left; width: 120px; height: 120px; margin: 0 50px; }

I hope that works.

Edited by Wickham

  • Author

It put the USA flag underneath the UK flag...

  • Author

OK, adding the float left that you added in worked but now their not where they were. Slightly more left. I'm wanting them to be centered underneath the text above them also the same dimensions between then and the edges... If that makes sense.

There are probably several ways to center them. I haven't looked to see how wide your containing div is but you could add a style top the p tag with a width sufficient for the images and margins and also margin: 0 auto which will center the p tag. Assuming that my margins of 50px are OK, the total width of the p tag would be 120*2 + 50*4 = 440px.

<p id="images">
<a class="image" href="uk-virtual-servers.html" title="United Kingdom"><img src="images/uk-flag.png" width="120" height="120" alt="United Kingdom" /></a>
<a class="image" href="usa-virtual-servers.html" title="United States of America"><img src="images/us-flag.png" width="120" height="120" alt="United States of America" /></a>
</p>

 

#images { width: 440px; margin: 0 auto; overflow: hidden; }
.image { display: block; float: left; width: 120px; height: 120px; margin: 0 50px; }

 

Overflow: hidden is to create a height for the p tag and stop lower elements coming up over them. I think that works but there will be other ways.

  • Author

Thanks! That worked a treat!

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.