Amando css

Páginas: 9 (2195 palabras) Publicado: 17 de septiembre de 2012
A List Apart: Articles: Learning to Love the Boring Bits of CSS

8/22/12 10:51 AM

Learning to Love the Boring Bits of CSS
The future of CSS gives us much to be excited about: On the one hand, there’s a whole range of new methods that are going to revolutionize the way we lay out pages on the web; on the other, there’s a new set of graphical effects that will allow on-the-fly filters andshaders. People love this stuff. Magazines and blogs are full of articles about them. But if these tools are the show ponies of CSS, then I think it’s time we gave some love to the carthorses: the nuts-and-bolts components of the language, like selectors, units, and functions. I often call these the boring bits, although I say that only with great affection—an affection I think you should share. Tosee why, let’s take a quick walk through some of the best of the new boring bits in CSS—the bits being worked on in half-lit laboratories away from the brilliance of the shiny new things in the shop windows. Some of these boring bits have been around for a while but deserve more recognition, while others are just starting to appear in browsers. But they’ll all be revolutionary to the way wework—albeit in humble, unassuming ways.

Relative size units
It’s likely that, as the smart and forward-thinking developer you are, you’ve worked with relative sizing—that is, em units or percentages—so you’ll know this problem: having to use a calculator to work out sizes because of inheritance. For example, it’s pretty common nowadays to set a base font size for your document and then use relativesizing to set your fonts across the rest of the page. In CSS, that probably looks something like this: html { font-size: 10px; }
http://www.alistapart.com/articles/love-the-boring-bits-of-css/ Page 1 of 7

A List Apart: Articles: Learning to Love the Boring Bits of CSS

8/22/12 10:51 AM

p { font-size: 1.4em; } This is fine, and not a problem at all, until you have a child element you want toset at a different font size. For example, in markup like this: The cat sat on the mat. If you want that span to be at a smaller font size, say 1.2em, what do you have to do? Get your calculator out and work out 1.2 divided by 1.4, resulting in this: p span { font-size: 0.85714em; } And the problem’s not limited to using em either. If you’re building a fluid site using percentages, you’ll knowthat the percentage is relative to its container; so if you have an element that you want to be 40 percent of its parent, the length of which is 75 percent, then the width of the element must be set to 53.33333 percent. Not ideal.

Root-relative lengths
To combat this font-sizing problem, we now have access to the rem (root em) unit. This is still a relative unit, but it’s always relative to afixed base value, which is the font size of the root element of the document (in HTML, that’s always the html element). Presuming the same root font size of 10px that we used in the preceding example, the CSS rules required for the case at hand are: p { font-size: 1.4rem; } p span { font-size: 1.2rem; } Now both rules are relative to the root font size, which is much more elegant and easy to workwith, especially if you have a simple base like 10px or 12px. It’s sort of like going back to using px values again, only scalable. This is one of the better-supported features in this article; it’s in all modern browsers including IE9, and only absent in Opera Mobile.

Viewport-relative lengths

http://www.alistapart.com/articles/love-the-boring-bits-of-css/

Page 2 of 7

A List Apart:Articles: Learning to Love the Boring Bits of CSS

8/22/12 10:51 AM

If you think the rem unit is cool (I do), you’ll be delighted to know there’s also a new set of length units to combat the percentages problem. These work in a similar way to rem, except that they’re relative not to a user-defined value on the document root, but to the dimensions of the device viewport itself. The two main...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • AMANDA
  • Amanda
  • amanda
  • Que Es Css
  • Amanda
  • Amanda
  • amanda
  • Amanda

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS