views:

150

answers:

4

I just stumbled across this question and I noticed the user is using some notation I've never seen before:

@font-face {
   /* CSS HERE */
}

So is this '@' symbol something new in CSS3, or something old that I've somehow overlooked? Is this something like where with an ID you use '#', and with a class you use '.'? Google didn't give me any good articles related to this. What is the purpose of the '@' symbol in CSS?

Thanks!

+1  A: 

Check this out:

http://www.css3.info/preview/web-fonts-with-font-face/

kbrimington
So is this symbol specific to the `font-face` property?
Hristo
No, see my answer.
BoltClock
That really doesn't answer the question. What is the '@' and what does it mean?
Sam
+9  A: 

@ has been around since the days of @import, and recently @font-face and @media. These are all known in CSS as at-rules. They're special instructions for the browser, not directly related to styling of (X)HTML/XML elements in Web documents using rules and properties (although they do play important roles in controlling how styles are applied).

Some code examples:

/* Import another stylesheet from within a stylesheet */
@import url(style2.css);

/* Apply this style only for printing */
@media print {
    body {
        color: #000;
        background: #fff;
    }
}

/* Embed a custom web font */
@font-face {
    font-family: 'DejaVu Sans';
    src: local('DejaVu Sans Regular'), url(/fonts/DejaVuSans.ttf);
}
  • @font-face defines custom fonts for use in your designs that aren't always available on all computers, so a browser downloads a font from the server and sets text in that custom font as if the user's computer had the font.
  • @media queries control which styles are applied and which aren't, based on what media the page is being displayed in. In my code example, only when printing a document should all text be set in black against a white (the paper) background. You can use media queries to filter out projectors, mobile devices and so on and style pages differently for those.

There is a full list of at-rules at the SitePoint CSS Reference.

BoltClock
So what is the purpose behind these "directives"? I know about `@import`... it includes files right? I'm not familiar with `@font-face` and `@media`... does it include font styles and different media types (video, images, etc...)?
Hristo
You updated your post :) That explains my previous question. Thanks. So does '@' exist elsewhere... besides import, media, and font-face?
Hristo
@BoltClock actually they are called `at-rules`.
Frankie
@Frankie: fixed
BoltClock
+4  A: 

@ is used to define a rule.

@import
@page
@media
@font-face
@charset
@namespace

The above are called at-rule's.

Frankie
What do you mean by "define a rule"?
Hristo
At-rules encapsulate a bunch of CSS rules and apply them to something specific. (http://htmldog.com/guides/cssadvanced/atrules/)
Frankie
A: 

I am more into desktop programming, C, C++ but it is easy to guess that @ is some sort of a directive.

r3st0r3
I'm not quite sure what you're trying to say here... I've done C/C++ as well. But that doesn't really relate to my question. CSS is really far away from C/C++
Hristo