Skip to content

Commit

Permalink
[Sass] Add @extend to the changelog.
Browse files Browse the repository at this point in the history
This is really just a copy of the first bit of the reference.
  • Loading branch information
nex3 committed Apr 26, 2010
1 parent 4c9122a commit 0846056
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
112 changes: 112 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,118 @@

## 3.0.0.beta.4

### `@extend`

There are often cases when designing a page
when one class should have all the styles of another class,
as well as its own specific styles.
The most common way of handling this is to use both the more general class
and the more specific class in the HTML.
For example, suppose we have a design for a normal error
and also for a serious error. We might write our markup like so:

<div class="error seriousError">
Oh no! You've been hacked!
</div>

And our styles like so:

.error {
border: 1px #f00;
background-color: #fdd;
}
.seriousError {
border-width: 3px;
}

Unfortunately, this means that we have to always remember
to use `.error` with `.seriousError`.
This is a maintenance burden, leads to tricky bugs,
and can bring non-semantic style concerns into the markup.

The `@extend` directive avoids these problems
by telling Sass that one selector should inherit the styles of another selector.
For example:

.error {
border: 1px #f00;
background-color: #fdd;
}
.seriousError {
@extend .error;
border-width: 3px;
}

This means that all styles defined for `.error`
are also applied to `.seriousError`,
in addition to the styles specific to `.seriousError`.
In effect, everything with class `.seriousError` also has class `.error`.

Other rules that use `.error` will work for `.seriousError` as well.
For example, if we have special styles for errors caused by hackers:

.error.intrusion {
background-image: url("/image/hacked.png");
}

Then `<div class="seriousError intrusion">`
will have the `hacked.png` background image as well.

.error {
@extend .criticalError;
border: 1px #f00;
background-color: #fdd;
}
.seriousError {
@extend .error;
border-width: 3px;
}
.criticalError {
@extend .seriousError;
position: fixed;
top: 10%;
bottom: 10%;
left: 10%;
right: 10%;
}

#### How it Works

`@extend` works by inserting the extending selector (e.g. `.seriousError`)
anywhere in the stylesheet that the extended selector (.e.g `.error`) appears.
Thus the example above:

.error {
border: 1px #f00;
background-color: #fdd;
}
.error.intrusion {
background-image: url("/image/hacked.png");
}
.seriousError {
@extend .error;
border-width: 3px;
}

is compiled to:

.error, .seriousError {
border: 1px #f00;
background-color: #fdd; }

.error.intrusion, .seriousError.intrusion {
background-image: url("/image/hacked.png"); }

.seriousError {
border-width: 3px; }

When merging selectors, `@extend` is smart enough
to avoid unnecessary duplication,
so something like `.seriousError.seriousError` gets translated to `.seriousError`.
In addition, it won't produce selectors that can't match anything, like `#main#footer`.

See also {file:SASS_REFERENCE.md#extend the `@extend` reference documentation}.

### Sass Property Syntax

New-style properties (with the colon after the name) in the indented syntax
Expand Down
2 changes: 1 addition & 1 deletion doc-src/SASS_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ and you can do

and `_colors.scss` would be imported.

### `@extend`
### `@extend` {#extend}

There are often cases when designing a page
when one class should have all the styles of another class,
Expand Down

0 comments on commit 0846056

Please sign in to comment.