CSS Trick: How To Center an Object/Image Exactly In The Center of Browser

CSS Trick: How To Center an Object/Image Exactly In The Center of Browser

I recently needed to make a landing page using a placeholder image for a site. I wanted their logo image to be vertically and horizontally centered in the browser.

My first thought was to give the image element the class “centered” and then style that class using my CSS stylesheet:

.centered {
position: absolute;
top: 50%;
left: 50%;
}

What that accomplishes is putting the upper left corner of image exactly in the center of the page, not the center of the image in the center of the page.

In order to get the image exactly centered, it’s a simple matter of applying a negative top margin of half the images height, and a negative left margin of half the images width. I updated my CSS with:

Post navigation

25 thoughts on “CSS Trick: How To Center an Object/Image Exactly In The Center of Browser”

A better way to do this would be to set the margin of the div to margin: 0 auto; That automatically centers the object horizontally inside of it’s container, regardless of width. Then just use what you did to center vertically. This way, if the size changes all you have to modify is one value.

Great Musical.ly is a preferred application for developing 15-second music videos. Exactly how it functions is youngsters select fragments of popular songs and also record themselves singing, lip-syncing or dancing. Fine.

When it comes to gaming consoles, there is always a big fight between Sony’s Playstation and Microsoft’s XBox. Now this rivalry is going to increase even more because Microsoft is getting ready to launch it’s next console, the Xbox 2. You can check out all the details from my site here Xbox 2 Release Date

In this challenging world, we need to be more challenging than others. Due to the advancement of technology, there are many changes in the world, here is the great development called Live IPTV apps. With these, you can watch all the movies, tv serials, & live tv for free. Hence, download live nettv 4.6 updated free apk file.