CSS버그, Auto Height & Margin-collapsing

Some of you may be aware of the fact that I am co-teaching a CSS-Workshop over at IWA/HWG. This week two students ran into exactly one and the same problem so that I had to find an explanation. So this entry is basically meant for them.


If you are working with CSS on a regular basis, you might have come across this behaviour. As did I. And if you are like me, you might have found a solution that works around it. But I have to admit that I never really understood what was happening.


So here is the first part of this problem. Consider the following markup:




We’d have the following stylesheet:




I am sure that by quickly having a look at the markup and the styles most of you would expect the following (even I did that):



But, surprisingly, in a modern browser it renders like that:



You can have see this in action by checking out Example 1.


What triggers this behaviour? There are two aspects coming into play here. One of them being the behaviour of margin-collapsing. This means that correctly implemented user agents collapse vertically adjacent margins. Using our example from above that is to say that the top border edge of our div is 20px away from a preceeding or its containing element (assuming that any eventual preceeding element hasn’t a bottom margin that is larger than 20px, which isn’t the case here. Let’s also assume and state that our div is the first and only child of body.) and not 30 pixels. So the smaller of the two margins is eliminated in favour of the larger. This is illustrated in the following figure:



Fair enough, you’d probably say, but why isn’t the paragraph 20 pixels away from the div’s top outer border edge like shown above in figure 1? Why does the paragraph’s margin “stick out” of the div?


Before answering this question I am going to provide you with a figure that shows you the complete box model for reference (okay, maybe not complete, I focused on the vertical axis, since that is all that matters here):



Now, the answer to our questions from above is derived from the fact how the height for a block-level element is calculated in CSS. If such an element has no height defined, it will be set to auto, which is the default height for block-level elements. Thus, in our example the height of the div is per definition the distance from the outer top border edge to the outer bottom border edge of the paragraph. Any vertical margin of the paragraph therefore will stick out of the div. The following two figures try to illustrate this. The first one shows the paragraph’s box, while the second one outlines the beforementioned calculation of the div’s height.




How would we then avoid the collapsing of the topmargins? I want the paragraph being 20 pixels away from the div’s top border edge, how would I do that? The solution to this question lies in the question already. We have to change the height of the div by either adding a border or a padding. Let’s add the following to our above styles:




This little addition now completely changes how the height of the div (which is still auto) is calculated. Now its height will be the distance from the outer top margin edge to the outer bottom margin edge of the paragraph. The same would have been valid if we had added a top and bottom border instead of top and bottom padding. See the illustration below or check out Example 2.




Another example involving a floated element!


The following is a simplified reconstruction of what happened to some of my students in the workshop. The given markup would be something like this:




Furthermore, we apply the following styles:




Let me show you the rendering results of three different browsers first:


Mozilla rendering
Mozilla 1.7


Opera rendering
Opera 7.5


Internet Explorer rendering
Internet Explorer 6


You can check your own browser by looking at Example 3.


Well, that’s pretty neat, isn’t it? In fact, that is why we like CSS so much 🙂


But given our markup and our style declarations, Mozilla does it correct. Under certain circumstances (I’ll explain that a bit later) Opera is correct either. Internet Explorer (surprise, surprise) is wrong here.


At first glance I thought to myself that Mozilla must be wrong. It seemed to clearly violate the float rule number 8, which states:




A floating box must be placed as high as possible.


So, Opera must be right, and even IE is coming close. This second thought alone should strike all alarm bells! Let us see what else is available. Take a look at float rule number 4:




A floating box’s outer top may not be higher than the top of its containing block.


So it all comes down to one thing again. The containing block in our case would be body. Where is the top of body and what is the height of body? Take a look at our body styles. There is not much in there, just a font declaration. So the initial values for margin, padding and border will be assumed. Those are 0, 0 and none which means no margin, no padding, no border.


If we now consider what we have learned in our first example, the height of body will be the distance from the outer top border edge to the outer bottom border edge of its normal-flow block-level child (= the content div), while the margins of that child will again “stick out” of it.



But how can Opera render it completely different and nonetheless be correct? In this special case, you have to be aware of the fact that most browsers have their own user agent stylesheets implemented. These stylesheets rule the rendering of hyperlinks for example, or the font family and size that is displayed on completely unstyled pages. Additionally, they set an explicit value for margin and padding for body.


Since we have declared neither in our styles, our initial values will be outruled by the user agent’s styles. Now the main point here is, that Opera has different styles than Mozilla and Internet Explorer. The Opera styles declare:




On the other hand, Mozilla and Internet Explorer assign the following styles:




This is only a slight difference, but it has a lot of impact on our example design. Let us copy Opera’s styles and add the following to our working example:




Since there is now a padding, the height of body will change. It will be now the distance from the outer top margin edge to the outer bottom margin edge of its normal-flow block-level child.



This last example is also available. If you wish, please have a look at Example 4.


If the above illustrations are too small for your eyes, I have created a page containing all of them at a higher resolution.


이 글은 스프링노트에서 작성되었습니다.

giving blessings to those who are less fortunate than usIn this price range, DirecTV will be worth around $50 billion, and AT will assume its $16 billion of net debt (DirecTV’s financial and operating data are available here). That makes the enterprise value of this deal $66 billion.. I can’t do it.’ So the secret to my success is just that I knew I had the ability and desire deep down and I held on. It seemed like success happened to me. So, Jeff has to tell me that he’s going to, what are you going to do Jeff? Eight ball in the corner pocket. Now, if Jeff scratches while shooting at the eight ball, he loses. Etablissements Delhaize may sound unfamiliar to many Americans, but those in the south and mid Atlantic states probably recognize the company’s Food Lion supermarket brand. In fact, this retailer has over 1400 stores in 10 of the states in the southern region. On Saints game day, the square mile around the Superdome is all tailgaters and they take their “Who Dat” rallying cry very seriously. It’s basic vocabulary around here, explains Mike Stieger. We observed that there was a baseline level of T Tau in control mouse serum. However, the levels of serum T Tau began to increase gradually after injury and it remained significantly higher than sham controls from day 1 to day 30 (Fig. Moving wholesale nfl jerseys onto Kinect, Major Nelson reminds gamers that they can launch any app by wholesale jerseys china simply saying “Xbox, Go To” and then say the name of the game or app they want to launch. This works at any time so you can say, “Xbox go to Forza Motorsport 5” and Cheap Oakleys then immediately say “Xbox go to Killer Instinct.” The first game will be put on hold and the second will be launched. The good news is that the more you care (and show you cheap nfl jerseys do), the more you stand out in a world where many don Caring is great for business. The even better news is that by making, say, one percent more effort cheap oakley sunglasses and paying attention to the little things, you can transform your relationships and see your overall success skyrocket.. Kind of lay it and make sure you are covering both sides so its even. And then you wholesale jerseys kind of just smooth it down and make sure everything is good. The results suggest some whites feel a degree of discomfort seeing an African American in an on field leadership role, and cheap oakleys outlet this puts pressure on black quarterbacks to produce quickly or be replaced. Whether the coaches and team owners are responding in a personally racist way, or believe they are reflecting the perceived preferences of the fans, is not clear.

DOC타입이 설정된 문서내 ScrollLeft와 ScrollTop의 인식문제

Script Code:

 

Html Code:

 

Explain:

DOC Type이 설정되지 않은 문서의 경우에는 document.body.scrollLeft가 잘 작동하나 DOC Type이 설정된 문서의 경우 스크롤이 최상단에 있는 경우를 제외하고는 스크롤의 값을 0으로 반환한다. 위의 작성예제와 같이 document.documentElement.scrollLeft 로바꿔서 사용해보면 잘 작동되는 것을 알 수 있다.

 

But at least someone finally gave a hoot about soccer. I feel proud. According to height and weight standards published nfl jerseys cheap by the Marine Corps in 2008, the maximum weight for women who are 5 foot 3 is 141 pounds. Taller women are allowed to weigh more, with the weight limit set at 164 pounds for a woman who is 5 foot 8 and 184 for a woman who is 6 feet tall.. They’re this unstoppable juggernaut. How do they do it? Let’s analyze Art Briles’ offense. But when you think about it, the conclusion the president and vice president reach (to not listen to Dennis Quaid) is extremely scientific. Because Dennis Quaid is a lone crackpot. For me this is more than enough information to track my fantasy team and players. I see no advantage of the NFL Sunday Ticket.. Jurassic Park is a movie about science, starring scientists, written by ray ban sunglasses a scientist. The antihero is John Hammond, a leisure suited billionaire with childlike enthusiasm for the possibilities of genetic science. The name was created in 1921 to “personalize responses to consumer inquiries,” and her famous signature was chosen from samples submitted by female employees. She was invented by Sam Gale, Washburn Crosby’s advertising director, because he didn’t think women would take cooking advice from a man.. Higbee was arrested April 10 on suspicion of second degree assault, evading police and public intoxication after an altercation with a man outside a bar in Bowling Green. Nawaf Alsaleh, 24, was found unconscious and bleeding from the mouth. 14 days post surgery, GFP positive monocytes were found in the blood of WT parabionts by both immunocytochemistry and flow cytometry (data not shown), hockey jerseys which demonstrates the parabiotic partners successfully share their blood. Furthermore, we examined the peripheral organs including lungs and livers, in which monocytes/HSCs differentiate into macrophages at a higher turnover rate than CNS16,17,18. However, the Turbiaux’s bullets fell much closer to the “cute” axis of the French Firearms Scale of Preciousness and Death, so shooting a fellow with it was more a means of expressing your general displeasure with his choice of hat than a viable method of actual assassination. Plus, if the victim didn’t die from the initial hail of micro Cheap Jerseys bullets, you had to fully dismantle the gun just to reload. Our consumption has risen every year but one since 1983. Added sugars include regular table sugar derived from sugarcane and sugar beets (sucrose), corn syrup, high fructose corn syrup, corn sugar (glucose), honey, and others. This has cheap nfl jerseys not been the case with LINE. Much like Wholesale NFL Jerseys ray ban outlet a running back, LINE has kept the ball moving forward during these tough economic times.