Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to align img inside the div to the right?

Tags:

html

css

I would like to know how to align the image inside the div on the right side?

like image 237
Linards Avatar asked Jul 15 '10 10:07

Linards


People also ask

How do I align an image to the right in a div?

Aligning an image means to position the image at center, left and right. We can use the float property and text-align property for the alignment of images. If the image is in the div element, then we can use the text-align property for aligning the image in the div.

How do I align an image to the right side in HTML?

To align the image to the right use attribute value as “right”. Example: HTML.

How do I align an image in CSS?

To center an image with CSS Grid, wrap the image in a container div element and give it a display of grid . Then set the place-items property to center. P.S.: place-items with a value of center centers anything horizontally and vertically.


2 Answers

You can give the surrounding div a

text-align: right 

this will leave white space to the left of the image. (= the image will occupy the whole line).

If you want content to be shown to the left hand side of the image, use

float: right 

on the image. However, the surrounding div will then need overflow: auto to stretch to the needed height.

like image 178
Pekka Avatar answered Sep 24 '22 18:09

Pekka


<div style="width:300px; text-align:right;">         <img src="someimgage.gif"> </div> 
like image 27
gillyb Avatar answered Sep 25 '22 18:09

gillyb