Opt-in Typography

I recently heard Chris Eppstein give a talk (slides) about creating better stylesheets and using SASS to do it. There were a couple of surprising bits in there, one of which was about “opt-in typography.” The idea was that instead of setting global styles for typographic elements like p, ul, ol, h1, h2, etc that you would instead apply those styles as a class, perhaps .text.

The idea is that there is a lot of places on a website where you want a clean slate to work from and not be worried about what global styles are doing. The classic example is lists, where when using them for things like navigation you likely don’t want the same margin/padding/list-style as you would within an article.

Further, you might have different sets of typographic styles you may want to apply at will. So, instead of global styles like this:

p { } ul { } ol { } h1 { } h2 { } /* etc */

You would scope them to a class instead (using SCSS here):

.text-article { p { } ul { } ol { } h1 { } h2 { } /* etc */ } .text-module { p { } ul { } ol { } h1 { } h2 { } /* etc */ }

In an area of the site that’s a blog post, you can snag your article typography, and in a sidebar module, you can grab the typography for that:


...

Anthony Short feels the same way.

Of course, the effectiveness of this depends on the website. What kind of site it is and what stage in it’s evolution it’s in. I suspect it would work better on websites that have a more “modular” architecture and that don’t have a huge set of legacy content. I’d be interested in trying it on a fresh project.

Opt-in Typography is a post from CSS-Tricks

Source: CSS-Tricks

 

Autofill City & State from Zip Code with Ziptastic

Most address fields on web forms ask for city, state, and zip code (or city and post code, outside of the US). But as us nerds often lament, city and state are redundant with zip code. Or at least they can be inferred from a correctly entered zip code. That’s the kind of thing computers are good at. What we need is a proper API to cough up that information for us on demand.

Enter Ziptastic, a free (donations welcome) API for just that.

Let’s use it.

Form Markup

Five fields. Two for street then city, state, and zip. All wrapped up in a form and fieldset. Nothing special.


Address

Not a real zip code.

Only show the zip at first

We’ll hide all the divs that wrap each row of form elements. We’ll use JavaScript, so that in case the user has JavaScript turned off, the form is still usable.

$(".fancy-form div > div").hide();

Then reveal just the zip code.

form .zip-wrap { display: block !important; }

Front end validation

On the front end, we’re already doing the best we can to help the proper entry of a zip code through HTML5 input attributes pattern, maxlength, and required.

Notice it’s not of type number. Whenever considering type=number, consider “would I be cool with the browser adding commas inside of this number?” and if it’s no, don’t use it, because some do.

jQuery: Watch for entry of valid zip code

We’re going to watch the zip input for keystrokes. Should the final value after a keystroke be a valid zipcode, we’ll attempt to get the city and state through Ziptastic and reveal the other fields.

$("#zip").keyup(function() { var el = $(this); if ((el.val().length == 5) && (is_int(el.val()))) { // Make Ajax call, etc } }

The is_int function is just some extra protection that the number is an integer (like all zip codes) in case the current browser doesn’t support the necessary HTML5.

function is_int(value){ if ((parseFloat(value) == parseInt(value)) && !isNaN(value)) { return true; } else { return false; } }

jQuery: Ajax the data

Yeah so jQuery. We used it above to make event handling on the input easier, but it’s really need here because of its ability to make ajax calls with error handling sixty two times easier than doing it with vanilla JavaScript.

After the passed validation, we can make the Ajax call. All we give it for data is the zip code we’ve collected and we get some JSON back which is trivially easy to access the city and state and apply them as values to the appropriate inputs.

$.ajax({ url: "http://zip.elevenbasetwo.com", cache: false, dataType: "json", type: "GET", data: "zip=" + el.val(), success: function(result, success) { $(".fancy-form div > div").slideDown(); /* Show the fields */ $("#city").val(result.city); /* Fill the data */ $("#state").val(result.state); $(".zip-error").hide(); /* In case they failed once before */ $("#address-line-1").focus(); /* Put cursor where they need it */ }, error: function(result, success) { $(".zip-error").show(); /* Ruh row */ } });

Of course we can validate all day long for the valid format of zip codes, but not every 5 digit integer is a zip code. Should we ask Ziptastic for a zip code that doesn’t exist, it will return an error. In that case we just show an error message.

Demo and Download

View Demo   Download Files

Snag the ZIP. GET IT?! Also, if someone wants to apply some actually nice UX and design to this, I’d be happy to update the demo with credit.

Notes

  • I’m not going to tell you this is bulletproof. Addresses are hard. I heard some zip codes cross state lines.
  • Ziptastic is US only. Zippopotamus is similar and supports 60 counties.

Autofill City & State from Zip Code with Ziptastic is a post from CSS-Tricks

Source: CSS-Tricks

 

CSS Regions Level 3 Updated

The CSS Working Group has published an updated Working Draft of CSS Regions.

CSS Regions allows you to collect content in a named flow, then flow this content through boxes in a region chain.

The most important change in this new draft is the ability for region boxes to automatically size to the fragment of content they receive. This is described in a new visual formatting section which explains the processing model that enables this new behavior. In particular the auto sizing processing model allows regions to have height:auto and size themselves to accomodate content between breaks. There is a thorough example that walks through the steps, and a quick summary on www-style.

Another big change is an updated and expanded CSSOM section. It incorporates extensive feedback from specification and implementation work.

The introductory example has been reworked to include a final region that sizes to accommodate the remainder of the flow content and use grid layout to position the various regions. The code for the example has been collected in one place to improve readability.

A new section describes how multicolumn properties interact with region chains.

There are too many other changes to list here, but you can look through the change list to see the record of every difference from the last working draft.

This new draft is still a work-in-progress, but many improvements have been made since the last official publication. All of the known needed work on outstanding issues is captured in the draft with links to the latest discussions.

As always, please send feedback to the (archived) public mailing list www-style@w3.org with the spec code ([css3-regions]) and your comment topic in the subject line. (Alternatively, you can email one of the editors and ask them to forward your comment.)

Source: CSS WG Blog

 

CSS Exclusions and Shapes Level 3 Updated

The CSS Working Group has published an updated Working Draft of CSS Exclusions and Shapes.

CSS Exclusions and Shapes allows you to define non-rectangular shapes for wrapping content, for instance around the outside of floats. It also extends content wrapping functionality previously limited to floats: now any element can become an exclusion.

This new draft contains an update to the exclusions processing model, which describes how exclusions cause content to wrap around their shapes. Several updated examples show how the model works using varying positioning schemes such as floats and grid layout.

The draft also goes into much more detail on how floats work with all of the new capabilities. A new example using floats has been added, and a new section clarifies how floats and exclusions interoperate.

CSS Exclusions and Shapes is still a work-in-progress, but many other improvements have been made in this draft since the last official publication. All of the known needed work on outstanding issues is captured with links to the latest discussions.

As always, please send feedback to the (archived) public mailing list www-style@w3.org with the spec code ([css3-exclusions]) and your comment topic in the subject line. (Alternatively, you can email one of the editors and ask them to forward your comment.)

Source: CSS WG Blog

 

Minutes and resolutions telcon 2012-05-02

The main topic of the telcon was the Disposition of Comments for the March draft of Values and Units.

  • Resolved: Errata CSS 2.1 to disallow ‘inherit’ after comma in ‘font-family’
  • Resolved: Include the sign in the NUMBER token in CSS 2.1.
  • Resolved: The result or attr() is of integer type if all operands are integer and there is no division.
  • Resolved: Allow attr() in calc() and disallow cycle().
  • Resolved: cycle() is top-level only; when attr() is not at top level then the type of the fallback must match.
  • Resolved: Drop minimum supported multipliers for repeated components from 30 to 20.

Full minutes

Source: CSS WG Blog

 

CSS Writing Modes Level 3 Updated

The CSS Working Group has published an updated Working Draft of CSS Writing Modes Level 3. This CSS module covers bidirectional text and vertical text layout.

The primary changes in this update are to integrate references to Unicode Technical Report #50 (which will define the default orientation of all Unicode characters) and to adjust the algorithm for auto sizing in orthogonal flows to account for the size of the containing block. Significant changes since the last Working Draft are listed in the Changes section.

As always, please send feedback to the (archived) public mailing list www-style@w3.org with the spec code ([css3-writing-modes]) and your comment topic in the subject line. (Alternatively, you can email one of the editors and ask them to forward your comment.)

Source: CSS WG Blog