dream hunter dream hunter - 3 months ago 7
CSS Question

i want to align this image to center but it's not working

In the above code I used

margin-left: auto
and
margin-right: auto
properties to align the image to center. I want to align this image to center but it's not working.


  • What is wrong with this code?

  • Are there any alternative methods?





#boom{
margin-top: 30%;
height: 4%;
width: 50%;
margin-left: auto;
margin-right: auto;
}

<img src="image1.jpg" id="boom">




Answer

Add display:table; into your code

#boom{
        margin-top: 30%;
        height: 4%;
        width: 50%;
        margin-left: auto;
        margin-right: auto;
        display:table;
    }