Hacker News new | past | comments | ask | show | jobs | submit login

Waste time? I can make a one line change to make it basically good enough on mobile:

  - main { max-width: 800px; }
  + main { box-sizing: border-box; max-width: min(864px, 100%); }
There. Anyone who thinks that's a waste of time probably shouldn't be allowed to touch the CSS of a high traffic website.



Nice! As someone who understands very little CSS, could you explain why this works?


I can't tell why it works, but I can talk about some general things I see.

First, I assume the problem is that, when viewed on mobile, this website is wider than the screen. (Or wider than the browser window.) This makes some horizontal scrolling necessary in order to read some of the text.

No matter how narrow I make the browser window on a desktop, the same problem never occurs, so at first glance this looks like a bug in the mobile browser (which for me is Firefox Focus).

The `box-sizing` CSS property determines whether you want the size of an element to be set to the value you specify, or to something else. You might ask "why would I want something else?", and that's a good question.

Anyway, `box-sizing: border-box` means that when you set the width of the element, it won't be any wider than the width that you set. The default value of this setting is `content-box`, which means that the "content" of the element won't be any wider than the width you set, but, if the element itself uses any padding or borders, those don't count toward the width and the element will be wider than you said it should be.

I assume the adjustment to `max-width` is intended to do two things:

(1) prevent the width of the element from exceeding 100%, presumably related to the width of the browser window;

(2) otherwise, raise the previous maximum by 64px, to adjust for the fact that padding is now included in the notional width of the element. There was probably 64px worth of padding originally.

The problems I see in my own analysis are:

(a) We're only adjusting the `max-width` property, which means that if an element wants to be narrower for other reasons, such as the width of the browser window, that was always allowed. It's not clear to me why this wouldn't have been happening in the page as delivered.

(b) As I mentioned above, the problem that occurs on mobile does not ever occur on desktop, no matter how narrow the browser window gets. This suggests that it isn't a problem with the CSS, but rather with the mobile browser.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: