i want to align 3 images in same row in a div, the 1st image should be aligned to complete left of page, the third image should be aligned to complete right of the page and the 2nd image should be aligned in exact center of 1st and 3 rd images
tried the below code but its diaplaying the way i want, how to align the 3 images with the 2nd image placed exactly in the center of the other 2 images?
<div>
<img src="@Url.Content("~/images/image1.bmp")" alt="" align="left" />
<div id="content" align="center">
<img src="@Url.Content("~/images/image2.bmp")" alt="" align="center" />
</div>
<img src="@Url.Content("~/images/image3.bmp")" alt="" align="right"/>
</div>
<style type="text/css">
#content {
width:50%;
margin-left: auto ;
margin-right:auto ;
}
This should be your answer
HTML:
CSS:
I haven't tested this, but hope this will work.
You can add 'display:inline-block' to .container span to make the span to have fixed 30% width
Option 1:
Always remember to add
overflow:hidden
to the parent (if you have one) of all the images because using floats with images have some side effects.Option 2 (Preferred):
This will be the best way to make sure the 2nd image is alligned to the center always without worrying for the exact width of the table.
Something like below:
The modern approach: flexbox
Simply add the following CSS to the container element (here, the
div
):The old way (for ancient browsers - prior to flexbox)
Use
text-align: justify;
on the container element.Then stretch the content to take up 100% width
MARKUP
CSS
I assumed the first DIV is
#content
:And CSS :