View Single Post
Old 03-26-2024, 01:38 PM   #7
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,119
Karma: 18727091
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Quote:
Originally Posted by swepub View Post
I used your 2nd one and it works great. Just one more question - can you adjust the space between the images and center the two images?
Yes, just set the margin to auto and define a specific width for the div: width = image(s) + padding
5+200+5 + 5+200+5 = 420px

Code:
CSS
.images     {clear:both; width:420px; margin:0 auto}
.images img {float:left; width:200px; padding:0 5px}

HTML
<div class="images">
  <img alt="" src="../Images/img_1.png"/>
  <img alt="" src="../Images/img_1.png"/>
</div>
This is a little less dynamic as you're locking in the image size in px instead of leaving it as a %. If you really need it to be dynamic, replace the px with % like this:

Code:
.images     {clear:both; width:50%; margin:0 auto}
.images img {float:left; width:45%; padding:0 2.5%}
You can set the amount of screen space the images take up by changing the % in the .images width...for example, width:50% => width:75%


Edit:
If the different values for width are confusing just remember that the width refers to the container’s width. In this case, the img width is 45% of the containing div. The total width of the images + padding equals 100% of the div width.
For 2 images:
2.5%+45%+2.5% + 2.5%+45%+2.5% = 100%
For 3 images:
1.66%+30%+1.66% + 1.66%+30%+1.66% + 1.66%+30%+1.66% = 100%

The width of the div is the % of ITS container (the body/document)
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2024-03-26 133617.png
Views:	63
Size:	297.4 KB
ID:	207167  

Last edited by Turtle91; 03-26-2024 at 09:15 PM.
Turtle91 is offline   Reply With Quote