css

Opera’s WebKit patches

About five weeks ago, we announced that Opera's products would transition to using WebKit. We said "Opera will contribute to the WebKit and Chromium projects. Our work on web standards to advance the web continues."

Obviously, replacing a rendering engine is a huge engineering change, so we've been working flat out, hooking up the new rendering engine, rewriting the UI, integrating new features and testing everything so that you can actually see products. (Have you tried Opera 14 beta for Android 2.3 and above yet?)

But we haven't forgotten our commitment to contributing back. Here are the patches we've submitted to enhance any WebKit-based browser so that they better support CSS:

There are also a number of house-keeping patches submitted by Morten to tidy up some WebKit code: Bug 112442, 110123, and 110121.

Morten's currently looking at implementing CSS object-fit and further CSS multi-column improvements. So don't disturb him until those patches land!

As products start to ship, we'll bring you more news of enhancements we're offering back.

Kickfolio lets you embed iOS apps on any webpage, adds iPad support, slashes pricing

A demo of Angry Bots iOS app embedded using Kickfolio

We told you about a service called Kickfolio in December that would allow developers to demo their iOS apps directly in the browser using a new HTML5-based platform. The service converts a zipped version of an iOS app into a private test page with a completely interactive HTML5 and CSS version of the app. Today, the service got a few updates including the ability to embed app demos on any webpage using an iframe. You’ll find embedded iOS apps above and below that Kickfolio sent over for us to try. Kickfolio also now supports iPad apps, and it is making the service much more affordable for all. This is a powerful tool for developers promoting their apps online, and it’s one I expect many to take advantage of when providing free demos to potential customers and press on their website.

Kickfolio originally had some feedback for users about plans starting at $50 a month. The good news: the company just slashed the cheapest plan to $9 a month (that includes 500 embed sessions). Every plan now also includes unlimited apps, and the company is reopening 15-day free trials so everyone will get a chance to try the new features.

Another embedded app demo from Kickfolio below:


Placeholders and Overflow

Oftentimes our search boxes and other form fields get drastically shortened on mobile devices.  Unfortunately in some circumstances the INPUT element’s placeholder text doesn’t fit within the length of the element, thus displaying an ugly “cut off.”  To prevent this ugly display, you can use CSS placeholder styling and text-overflow: ellipsis!

input[placeholder] { text-overflow: ellipsis; }
::-moz-placeholder { text-overflow: ellipsis; } /* firefox 19+ */
input:-moz-placeholder { text-overflow: ellipsis; }

Most developers are unaware of each of the properties and even fewer are aware that they are so perfectly complimentary!

Read the full article at: Placeholders and Overflow

Hosted by Media Temple, domain from Name.com.

IE 10 and CSS Grid Layout

IE 10 has recently graduated from beta and is now the current official release. It started out Windows 8 only, but now is available on 7 as well as a preview release. Hopefully that will allow it to grab more IE users quickly. IE, which has long been the bane of web developers, has been

Unprefixed CSS3 Gradients in IE10

IE10 in the Windows 8 Release Preview supports the W3C Candidate Recommendation for CSS Gradients in their unprefixed form. IE10 also supports the older CSS Gradients syntax from the W3C Working Draft of 17 February 2011 behind the vendor prefix -ms-. This blog post describes the differences between the old and new syntax and behavior and provides some insight into the change.

Key Changes

Should you choose to simplify your CSS by making the move from vendor-prefixed CSS3 Gradients to unprefixed CSS3 Gradients, there are some key syntax changes to be aware of. Many gradient generators have provided cross-browser markup, including markup for unprefixed gradients. In many cases, the unprefixed markup is no longer valid according to the CSS Image Values W3C Candidate Recommendation that covers gradients. Here are the changes you should be aware of.

Linear and Repeating Linear Gradients

Working Draft Candidate Recommendation
Direction Keywords The top, bottom, left, and right keywords describe the gradient line’s direction via its starting point. The preposition “to” precedes the keywords top, bottom, left, and right keywords describe the gradient line’s direction via its ending point.
Example -ms-linear-gradient(top, orange, black); linear-gradient(to bottom, orange, black);
An example linear gradient going from orange on top to black on the bottom. An example linear gradient going from orange on top to black on the bottom.
Corner calculation Corner keywords specify a gradient line drawn from that corner to the opposite corner. Corner keywords are preceded by “to” and specify a gradient line beginning from the quadrant specified and ending in the opposite quadrant. The center point of the gradient line intersects a line drawn between the remaining two corners.
Example -ms-linear-gradient(top left, fuchsia, yellow); linear-gradient(to bottom right, fuchsia, yellow);
Diagram showing how the angle associated with a corner-to-corner gradient was computed in the old working draft.
Diagram showing how the angle associated with a corner-to-corner gradient is computed in the new candidate recommendation.
Angle Direction 0deg is a gradient line pointing to the right. Angles increase in a counterclockwise direction. 0deg is a gradient line pointing to the top. Angles increase in a clockwise direction. Old angles can be converted to new angles using the formula new = abs(old−450) mod 360
Diagram showing angles in the old working draft with zero degrees at the 3:00 location and positive degrees going counterclockwise. Diagram showing angles in the new candidate recommendation with zero degrees at the 12:00 location and positive degrees going clockwise.
Example -ms-linear-gradient(200deg, lime, magenta); linear-gradient(250deg, lime, magenta);
Example of an angled gradient with magenta in the lower left and lime in the upper right. Example of an angled gradient with magenta in the lower left and lime in the upper right.

Radial Gradients and Repeating Radial Gradients

Working Draft Candidate Recommendation
Position Position keywords or lengths describe the location of the center of the gradient. Position keywords or lengths are preceded by the preposition “at” to describe the location of the center of the gradient. The position is now specified after gradient shape and size, if present.
Example -ms-radial-gradient(center, aqua, black); radial-gradient(at center, aqua, black);
Example of a radial gradient with aqua in the center and black in the corners. Example of a radial gradient with aqua in the center and black in the corners.
Size Keywords Gradient size is defined by one of the six keywords: farthest-corner, farthest-side, closest-corner, closest-side, contain, and cover. Gradient size is defined by one of the four keywords: farthest-corner, farthest-side, closest-corner, and closest-side. contain and cover are no longer valid and correspond to closest-side and farthest-corner, respectively.
Example -ms-radial-gradient(circle cover, lime, black); radial-gradient(circle farthest-corner, lime, black);
Example of a circular radial gradient with lime in the center and black in the corners sized so that the circle diameter matches the longer dimension. Example of a circular radial gradient with lime in the center and black in the corners sized so that the circle diameter matches the longer dimension.
Size and Shape Syntax Radial gradients specified with lengths must have both the horizontal and vertical radius lengths specified. Radial gradients may be specified with only a single radius length for circles.
Example -ms-radial-gradient(center, 50px 50px, red, black); radial-gradient(circle 50px at center, red, black);
Example of a 50px circular radial gradient with red in the center fading to black at the edge of the circle. The circle is centered in the containing rectangle. Example of a 50px circular radial gradient with red in the center fading to black at the edge of the circle. The circle is centered in the containing rectangle.

Background

CSS3 Gradients are defined within the CSS Image Values and Replaced Content Module Level 3 W3C Candidate Recommendation. Gradients were first added to the specification in 2009. They were based on the gradients introduced in WebKit, but with improvements to the syntax. At that time, WebKit had an implementation for -webkit-gradient(). The CSS Working Group iterated on the feature and altered its syntax. Radial gradients and linear gradients would be specified with separate property values, linear-gradient() and radial-gradient(). Fast forward a couple years and all major browsers—Chrome, Firefox, IE10 Platform Preview 1, and Opera—had introduced support for the version of CSS gradients described in the W3C Working Draft of 17 February 2011.

When the Working Draft was closely scrutinized, several changed were suggested and after much discussion the specification was edited to reflect these changes. The major changes, listed in the table above, improved the old specification by addressing issues of clarity and consistency. For instance, in the old angle coordinate system, positive angles increased in a counterclockwise manner. This is in contrast to CSS Transforms and SVG Transforms, where positive angle rotations occur in a clockwise manner. With the specification change, angles that describe CSS gradients are now consistent across other CSS angles and increase in a clockwise manner.

In the process of changing gradients’ syntax, compatibility was a recognized concern despite the specification being in a Working Draft stage. Not all cases are compatible, but much existing content will continue to work. Default values remain the same, so their rendering will be unchanged. For gradient-line direction, the required “to” preposition both adds clarity and changes the valid grammar. Existing content with unprefixed gradients using the old syntax will be invalid, thereby falling back on the vendor-prefixed version.

Update Your Unprefixed Gradients

Now that CSS3 Gradients are stable, we encourage you to update your gradients markup to the correct Candidate Recommendation unprefixed gradient syntax. The Internet Explorer 10 Guide for Developers includes full updated documentation of the unprefixed syntax. You may also remove instances of the -ms- prefixed gradients, as IE10 supports the unprefixed version. If you’re using corner keywords or angles to describe gradient direction, you may want to verify that your gradients still render as desired.

While vendor-prefixed gradients still work in IE10 and other browsers, adding correct support for unprefixed gradients future-proofs your content.

—Jennifer Yu, Program Manager, Internet Explorer

CSS variables

Weeee, CSS variables just landed in WebKit, this is pretty exciting!

Unfortunately I couldn't see them in action in WebKit nightly (must be something I'm missing), but they're here and here to stay. I know there are "purists" that say that stuff like variables has no place in the language and we don't really understand CSS, it's different, etc, etc. But once W3C has a modest proposal and one major engine is implementing variables, then this is where we're headed. And I personally applaud this direction.

Syntax

So the basic idea, according to W3C is this. There are two steps: you declare a variable (together with a value assignment) and then you use it.

This is a declaration of the variable my-color. It's a global variable (defined under :root).

:root {
  var-my-color: #fad;
}

Then you use it like:

.thing {
  color: var(my-color);
}

And the .thing gets the color #fad.

In WebKit

Webkit currently uses a -webkit vendor prefix which makes the whole thing more verbose:

:root {
  -webkit-var-my-color: #fad;
}

.thing {
  color: -webkit-var(my-color);
}

There are many examples for your browsing pleasure in the form of test files in WebKit's repo

Future

It's here. And it's only getting better. There's a dev draft of the CSS variables proposal which talks about using $ instead of var() to refer to a variable, which is so much nicer. Spoken like a true php'ied, eh? :)

:root {
  var-my-color: #fad;
}

.thing {
  color: $my-color;
}

Exciting times!

Moving the Stable Web Forward in IE10 Release Preview

As part of Windows 8 Release Preview planning, we reviewed all the W3C draft standards supported by IE10. In particular, we looked for those specifications that:

  • Are stable, that is, there were no recent additions or changes and no renaming or major changes are expected;
  • Are supported by at least two browsers other than IE10;
  • Are interoperable across all these browsers for the features’ core use cases;
  • Are already used on the Web, including in their unprefixed form; and
  • Reached Candidate Recommendation since Windows 8 Consumer Preview or are likely to become Candidate Recommendations in 2012.

The following W3C draft standard features match these criteria and IE10 now supports them in their unprefixed form:

For compatibility with sites and apps developed using the Windows 8 Consumer Preview, IE10 also supports these standards in their vendor-prefixed form using the Microsoft vendor prefixes (‑ms‑/ms).

IE10 also supports the following W3C draft standards in vendor-prefixed form. We believe these drafts do not yet meet the criteria listed above:

From Experimental to Stable

When Web browsers implement emerging standards they do so by marking the new features with their own vendor prefix: a style property prefixed with ‑moz‑ indicates an experimental CSS feature in Mozilla's Firefox, ‑ms‑ means the same for Microsoft’s Internet Explorer, ‑o‑ for Opera, and ‑webkit‑ for WebKit-based browsers including Google’s Chrome and Apple’s Safari. The features’ object model equivalents are similarly prefixed.

New platform APIs such as window.requestAnimationFrame() are likewise currently invoked as window.mozRequestAnimationFrame(), window.webkitRequestAnimationFrame(), or window.msRequestAnimationFrame().

Browser vendors generally drop their prefix once the corresponding specification reaches the Candidate Recommendation stage. This naming convention has a number of objectives, among which:

  • Allow the specification to evolve: without prefixes web content written for the earliest implementation(s) could constrain the editor(s) and make useful additions or changes difficult or even impossible, and
  • Segregate experimental implementations: the bugs or choice of draft version of a particular browser have no impact on other browsers.
  • Style sheet documentation: the vendor-specific dependencies of a style sheet are explicitly documented

Other standards may not rely on vendor prefixes at all. For instance, browser vendors never prefixed the new HTML elements introduced by the HTML5 specification such as <canvas> and <video>.

The Web’s Best Practices

In practice, there comes a time when several browsers support the same draft feature in an interoperable manner. As a result, Web developers find themselves writing declarations such as:

-webkit-transform: rotate(30deg);

-moz-transform: rotate(30deg);

-ms-transform: rotate(30deg);

-o-transform: rotate(30deg);

After copy and pasting this pattern a number of times, many developers assume the forthcoming W3C standard will be backward compatible with today’s Web. They proceed to “future-proof” their style sheets by adding an unprefixed version of the property:

-webkit-transform: rotate(30deg);

-moz-transform: rotate(30deg);

-ms-transform: rotate(30deg);

-o-transform: rotate(30deg);

transform: rotate(30deg);

From a web developer’s point of view, the above set of declarations is now ready for future browsers that support unprefixed CSS Transforms.

Past standard features have in fact validated this pragmatic assumption. When IE9 added support for the unprefixed border-radius property in its first Platform Preview, our team saw the feature “light up” across many sites due to the future-proofed style sheets already deployed.

A number of features are going through the same evolution now. Not only are many CSS Transitions demo pages already future proofed – see Paul Hayes’ parallax effect or Lea Verou’s animatable gallery – but open source projects such as Google’s html5slides, designers’ home pages, site logos and tutorials routinely include unprefixed transition declarations.

Many transition effects involve CSS Transforms, tutorials for which also frequently declare unprefixed transform properties.

Finishing the Specs

Even as Web developers anticipate browser convergence in their new markup, the standardization process is far more conservative. While border-radius worked interoperably enough for thousands of Web sites, members of the CSS Working Group were busy defining the rendering of more complex cases such as the appearance of a rounded corner between two adjacent borders of variable widths and colors. Likewise, the CSS Transitions, Animations, and Transforms editors are working to specify error conditions, fix errors, or clarify less common scenarios.

While these issues must be resolved to ensure a high level of interoperability and to reach Recommendation status, relatively few of them will affect current and future content. Once a specification is stable and interoperable the web should not be held back by the last corner cases. This was not necessary for new HTML5 elements or to finalize the CSS2.1 spec, neither of which required prefixing.

While solid specifications backed up by complete public test suites are critical, requiring all Web developers to repeat the same declarations multiple times until a Candidate Recommendation is published prioritizes spec completeness over content stability.

Finishing a specification is a time-consuming effort. To take one example, CSS gradients emerged in 2008, the first Working Draft specifying an interoperable solution in 2009 and the Candidate Recommendation was published in April 2012. In the meantime, the standardized syntax became incompatible with the prefixed syntax deployed on many Web sites. The Release Preview of IE10 is the first public unprefixed implementation of the latest spec. (IE10 also supports the more interoperable prefixed version with the ‑ms‑ vendor prefix.)

What It Means For Your Code

CSS gradients

While broadly interoperable, the prefixed gradient syntax supported by all modern browsers reflects a now obsolete draft version of the specification. This earlier syntax is incompatible with the current Candidate Recommendation. For example, if you have declared the following gradient:

background: -ms-linear-gradient(left, yellow, red);

Then producing the unprefixed equivalent is not simply a matter of removing the ‑ms‑ prefix. Because IE10's unprefixed linear gradient function conforms to the latest specification, it should become:

background: linear-gradient(to right, yellow, red);

A future blog post will cover IE10’s support for CSS gradients in more detail.

Cascading and the CSS Object Model

The cascade will resolve prefixed CSS properties as expected; given the following rule (notice the higher rotation angle in the unprefixed declaration):

-ms-transform: rotate(30deg);

transform: rotate(60deg);

Your element will rotate 60 degrees: the two properties are treated as aliases of each other and the last declaration wins. Their corresponding CSSOM properties are also aliases: if you request the computed value of the transform and msTransform style properties they will both reflect the winning 60 degree transform.

Likewise, setting element.style.transform will also set element.style.msTransform and vice-versa.

Serialization of property names

Properties such as transition-property take a list of CSS property names. For instance, to make the transform property transition over 2 seconds in IE10 Consumer Preview a developer would write:

-ms-transition-property: -ms-transform;

-ms-transition-duration: 2s;

IE10 Release Preview will serialize the value of both style.msTransitionProperty and style.transitionProperty as ‘transform’. Note that the original prefix is not preserved.

This is also true for the propertyName property of transition events.

Animation and Transition event type names

IE10 Release Preview allows the registration of Animation and Transition event listeners using both prefixed and unprefixed names i.e. the following are equivalent:

element.addEventListener("MSTransitionEnd", myHandler, false);

element.addEventListener("transitionend", myHandler, false);

But IE10 Release Preview will always return an unprefixed name in the type property of the event object.

What’s Next

We will submit new test cases to the W3C for all the features that IE10 now supports without a prefix. As Working Group members and co-editors, we will work with our colleagues to move these specifications forward to Candidate Recommendation.

We welcome feedback you have on our support for these feature and their cross-browser compatibility.

—Sylvain Galineau, Program Manager, Internet Explorer

→ CSS variables soon to land in WebKit

CSS variables are powerful and almost vital for me nowadays. They are supported in SCSS, LESS and Stylus (all preprocessors). But now WebKit now seem to be on its way of implementing a pure CSS version:

-webkit-var-foreground: green;
-webkit-var-background: rgb(255, 255, 255);

color: -webkit-var(foreground);
background-color: red;
background-color: -webkit-var(background);

I’ve written about a CSS variable implementation before, and even back then I noted that the proposed syntax is bulky and ugly. In the example above you’ll note verbosity and even a vendor prefix (!).

I certainly hope this will be revised and rethought. The way Sass and other preprocessors do it is the way to go:

$foreground: green;
$background: rgb(255,255,255);

color: $foreground;
background-color: red;
background-color: $background;

★ Permalink

CSS layout gets smarter with calc()

CSS layout gets smarter with calc():

Didn’t even know about this feature, but it’s brilliant. A quick idea of what you can do:

#bar {
  height: calc(10em + 3px); 
}

And regarding current support:

The calc() property for lengths is available now in Chrome 19 (Dev channel build) by use of the ‘-webkit-calc’ property, in Firefox since version 8 using the ‘-moz-calc’ property and in Internet Explorer since version 9 unprefixed.

CSS Clearfix Demystified

Introduction So you write HTML and CSS. You have a bunch of div’s and you float them all left. You place these floating divs inside a containing div and you expect the container to “wrap” or enclose the floating divs … Continue reading

CSS Clearfix Demystified is a post from: Themergency