Skip navigation.

ODIN Blog

Opera Developer Network

Posts tagged with "CSS"

@font-face Web Fonts resources

, , ,

So you've seen the Opera 10 Web Fonts showcases and want to use the technology to expand your site's typography without using images or JavaScript hacks. A great thing about Web Fonts is that they are inherently accessible; of course, it's still possible to choose an unreadable typeface or rubbish colour contrast, but the user can deal with that because it's just text.

Here are some resources which have some fonts that are licensed for embedding using CSS Web Fonts. Please note that I have not checked each individual license, and you should be sure that you check the license for any font you embed. That's your responsibility, not mine. Thanks to all who helped me compile this list, please add any you know of below (anonymous comments are fine).

For those who need to make EOT files and don't run Windows, or do run Windows but, like me, can't get the cobwebbed Microsoft WEFT conversion tool to work, ttf2eot is an command-line utility that does what it says on the tin.

Opera web standards curriculum: JavaScript in town!

, , , ...

Introduction

We've sure got a treat for you this week! You'll be pleased to hear that the final batch of the Opera web standards curriculum core articles is now published. This includes the last of the CSS - an impressively deep study of site planning, templates, layouts and headers, columns and footers - and the entirety of the JavaScript articles.

Please dive in, read through the articles, spread the word and send me your feedback so I can improve the course as much as possible.

Read more...

2008 - the year the web grew up?

, , , ...

In his first regular ZDNet article, our very own Mr Bruce Lawson looks at how web standards have been evolving in the last couple of years, and asks "is 2008 the year the Web finally grew up?".

Read more...

A lovely <br>eak with the CSS Working Group

, ,

Yesterday, Microsoft gave me a free lunch. They did it because I went to Cambridge to observe the CSS working group's face-to-face meeting. I was geekily excited to hear them discuss the topic "what is a br element", and to meet fantasai, with whom I'd worked to gather web designers' wishes for CSS 3 (and who promises faithfully that the feedback on those wishes is imminent).

The "what is a break" debate didn't disappoint. Is it, as Håkon suggested, {content:'\A'; white-space:pre;}? But what about the fact that a single break has no height, but two (or multiple) breaks do? So should we add the rule br+br {content:'\A'; white-space:pre; height:1 em;}?

Someone else pointed out that the break element was more than just a presentational effect, and it has semantics - for example, when used to mark up poetry or code. So is it best described by defining a new value display:break;?

This idea was parked; whereas in CSS 3, a new value for the display property is theoretically possible (but hugely complex), but it can't be done for CSS 2.1. As you might know, the CSS 2.1 spec is

a "snapshot" of CSS usage: it consists of all CSS features that are implemented interoperably at the date of publication of the Recommendation.

Amongst other things, the CSS 2.1 specification doesn't allow an author or implementer to learn how an HTML br should be styled. For example, Microsoft and Mozilla both allow page-break-* to be set on the break element, and all the big four allow br style="clear:left;" to be specified. The problem is that the CSS 2 spec only allows these properties to be set on block level elements, and br is an inline element. (Or is it? There was some debate about whether it was its own kind of element).

It would be wrong to blame the browsers for all allowing clear to be set; the br element has been in the language since dinosaurs roamed the earth, and CSS 1 allowed clear on all elements, not just the block-levels:

Note. This property applied to all elements in CSS1. Implementations may therefore have supported this property on all elements. In CSS2 and CSS 2.1 the 'clear' property only applies to block-level elements. Therefore authors should only use this property on block-level elements. If an implementation does support clear on inline elements, rather than setting a clearance as explained above, the implementation should force a break and effectively insert one or more empty line boxes (or shifting the new line box downward as described in section 9.5) to move the top of the cleared inline's line box to below the respective floating box(es).

CSS 2.1 definition of clear

There was no question whether the exceptional behaviour of br should be specified, only that of how. Anne wanted to make it a special case, by saying html:br may have page-break-* applied, but others objected because CSS is not just for styling HTML:

CSS is the Web's primary style sheet language for specifying the rendering of text documents, in particular those expressed in HTML and XML-based formats. It can also be used to specify portions of the rendering of certain non-text formats, such as SMIL (multimedia) and SVG (vector graphics).

CSS Working Group charter

Eventually, consensus was reached, expressing it in a way that nobody liked but everyone can live with: page-break applies to block-level elements and may also be applied to "other elements". Whether this means that I could develop my brand new Bruce-browser by reading the amended CSS 2.1 spec and interoperably implement br is doubtful (so I'll abandon that plan and carry on with Opera, after all!).

The whole conversation is minuted on the IRC logs. One thing that that impressed me, and which doesn't come over in the minutes, is how much the participants care about users, web authors and designers. On issues where there are several solutions and none is technically superior, the group asked Molly and Jason Cranford Teague (the designers in attendance that day) to make the call.

My thanks to all of them for agreeing to my request to observe. Fantasai is even groovier in real life than online. There are even photos to prove they're all real people!

CSS 3 image replacement

, , , ...

Since before the dawn of time, designers have wanted sexy fonts or images for headings, links and buttons on web pages. The adoption of @font-face for CSS to use any font a designer specifies will take away some of the use cases. The time-honoured method of using img in the source code, and using the alt attribute to as a text alternative still works, of course, and very nice it is too, but some designers prefer to use CSS to replace text with an image.

There is a variety of image replacement techniques, but they all add a background image and then hide the text, usually by moving off the screen. They all suffer from restrictions: they can only be used with opaque images, or against flat colour, or they need extra spans for style hooks. There's also the problem of people who surf with images off, which is quite common for those using phones whose web use is metered. They don't see the image, but don't see the text either.

Using the content property

The CSS 3 content property is experimentally supported by Opera and Safari. Firefox supports the CSS 2.1 spec when used with the :before and :after pseudo-elements and there is rudimentary support (so far) by IE 8 beta.

It allows you to "insert" text or an image into an element, over-writing the HTML content of the element.

So, for example, this code snippet will replace my name in the h1 with my blog logo:

h1 {content: url(bruce-logo.jpg);}
<h1>Bruce Lawson’s gorgeous blog</h1>

You can see it in action on this image replacement test page.

It's interesting to note how the browsers style this differently. To centre the logo, you need to style the h1 with text-align:center, as if Opera centres the real text and then replaces it with the image. Safari will only centre the logo with margins, as if it replaces the text with an virtual img tag, which is then impervious to text-align.

What should browsers do if the image can't be shown?

I think, in any circumstance that a browser can't show an image, it should show the content of the element in the natural position for that text. That would ensure that this CSS 3 image replacement technique degrades well when CSS and images are off.

This behaviour would be similar to iframe: "The information to be inserted inline is designated by the src attribute of this element. The contents of the iframe element, on the other hand, should only be displayed by user agents that do not support frames or are configured not to display frames." In a similar way, html has a fallback mechanism for images and objects: when it can't show the image, it shows the alternate text.

Here's where the support for this image replacement mechanism gets experimental, even in the highly standards-compliant browsers. This is because the specification changed between CSS 2.1 and CSS 3.

CSS 2.1 said

If the user agent cannot display the resource it must either leave it out as if it were not specified or display some indication that the resource cannot be displayed. CSS2 spec

So the current "standard" says that it should either show the contents of the element (the actual text between the tags), which makes sense to me, or some sort of "image not found" icon, which seems to me to be the worst of all worlds. If a screenreader or a search robot gets the plain text, why not a user who has images switched off?

The CSS 3 spec allows you to set a series of fallbacks, much like when you set font-family. So here, the browser will try to replace the header with a movie, then an animated gif if it can't find or display the movie, or a standard jpg if it can't find or display that gif, and if it can't render any of those, it will just show the contents of the element:

h1 {content: url(header.ogv), url(header.gif), url (header.jpg), contents; }

The spec says

If no alternatives exist, then 'none' is used as a final fallback...Thus to make an element fallback on its contents, you have to explicitly give 'contents' as a fallback. CSS 3 spec

To me, it's odd that anyone should want to display nothing instead of the content, let alone make it the default, but at least the new specification allows you to unambiguously tell the browser to display the contents of the element: it's not allowed to "choose" between the text and a "image not found" icon.

What do browsers do?

However, browser support is still experimental as the generated and replaced content module of CSS 3 is still susceptible to change. My no-images test page shows that Opera and Safari still have problems following the CSS 3 spec fully.

Conclusion

Once the CSS 3 spec is finalised and the browser support is solid, a foolproof way of doing image replacement will be available to us that is accessible to screenreaders and which degrades gracefully with CSS off and with images off.