Welcome to WebmasterWorld Guest from 107.20.122.81

Forum Moderators: not2easy

Message Too Old, No Replies

css image positioning

cannot have two images side by side

     

grmorley

7:43 pm on Jul 16, 2013 (gmt 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

DrDoc

8:35 pm on Jul 16, 2013 (gmt 0)

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



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>

grmorley

9:13 pm on Jul 16, 2013 (gmt 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

DrDoc

9:18 pm on Jul 16, 2013 (gmt 0)

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



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;
}

grmorley

9:41 pm on Jul 16, 2013 (gmt 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

aakk9999

9:58 pm on Jul 16, 2013 (gmt 0)

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month



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]

DrDoc

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

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



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

Blank images are a thing of the past.

grmorley

10:13 pm on Jul 16, 2013 (gmt 0)



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

Featured Threads

Hot Threads This Week

Hot Threads This Month