Welcome to WebmasterWorld Guest from 54.162.232.51

Forum Moderators: not2easy

Message Too Old, No Replies

css image positioning

cannot have two images side by side

     
7:43 pm on Jul 16, 2013 (gmt 0)

New User

joined:July 16, 2013
posts: 4
votes: 0


I've been trying and failing to have two images side by side with space between them and centered.

I can sort of do it but the bottom table comes up and rest against the bottom of images and no matter what I do it won't move.

In the end I have put them in a table and everything is great but I want to do it with CSS.

Can someone give me the exact CSS and html to make this happen?

Thanks.
Graham
8:35 pm on July 16, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


Welcome to WebmasterWorld! Glad to have you here, and hope to see you many more times.

As for your question, it might be good to point out that there's no disconnect between CSS and tables. Tables are HTML, CSS is used to style all HTML elements.

In this case, you are looking at a single property:
text-align
.

You can easily use CSS to tell your images to line up as described.

.container { 
text-align: center;
}

<div class="container">
<img src="img.jpg">
<img src="img.jpg">
</div>
9:13 pm on July 16, 2013 (gmt 0)

New User

joined:July 16, 2013
posts: 4
votes: 0


Thanks for that - yes it does work. How can I increase the white space between the images and also the lower table still clings to the bottom of the images? If I have just one image <br> or <p> gives me the required space between the images and lower table.

Thanks.
Graham
9:18 pm on July 16, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


Having a
<br>
certainly works. But there is also no need to introduce markup when it isn't necessary.

By tweaking the CSS above, you can easily achieve what you are looking for. Try giving your images some padding. for example:

.container img { 
padding: 1em;
padding-top: 0;
}
9:41 pm on July 16, 2013 (gmt 0)

New User

joined:July 16, 2013
posts: 4
votes: 0


Thanks for that - I see how that works but I want to increase the space between the two images - at the moment they are almost touching - before I would have put a blank image between them but sure this isn't the case?
Thanks.
Graham
9:58 pm on July 16, 2013 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Apr 30, 2008
posts:2630
votes: 191


For example:

<div class="container">
<img src="img.jpg" style="margin-right: 20px;">
<img src="img.jpg">
</div>

But this is inline css. There are many ways to do this in css that is not inline.

<added> This is wrong, isn't it! Not thinking!
</added>

[edited by: aakk9999 at 10:02 pm (utc) on Jul 16, 2013]

9:59 pm on July 16, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


You can achieve that by playing around with padding. [w3schools.com...]

Blank images are a thing of the past.
10:13 pm on July 16, 2013 (gmt 0)

New User

joined:July 16, 2013
posts: 4
votes: 0


Thanks for your help I'll try the padding etc. tomorrow and get back to you.
Thanks again.
Graham
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members