logoalt Hacker News

seg6yesterday at 11:57 PM6 repliesview on HN

The point of centering an element horizontally is to make sure that the content you’re viewing is directly in front of you. Browsers with a sidebar shift the content to the right, assuming the sidebar is on the left, which I’ve come to dislike! Others have expressed the same preference, hence this little snippet on my website.


Replies

stevagetoday at 12:11 AM

> The point of centering an element horizontally is to make sure that the content you’re viewing is directly in front of you.

That's an awfully big assumption. For starters, you're assuming that the browser window itself is centered on the screen, and that the device is centered in front of the user.

I don't think this is the point of centering an element horizontally at all, and the result you have created here is not at all what I as a user want.

danillonunestoday at 1:24 AM

I don't usually use browsers sidebars, but when I do I mentally compensate for it. The viewport is in fact the part of the web page I expect to be the full width, and what things should be centered on.

The same way the vertical centering counts the viewport height only, not the url bar and the tab bar.

wizzwizz4today at 12:04 AM

As a rule, you should not add functionality to a website to compensate for browser misfeatures. People who want the browser to work differently can get a different browser: that's why we call them "user agents". Making the web all complicated like this mainly serves to make it harder for people to use alternative browsers, or for browsers to change their misfeatures without breaking compatibility.

nkrisctoday at 12:12 AM

Joke’s on you: my browser window isn’t centered.

scubbotoday at 12:22 AM

I salute your dedication to understanding and fixing a problem that bothers you - but I must add my voice to those who think that this is not a good design for general use. The viewport is the region within which content should be positioned, and thus within which they should be centred. By your logic, left-aligned content in a browser with a left sidebar should be deliberately covered.

wat10000today at 12:37 AM

This all sounds like a really elaborate way of not taking advantage of the fact that modern windowing operating systems don't require windows to be full screen, and allow you to position the sides of your browser window wherever you want them to be.