i

Learn HTML and CSS in 10 Days

Positioning Images, Inline Positioning Images, Blocking Positioning Images , Positioning Images Flush Left or Right

Positioning Images

There are several ways to position an image on a web page. Images are positioned as an inline-level element by default. But still, one can change their position by taking the help of CSS, with display, float, and box model properties.

Inline Positioning Images

By default the   element is an inline-level element. Adding up an image without providing any styles to a web page will make that image to appear in the same line as that of the content. Moreover, the line’s height wherein a picture shows up will be changed to coordinate with the image’s height, which can make huge vertical gaps inside that line.

Gatsby is a white, brown and black hound mix puppy who loves to howl at fire trucks. 

Though he spends most of his time sleeping he can chase any birds who enter his vision.

Blocking Positioning Images

Giving a property of ‘display’ to an image and making its value to ‘block’ makes the image to become a block-level element.

img {

  display: block;

}

Positioning Images Flush Left or Right

Sometimes making an image as block or inline, or even inline-block, isn't that good. It might be our choice that all the images appear on the right or left side of its containing element, while the entirety of the other contents folds over the picture as necessary. To perform this, we use the property of 'float' with a value of 'right' or 'left.' We have already discussed it in Chapter 5.

img {

  background: #eaeaed;

  border: 1px solid #9799a7;

  float: right;

  margin: 8px 0 0 20px;

  padding: 4px;

}