|Language:||English, Spanish, German|
|Genre:||Fiction & Literature|
|Distribution:||Free* [*Sign up for free]|
CSS Mastery: Advanced Web Standards Solutions, 2nd Edition HD PDF As part of the Web standards, CSS has become the indispensable. CSS Mastery: Advanced Web Standards Solutions, Third Edition Andy Budd Emil Björklund Brighton, United Kingdom Malmo, Sweden ISBN (pbk). CSS Mastery: Advanced Web Standards Solutions, Second Edition Development (ISBN: ) for Apress and coauthored.
As lead web developer at Agenzia from to , he worked on numerous web projects for major record labels such as Poptones, Universal and bands including The Libertines, Dirty Pretty Things, Beta Band , visual artists and illustrators Jon Burgerman, Paddy Hartley, Lucy Orta, NOW Festival , businesses, community, and voluntary sector orgs, passionately ensuring everything was accessible and complied with current web standards.
He does a bit of public speaking here and there, and will generally do anything for a biscuit and cup of tea, but prefers hard cash. He has lived in many cities, including London and Reykjavik, but has now settled back in his beloved Nottingham, where the grass is green and the girls are pretty. He also drives a year-old car, and has a stupid cat called Bearface.
download Softcover. FAQ Policy. Creating a new block formatting context forces. No block formatting context With block formatting context. These represent explicit lengths that are derived from either the surrounding context extrinsic or the content of the element intrinsic. Both have serious constraints. It also allows you to change the order of elements as rendered on the page. At the time of writing. You would imagine that a robust and flexible layout model would be a key part of a visual presentation tool like CSS.
Initially this included adopting data tables because of their useful layout characteristics—despite their bloated markup and inappropriate semantics. Flexbox acts as an upgrade of the normal flow model inline and block. Flexbox allows you to lay out children of a box either horizontally or vertically and determine the size. The good news is that it is constructed in such a way that you can combine it with other methods.
This means layouts are no longer impacted by the source order of HTML. You can also control the space of the gaps between columns and apply border-like visual effects to these gaps. As multi-column layout is more a tool for typography than general layout.
You learned the difference between inline and block boxes. In the following chapters of this book. You were introduced to the various formatting models of CSS. You also learned about the concept of margin collapsing and how this can affect layout.
We will get acquainted with this powerful new module in Chapter 7. Summary In this chapter. It offers complete separation of layout from source order. One element acts as a source of content. We will take a closer look at flexbox in Chapter 6. Now that you are armed with these fundamentals.
Regions CSS Regions allows you to specify how content flows between elements on a page. Grid layout is not yet widely supported. This module allows you to choose either a set number of columns or a preferred width. Multi-Column Layout The Multi-column Layout Module is a fairly straightforward way of allowing content to flow into separate columns. As our first example in this chapter. Starting with the body element and working down into more and more specific rules. There are a number of areas we will cover in this chapter: This opens up the possibility for us to learn from hundreds of years of typographic history.
The fact that it still renders as a readable document is due to the default style sheet in the browser. Previous editions of CSS Mastery did not contain a separate chapter on web typography. Our goal is to create a relatively short style sheet to help improve the legibility and aesthetics of the page..
A simple HTML document with no styles yet applied Our simple document contains a couple of headings and some paragraphs of text with some inline elements to enhance the text where applicable.
Links will also still be blue. Text Color Text color is perhaps one of the most basic things we set for a document. Sufficient contrast is crucial for accessibility. Our page as it renders with Avenir Next and Georgia on Safari 9 left vs.
For headings. If neither version of Georgia is available. Georgia is a nearly universally available serif typeface. Should the browser fail to find that. Typefaces can have several different variations for each glyph. You can find a good starting point at http: The serif and sans-serif generic families are probably the most common ones to use for text.
Sans-serif simply refers to fonts without serifs. This collection was then used in a mechanical printing press. The sans-serif and serif font families defined at the end of our lists are known as a generic families.
We could also have chosen cursive. Some research around which default fonts are available on various operating systems can help you choose the right stack for your project. The choice of font is also more complex than just whether the font exists or not: If nothing else.
Font Size and Line Height The default font-size value in nearly every browser in existence is 16 pixels. In the digital world. A typeface also known as a font family is a collection of shapes known as glyphs for letters. The spec only demands use of quote marks if the font-family name is the same as a generic family name. The fantasy and cursive generic families are a bit more uncommon. When selecting typefaces for preformatted text such as code examples. These should not be used for screen styles.
Most browsers allow users to zoom the entire page.
The rem unit is relatively new. Setting It is a scaling factor. We could have set the font-size to 21px as well.
As a fallback for older browsers like Internet Explorer 8 and earlier. As a final flexible measurement. With ems. As the em unit scales based on inherited size.
We could have used percentages in place of ems when it comes to font-size. But it also means that p elements that are children of article elements will have a font-size of 1. Consider the following hypothetical style rules: For our h3 elements. To get a consistent but flexible value. Some people like to eyeball it. You can play around with a bunch of different preset scales in the Modular Scale calculator at http: The Modular Scale calculator allows you to play with combinations of fonts and mathematical sizing scales 67 www.
The sizes have then been rounded to match the nearest pixel size and truncated to three decimal places: This box may be further split in to several inline boxes. Each line of text generates a line box. The actual glyphs are then placed as to appear vertically balanced somewhere inside the content area.
Text is drawn in the middle of the inline boxes. If the font-size is 21px and the line-height is 30px. This is more commonly known as line spacing. This height can vary significantly between typefaces. Unlike in mechanical type. Constituent parts and technical terms of the inline formatting model We saw the high-level view of inline formatting in Chapter 3. In Georgia. The font-size is subtracted from the total line height. Glyphs are not necessarily constrained by the content area either: For this reason.
Like we said: Setting Line Height When setting line height. As you tweak the value. They all have more or less complicated relationships to the content area and parent line box. The font-size on the body worked out to be 16px. The default value is baseline. As a general rule. In our article example.
Just to give you an example. The length and font-size of the text also matters: We set line-height with a unitless 1. It is possible to set line-height using pixels.
Vertical Alignment In addition to line-height. At the end of our article. By leaving out the unit we ensure that the line-height for a particular element is inherited as a multiplier. The default value of normal is mapped to The numeric values are written as even hundreds. The various keywords and values that can be used with vertical-align. Helvetica Neue Bold.
Rather than declaring the name of a font variation. Some fonts have numerous variations. Font Weights Next. If there is an item in the line box that is shifted using vertical-align. Helvetica Neue Black. In between those are Medium and Semi-bold or Demi-bold. As the default for headings. The keywords bolder and lighter work a little differently. Note how the top and bottom of the line box are pushed out by the most extreme values.
This tag is originally a remnant of presentational markup from early HTML implementations. Italic style is often used for either emphasis or to distinguish things usually said with a different tone of voice. CSS allows you some control over this. In our example. The results of artificially bolded fonts are sadly often less ideal. Our h1 is displayed as uppercase 71 www. If a font is missing the desired weight. Font Style Setting the declaration font-style: If not.
Proper small-caps variations do this with a greater respect for the letter shapes than just plain shrinking them. Changing the Space Between Letters and Words Changing the space between words and individual characters is often best left to the designers of the typeface. Browsers have been slow to adopt these. Browsers will attempt to fake this for you if no such font is available. The value you give it specifies how much to add or take away from the default spacing.
One final tweak is to set the abbr element with a slightly smaller line-height. The word-spacing property is seldom used. The following rule would add 0. CSS does allow you some crude tools to change this though. In typographic terms. There is no exact answer as to what the perfect line length is.
A little extra spacing can actually make them easier to read. In the case of our body text. This means we can probably get away with a measure in the higher range.
On lowercase text. Should the viewport be narrower than that. In translating this advice to the Web. In the case of very small screens or large screens viewed far away.
Next up. What we can do is look to the research and historical advice on general rules for line length. Overly long or short lines disrupt the eye movements across the text and can cause the reader to lose their place or even abandon the text altogether. It depends on the size of the font.
Uppercase or small-cap glyphs are much better suited to interpret individually. Applying constraints to line length can be done by setting a width either on elements enclosing the text or on the headings.
Having the end edge ragged is not a disaster. Having the left edge of the text straight helps the eye find the next line. Centered text works best for small pieces of user interface copy like buttons or short headings. For paragraphs following upon paragraphs. The article element is constrained by a max-width of 36em. A paragraph of text where text-align: The Web is a different medium. This is a common technique in printed media. If you use justified text. In a right-to-left language such as Arabic.
The type of algorithm used can be altered with the text- justify property. These two logical direction keywords correspond to the writing mode of the text: Different screen sizes. The text-align property can also use the value justify. Internet Explorer supports the nonstandard value newspaper for this property. With the hyphens property. Manual hyphenation with soft hyphens For a longer text like an article.
The manual mode still respects soft hyphens.
HTML entity in your markup. Versions of Internet Explorer before version If you want to activate automatic hyphenation. Activating automatic hyphenation shows a more straight right rag in Firefox To switch hyphenation off. Trying to use it for other purposes is definitely possible. Gaps between columns are controlled with the column-gap property: The article contents now flow automatically into as many columns as can fit inside the 70em maximum width. If we were to increase the max-width to something like 70em.
So much unused whitespace! Older browsers will then show a single column but still comfortably readable fallback: Fallback Width To avoid excessive line lengths in browsers lacking support for the multi-column properties. We can choose to opt out some elements from that flow. If you set a column width and a count. If you set only a column count. An element with column-span: The first heading and the last paragraph span all columns Should we instead choose to let an element in the middle of the flow span all columns.
It does make sense to at least try in some circumstances. Zoe Mickley Gillenwater has an article on this and other pitfalls: Some parts fall out of rhythm 80 www. In print design. Some caveats apply though: We also set a common margin-top value for all headings as 1.
Some designers swear by these types of harmonious measurements. Not only does it help the eye movements when scanning the page. Our multi-column layout.
The multi-column article. That way. Common web fonts like Helvetica. The important thing is that both of these rules sum to a multiple of the base line height: The fear was this would lead to uncontrollable piracy of their typefaces.
Since then. Most foundries that make their fonts available on the Web require certain security restrictions about how they are served. Initially quite experimentally on small blogs and personal sites. The technology to do this has been available since the release of Internet Explorer 4 in The http: Once this new Vollkorn font has been declared. Hosted services take a huge amount of the pain out of dealing with web fonts and allow you to focus on the design and use of them within your web pages.
Choosing a hosted service allows you to license fonts either individually for one-off use or as part of a subscription to a library of fonts. Commercial services like Adobe Typekit http: This rule allows you to specify the location of a font on a web server for a browser to download. In the previous example. The font-face rule The key to embedded web fonts is the font-face rule. Font File Formats Although support for web fonts is now very good across all the main browsers.
They then host and serve these fonts from their reliable and high-speed servers. These online services handle the different licensing deals with foundries and the difficult job of converting fonts to the correct file formats.
The history of font formats is long. If you need support for IE8 and earlier. We have also documented workarounds in the code samples that come with the book. Optional weight of the font.
We are not changing anything about the font. Defaults to normal. It even accounts for quirky behavior in IE6—8. Font Descriptors The font-face rule accepts a number of declarations. Optional style of the font. To deal with this inconsistent support. This pattern. Using this feature. This is part of the spec for how browsers load and select fonts: Many typefaces have different fonts for the various weights, styles, and variants, so you could have several different font-face blocks referencing the font-family name Vollkorn pointing to different files.
AlegreyaSans; src: Vollkorn; src: Vollkorn; font-weight: The h1 and h2 are now using the Vollkorn Bold font file, whereas the h3 uses Vollkorn Medium automatically as the font-weight matches We can see in the preceding example how the mechanics of font-family work in combination with our new typeface: For these glyphs, the fallback font is used—in this case Helvetica. This is apparent from the differing x-height in the two fonts.
The Greek glyphs use the fallback font from the font-family stack. Note how the x-height differs slightly. Luckily, Alegreya contains a wide range of variations, so if we add a new font-face block pointing to the correct file, this issue should resolve itself for any body text already set as font-style: Web Fonts, Browsers, and Performance Although web fonts have provided a considerable leap forward for web design, their application comes with certain disclaimers.
It should be obvious that by downloading extra fonts you are subjecting your users to an increased total page weight.
Your very first consideration should be limiting how many font files you need to load. It is also very important that if you are hosting your own custom fonts, you must apply appropriate caching headers to minimize network traffic. However, there are other considerations in regard to how browsers actually render the fonts to the screen. While web fonts are downloading, the browser has two choices for your textual content. First, it can block showing text on the screen until the web font has downloaded and is available for use, known as the flash of invisible text or FOIT.
This is the behavior that Safari, Chrome, and Internet Explorer exhibit by default, and it can lead to a scenario where users cannot read the content of your site because the fonts are slow to download. A page on http: The other option for browsers is to show the content in a fallback font while it waits for the browser to download the web font.
That flash is sometimes known as the flash of unstyled text, or FOUT. This flash of unstyled text can impact the perceived performance, especially if the metrics of the fallback font are different from the preferred web font you are trying to load.
If the page content jumps around too much when the font is downloaded and applied, the user can lose their place in the page. Sadly, browser support is not particularly broad yet. Instead, we need to use third-party libraries to ensure a consistent font-loading experience. This is a small library that uses the native font-loading API behind the scenes where supported, and emulates the same functionality in other browsers.
It comes with support for some of the common web font providers such as Typekit, Google Fonts, and Fonts. Web Font Loader provides a lot of useful functionality, but one of the most useful is the ability to ensure a consistent cross-browser behavior for font loading.
In this case we want to ensure that slow-loading fonts never block the user from reading our content. In other words, we want to enable the FOUT behavior across our other supported browsers.
Web Font Loader provides hooks for the following events: This code will both download the Web Font Loader script itself and configure which fonts and variations we use highlighted in bold in the code.
The variations we want are described after the font- family name: As the fonts found in this style sheet are loading, the script will automatically add generated class names to the html element.
That way, you can tailor your CSS to the current state of the font loading. These two CSS rules mean that before the Alegreya font has loaded, we are showing the fallback font stack in its place. Then, once Alegreya is done loading, the loader script adds the wf-alegreya-n4-active class to the html element, and the browser starts using our newly downloaded font.
Not only will we now see a consistent behavior across browsers, but we also have a hook for tweaking the details of our typography for both fallback fonts and web fonts. Matching Fallback Font Size With a similar rule applied when the font is loading but not done yet, we can parry differences in font metrics between the web font and the fallbacks.
This is important because when the web font replaces the fallback font, you want this change in size to be as discreet and unnoticeable as possible. In our example, the Alegreya font has a noticeably smaller x-height than Helvetica and Arial both of which have similar metrics. By tweaking the font-size and line-height slightly, we can match the height pretty closely. Similarly, we can adjust for differences in the character widths by tweaking word-spacing slightly.
This way, we end up with a result that much more closely resembles what the text will look like once the web font has loaded. This property allows you to specify the aspect ratio between the x-height and the font-size. In cases where a glyph is missing in the preferred font, the fallback font will then be adjusted in size to match that ratio.
This usually comes down to about half as tall a value of 0. Instead of measuring by hand and setting this value to a number, we can set the keyword auto, and let the browser do the work for us:. At the time of writing, Firefox is the only browser with shipped support for font-size-adjust, with Chrome offering experimental support behind a preference flag.
Advanced Typesetting Features OpenType, a font format developed by Microsoft and Adobe in the s, allows for additional characteristics and features of fonts to be included in a font file. The CSS Fonts specification has targeted properties for many OpenType features, like font-kerning, font-variant-numeric, and font-variant-ligatures.
Support for these targeted properties is not currently available cross-browser, but there are methods for accessing these features through another, more low-level property, font-feature-settings, that does have support across many modern browsers. The font-feature-settings property accepts values that toggle certain feature sets, by passing it four- letter OpenType codes, optionally with a numeric value.
Two pieces of text set in Vollkorn, the first without ligatures and the second with ligatures enabled. The typeface designer can specify several categories of ligatures, depending on whether they should be used generally or in special cases.
To enable the two kinds of ligatures present in the Vollkorn typeface called standard ligatures and discretionary ligatures, we would use the following rule:. Standard ligatures are always enabled by default in browsers supporting OpenType using font- variant-ligatures, so they are left out in the first declaration.
Certain browsers support the font-feature- settings property with a slightly different syntax, and others need a vendor-prefixed version of the property, so a full rule to turn on common and discretionary ligatures would be.
The syntax differences require a bit of explanation: These codes indicate the state for the feature, and if you leave them out like in the preceding example , they default to on. If the feature only has on and off states, a value of 1 turns it on. Tabular lining numerals as set in Alegreya Sans.
Many typefaces. Lining numerals top vs. Numerals Some typefaces include multiple styles of numerals for use in different situations. In the rest of the examples. Vollkorn also includes lining numerals. Prices on the right line up vertically. A full list of the OpenType feature codes can be found from Microsoft at http: It means that some letter pairs may need extra space between them to not seem too cramped up with each other.
A value of auto allows the browser to turn it on when deemed appropriate. This process of fine-tuning the spacing is known as kerning. It can prioritize performance optimizeSpeed. A sentence without top and with bottom detailed kerning activated. We trigger it by setting the font-kerning property. This property has been around for a while and is fairly well supported. For longer runs of body text.
For headings or other short pieces of text. A simple text shadow with some spread applied. The offset of the light vs. When applying multiple shadows. The syntax for text-shadow is pretty straightforward. You need to supply lengths for the x. The ability to add multiple shadows to a single piece of text makes this quite a versatile effect. Any spread value other than 0 means that the shadow is blurry In addition to this. Adding a large number of sharp shadows. The text is set in Nunito.
A large number of text shadows with increasing offset creates a diagonal shade from the text To further increase the sense of hand-painted signage. This way. This is achieved by offsetting the individual shadows in a staggered way. Almost all browsers support the text-shadow property. As for performance where they are supported. The lettering. An example of using the lettering. A script from Zach Leatherman of Filament Group that tries to make a line of text as big as possible based on its container https: Your only option if you would want each letter to have a different color.
A jQuery plug-in from the same folks behind lettering. One of the people behind this plug-in is designer and developer Trent Walton. That approach is not very viable. A script from Nathan Ford of Gridset.
Here are some examples: We took a look at some of the more detailed OpenType options available for increased typographic control—ligatures. Another great guide to typographic practice. The range of possibilities seems endless and makes for a steep and daunting learning curve. While most books concentrate on basic skills, this one is different, assuming that you already know the basics and why you should be using CSS in your work, and concentrating mainly on advanced techniques. This new edition covers all of the CSS fundamentals such as the importance of meaningful markup, how to structure and maintain your code, and how the CSS layout model really works.
Andy curates dConstruct, one of the U. He's also responsible for UX London, the U. Andy was an early champion of web standards in the U. As an active member of the community, Andy has helped judge several international design awards and currently sits on the advisory board for.
NET magazine. Andy is also the driving force behind Silverbackapp, a low-cost usability testing tool for the Mac. Andy is an avid Twitter user and occasionally blogs at andybudd. Never happier than when he's diving in some remote tropical atoll, Andy is a qualified PADI dive instructor and retired shark wrangler. Coming back to the web in , he found this magical thing called CSS and has been fascinated by it ever since.