4 ms·
I'm open to new perspectives. In what way I should I see the page such that "center me in my parent" is unreasonable unless the parent has a fixed width? What,
by ericb 19y ago
I'm open to new perspectives. In what way I should I see the page such that "center me in my parent" is unreasonable unless the parent has a fixed width? What, in particular, about the box model makes this impossible?
- run4yourlives 19y agoThe notion of "center" doesn't exist without a width. Now, you could give the object in question a width and simply give it margin-left/right: auto. That would center it in the width-less parent, but it wouldn't fix its position to the particular spot you're currently seeing it in. For understanding, take it up to the highest level, the browser window. Make your browser 1024x768. Now make it bigger or larger - where is the "center"? It's moved depending on the size of the browser window. If you have a parent whose width is variable, you can't center the child. The key is that, unlike years of using tables to hack up a website, the canvas CSS uses is variable; its height and width is undefined. Thinking of it like this, it makes perfect sense that center isn't used.
- palish 19y agoI don't follow. At any instant in time, every element on a webpage has a well-formed width. So why can't a child be centered, using that width?
- run4yourlives 19y ago>At any instant in time, every element on a webpage has a well-formed width. That's not exactly true. Every block element has a width, but inline objects do not. Furthermore, some block elements may have fixed widths, while others may be designed to take up as little as they require. The "center" attribute that you describe would run counter to the visual formatting model of the standard that is in place to support a number of other things. That would mean that its behaviour would be next to impossible to design around if you were trying to account for all of your users screen sizes at the same time. See here: http://www.w3.org/TR/REC-CSS2/visuren.html#containing-block http://www.w3.org/TR/REC-CSS2/visuren.html#containing-block
- palish 19y agoThat would mean that its behaviour would be next to impossible to design around if you were trying to account for all of your users screen sizes at the same time. See, there's where we differ. I'd like to easily design a webpage that renders fine on 90% of my user's screens. I'd bet 90% of my users will be using personal computers, and use a resolution between 800x600 and 1920x1200. Want to look at my page on your non-iPhone? I'd love to introduce you to the m.mypage.com section of my site. Something like "Center a child relative to a parent" isn't hard to do (we do it at work for our video game GUI), and it really seems like a few architecture astronauts got ahold of the CSS standards to cause these API usability problems. Also, arguments like "You can't do that simple thing because.." are starting to sound like the arguments C++ pundits use to justify its monstrous complexity compared to C.
- run4yourlives 19y agoI never said you couldn't do it, you just can't do it the way you prefer: parent {} child{ margin-left: auto; margin-right: auto; width: 100px; }
- palish 19y agoMy question is simply, what's the reasoning behind my inability to type: child{ center: horizontal; } That would be very newcomer-friendly. Possibly naive, but I'm interested to know why.
- run4yourlives 19y ago1. center to what? 1a. child is 0px wide. 2. semantics: You're basically saying "Why isn't language x exactly like language y/how I want it to be?" 3. margin is what you're adjusting, so saying margin-auto makes sense. 4. Layers and layering are an important aspect of CSS, you've just broken all of them.
- euccastro 19y ago
- deleted 19y ago[deleted]