Problem statement: You must have seen that while applying margin:auto property to the image tag in the navigation bar, the logo image in the navigation bar does not get centered.
Approach: As the image tag in CSS is an inline element, so the image tag will occupy only that much space which is required by it. So, in order to resolve this problem, we have assigned the display property of the image tag to “block” and then assign proper width and height to it. Assign the margin to “auto”. You will see that the logo image is now centered in the navigation bar.
HTML code: Following demonstrates the code for the above approach.