I’m working my way through a book on CSS, came across this passage, and am finding myself confused. I cannot work out the author’s conversion. Would love (and really appreciate) some help. How does he figure the “element’s containing block must be 27.272727em wide”?
Thanks!
Is there anything mre to go off of? The paragraphs width would be varied depending on the parents width. Also 27em width would vary depending on the font size of the parent. Overall, this doesn’t seem to make much sense. There’s just not enough information to go off of.
To be completely honest, he shouldn’t even be trying to force calculations to add percents and ems together. Dunno…just need more information, but I doubt there is, based on that screenshot.
lol, thanks for getting back! Yeah, I was considering this might have just missed some proofing before it went to print. The book is by a pretty respected figure in CSS too, Eric Meyer. Here’s a larger screen shot. And here’s a link to the book in google books:
Ok he’s basically setting up that p{} example and telling you what value the containing block element will equate out to (27.272727em) and any wider than that will result in the auto right margin in being a positive value. Or make the inner p content width wider than 18.272727em and it’ll equate to a positive value and thus create a right margin gap.
I think that’s what the example here is trying to indicate.
So his 27.272727em; example …2/3rds of that (sinceh eh as 67% width) will equate out to 18.181818em (basically). Then you add in the 4em from the right / left padding. That’s 22.181818em. Then 5em from the left margin. That’s 27.181818em. Some browser rounding in place (or bad math by me) and that’s 27.272727em.
Basically, his 27.272727em width parent could easily be any width, and the logic applied elsewhere. For a right margin to appear (as he says), a smaller p{} width is needed, or a larger parent width. Does this make sense?
Your explanation helps a bit, but I’m still confused. So was that figure 27.272727 just arbitrary? Seems pretty specific. I’m with you though on 2/3 of that being the 18.272727.
And I’m not sure why he says "In order for the right margin’s width to evaluate to zero, the element’s containing block must… " Why would you want the right margin’s width to evaluate to zero?
He was saying with that current setup, due to the width of the p{} element (width/margin/padding), there was no right margin due to how an auto margin works.
With that specific example, it equates to margin-right:0;.
I imagine it’s just arbitrary but it does seem specific. I still feel like context was missing, but I’m going with what is in front of me .
I think the whole point that Meyer was trying to make, was that it’s possible to combine different units of measurement, but just make sure you actually take time to do the math .
I believe the math is based on his assumption higher up the page where he says the div width is 30em. In order for the right margin to be zero with all those dimensions in place would mean either the containing block was smaller or the 67% should be larger. Of course the right margin doesn’t need to be zero.
It does seem an overly complex way of saying somethng pretty simple though.
I think the eventual point was that mixing percentage and fixed length units can never produce a full fluid layout. (Of course he didn’t know about the border-box model then so most of that discussion is a moot point really as you can simply switch the border-box model and mix things more or less as you wish.)
OK, I see way up on page 168 he mentions an assumption of a containing block width of 30em. I still don’t understand how he arrives at 27.272727 though.
Ok if he’s working from a 30em containing width, then let’s go through the math here with the mixed example.
67% width would be roughly 20em for the p{}. Then we add in 4em from padding. That’s 24. Then another 5 from the left margin and that’s 29. That means, if we throw together an example…it should have some space on the right due to the 1em leftover (auto margin will make use of this.)
I’m guessing that’s what Meyer meant. He was trying to tell show what value was needed for a 0 right margin, as well as you then knowing what container widht (OR paragraph width) would be needed for that auto right margin to calculate positive/negative.