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.

Problems aligning text next to images

Featured Replies

Hi all

 

I don't know why but I'm really struggling with what I feel should be a relatively straight forward task.

On one of my webpages I want to have five images slighlty to the left of center with a paragraph of text next to it.

Think of a Word document - picture with text next to it. A few lines break, next picture underneath the first one, second text underneath the first text.

 

I'm struggling with what to use to make this work.

 

Here is my CSS:

 

For the first two images:

 

#image {

margin-left:100px;

margin-right:auto;

width:400px;

float:left;

}

 

#image1 {

margin-left:100px;

margin-right:auto

width:400px;

float:left;

}

 

For the text/info:

 

#info {

margin-left:650px;

margin-right:auto;

width: 400px;

 

}

 

The HTML:

 

<div id="image">

<img src="images/image.jpg" width="250" height="100" />

</div>

<div id="info">

CONTENT HERE

</div>

 

<div id="image1">

<img src="images/image1.jpg" width="250" height="100" />

</div>

<div id="info">

CONTENT GOES HERE

</div>

 

Doesn't work very well.

I can get teh first image and text lined up fine but not the second.

 

 

In desperation I have tried using float, absolute and relative positions (don't really know what I'm doing) with limited success.

 

The only way I think I can do this is to create 5 CSS DIV's for the five images and another 5 DIV's for the text to go next to them.

 

Please tell me there is a much easier way?

 

Thanks for any help

 

Webtatsic

Edited by Webtastic

You should be able to use a p tag for each line of text and an image, then repeat for the next image and bit of text. See

http://www.wickham43.net/generaladvice.php#textalignvert

where the image (which presumably has more height than the single line of text) has vertical-align: middle which in fact lowers the text to the middle of the image as the image uses the full line-height.

 

If all the images are the same width and are on the left of the text, the text should appear to start at the same place horizontally, if not a more complicated code will be required..

  • Author

Thank you Wickham and Lev for your replies.

 

Just wanted to reply back that I achieved what I needed to achieve with the layout.

However I used a shed load of divs! Again, I'm sure I could have done it a better way but I got there in the end!

 

I'm still confused about <span> and class and what they do.

 

For example:

 

<div id="columns"> I understand that and how it comes from my css file.

 

<div class="somethingelse"> I think I understand that. It also comes from css file which but starts .somethingelse { instead of #somethingelse. Not sure when or why byou would use that?

 

<span> and <span class=""> No idea when you would use these and what they do.

 

Any pointers for the new guy?

Edited by Webtastic

Keep it simple, use *very* simple XHTML, making good use of standard tags.

Get your XHTML markup right first, then style it - that's the best way to approach things.

 

There are many many ways to do what your trying to achieve.

 

You can do exactly what you want to acheive in two ways, first, without any CSS at all:

 

<img src="myimage.jpg" alt="my alt text" align="left" />
<p>My text content goes in here, it will align to the left of the image.</p>

 

Whilst this method works, it's problematical depending on how high your image is and how much text you have.

You may find the images underneath floating against your first image etc.

 

Or, you can apply some very simple xhtml / css.

 

<div class="image_with_text">
  <img src="myimage.jpg" alt="my alt text" />
  <p>My text content goes in here, it will align to the left of the image.</p>
</div>
<div class="clear"></div>

.image_with_text img {
  float:left;
  margin:0 10px 10px 0;
}
.clear {
  clear:both;
}

 

The clear part ensures that the next image and text is not floated alongside the previous.

It should be noted that clearfix would be best suited to this, rather than an additional div, but that is getting fairly advanced and it's probably best if you take things one step at a time!

Edited by bb_matt

  • Author

Keep it simple, use *very* simple XHTML, making good use of standard tags.

Get your XHTML markup right first, then style it - that's the best way to approach things.

 

There are many many ways to do what your trying to achieve.

 

You can do exactly what you want to acheive in two ways, first, without any CSS at all:

 

<img src="myimage.jpg" alt="my alt text" align="left" />
<p>My text content goes in here, it will align to the left of the image.</p>

 

Whilst this method works, it's problematical depending on how high your image is and how much text you have.

You may find the images underneath floating against your first image etc.

 

Or, you can apply some very simple xhtml / css.

 

<div class="image_with_text">
  <img src="myimage.jpg" alt="my alt text" />
  <p>My text content goes in here, it will align to the left of the image.</p>
</div>
<div class="clear"></div>

.image_with_text img {
  float:left;
  margin:0 10px 10px 0;
}
.clear {
  clear:both;
}

 

The clear part ensures that the next image and text is not floated alongside the previous.

It should be noted that clearfix would be best suited to this, rather than an additional div, but that is getting fairly advanced and it's probably best if you take things one step at a time!

 

 

This is really helpful advice, thank you!

A lot to take it in but makes sense.

 

+1

 

W

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.