How to Centre Images in CSS

How to Centre Images in CSS

How to Centre Images in CSS. In this article i will share how to centre images using CSS.

In some situation we might want to centre our image , to make it align to our designs and theme.

We can do this using several method. The most common method is using the ” Text-align” method. While in this article we will look into a different approach on how we can centre our image.

In order to do this there are 2 commands involve . the first one is “Display ” while the second one is “Margin”.

Refer the Code Below

HTML

 

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html>
     
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>GETTING STARTED WITH BRACKETS</title>
        <meta name="description" content="Just another Website.">
        <link rel="stylesheet" href="main.css">
        <link href="https://fonts.googleapis.com/css?family=Arvo|Indie+Flower|Ranchers" rel="stylesheet">
    </head>
    <body>
      
      <div class="container">
          <img src="images.jpg " class="borderImage">
                 
        </div>      
         
    </body>
</html>

CSS

 

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
html{
     
     
    background-color: darkgrey;
}
 
 
 
 
img{
   max-width: 100%;
   height:auto;
   padding:5px;
     
     
}
 
 
 
 
.borderImage{
  border-radius: 10px;
  width: 300px;
  height: 300px;
  border : 3px solid #ddde;
  padding : 20 ;
  opacity: 0.5;
  display: block;
  margin:auto;
   
}

 

Output

How to Centre Images in CSS

 

Check out HTML School

Check out how to add transparency to Images using CSS here.

 

 

Leave a Comment

nine + nineteen =