Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 916935 of scroll-snap-destination

  • Revision slug: Web/CSS/scroll-snap-destination
  • Revision title: scroll-snap-destination
  • Revision id: 916935
  • Created:
  • Creator: Sebastianz
  • Is current revision? No
  • Comment Added example

Revision Content

{{CSSRef}}{{SeeCompatTable}}

Summary

The scroll-snap-destination CSS property defines the position in x and y coordinates within the scroll container's visual {{Glossary("viewport")}} which element snap points align with.

{{cssbox("scroll-snap-destination")}}

Syntax

/* <position> value */
scroll-snap-destination: 400px 600px;

/* Global values */
scroll-snap-destination: inherit;
scroll-snap-destination: initial;
scroll-snap-destination: unset;

Values

<position>
Specifies the offset of the snap destination from the start edge of the scroll container’s visual viewport. The first value gives the x coordinate of the snap destination, the second value its y coordinate.

Formal syntax

{{csssyntax2}}

Example

HTML Content

<div id="container">
  <div>
    <p>Snaps at the coordinate (0, 0)</p>
    <div class="scrollContainer destination0">
      <div>1</div>
      <div>2</div>
      <div>3</div>
    </div>
  </div>

  <div>
    <p>Snaps at the coordinate (25, 0)</p>
    <div class="scrollContainer destination25">
      <div>1</div>
      <div>2</div>
      <div>3</div>
    </div>
  </div>

  <div>
    <p>Snaps at the coordinate (50, 0)</p>
    <div class="scrollContainer destination50">
      <div>1</div>
      <div>2</div>
      <div>3</div>
    </div>
  </div>
</div>

CSS Content

.container {
  display: flex;
}

.scrollContainer {
  width: 200px;
  overflow: auto;
  white-space: nowrap;
  scroll-snap-points-x: repeat(100%);
  scroll-snap-type: mandatory;
  scroll-snap-destination: 20px 0;
  font-size: 0;
}

.container:nth-child(-n+2) {
  margin-bottom: 20px;
}

.destination0 {
  scroll-snap-destination: 0 0;
}

.destination25 {
  scroll-snap-destination: 25px 0;
}

.destination50 {
  scroll-snap-destination: 50px 0;
}

.container > div {
  width: 200px;
  height: 200px;
  display: inline-block;
  line-height: 200px;
  text-align: center;
  font-size: 100px;
}

.container > div:nth-child(even) {
  background-color: #87EA87;
}

.container > div:nth-child(odd) {
  background-color: #87CCEA;
}

{{EmbedLiveSample("Example", "100%", "240")}}

Specification

Specification Status Comment
{{SpecName("CSS Scroll Snap Points", "#propdef-scroll-snap-destination", "scroll-snap-destination")}} {{Spec2("CSS Scroll Snap Points")}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatUnknown}} {{CompatGeckoDesktop("39.0")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatGeckoMobile("39.0") }}[1] {{CompatGeckoMobile("39.0") }} {{CompatNo}} {{CompatNo}} {{CompatNo}}

[1] On Firefox Mobile, available since Gecko 39, but behind the preference layout.css.vertical-text.enabled, disabled by default.

Revision Source

<div>{{CSSRef}}{{SeeCompatTable}}</div>

<h2 id="Summary">Summary</h2>

<p>The <strong><code>scroll-snap-destination</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> property defines the position in x and y coordinates within the scroll container's visual {{Glossary("viewport")}} which element snap points align with.</p>

<p>{{cssbox("scroll-snap-destination")}}</p>

<h2 id="Syntax">Syntax</h2>

<pre class="brush: css">
/* &lt;position&gt; value */
scroll-snap-destination: 400px 600px;

/* Global values */
scroll-snap-destination: inherit;
scroll-snap-destination: initial;
scroll-snap-destination: unset;
</pre>

<h3 id="Values">Values</h3>

<dl>
 <dt><code>&lt;position&gt;</code></dt>
 <dd>Specifies the offset of the snap destination from the start edge of the scroll container’s visual viewport. The first value gives the x coordinate of the snap destination, the second value its y coordinate.</dd>
</dl>

<h3 id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox">
{{csssyntax2}}</pre>

<h2 id="Example">Example</h2>

<h3>HTML Content</h3>

<pre class="brush: html">
&lt;div id="container"&gt;
  &lt;div&gt;
    &lt;p&gt;Snaps at the coordinate (0, 0)&lt;/p&gt;
    &lt;div class="scrollContainer destination0"&gt;
    &nbsp; &lt;div&gt;1&lt;/div&gt;
    &nbsp; &lt;div&gt;2&lt;/div&gt;
    &nbsp; &lt;div&gt;3&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div&gt;
    &lt;p&gt;Snaps at the coordinate (25, 0)&lt;/p&gt;
    &lt;div class="scrollContainer destination25"&gt;
    &nbsp; &lt;div&gt;1&lt;/div&gt;
    &nbsp; &lt;div&gt;2&lt;/div&gt;
    &nbsp; &lt;div&gt;3&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div&gt;
    &lt;p&gt;Snaps at the coordinate (50, 0)&lt;/p&gt;
    &lt;div class="scrollContainer destination50"&gt;
    &nbsp; &lt;div&gt;1&lt;/div&gt;
    &nbsp; &lt;div&gt;2&lt;/div&gt;
    &nbsp; &lt;div&gt;3&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>

<h3>CSS Content</h3>

<pre class="brush: css">
.container {
  display: flex;
}

.scrollContainer {
  width: 200px;
  overflow: auto;
  white-space: nowrap;
  scroll-snap-points-x: repeat(100%);
  scroll-snap-type: mandatory;
  scroll-snap-destination: 20px 0;
  font-size: 0;
}

.container:nth-child(-n+2) {
  margin-bottom: 20px;
}

.destination0 {
  scroll-snap-destination: 0 0;
}

.destination25 {
  scroll-snap-destination: 25px 0;
}

.destination50 {
  scroll-snap-destination: 50px 0;
}

.container &gt; div {
  width: 200px;
  height: 200px;
  display: inline-block;
  line-height: 200px;
  text-align: center;
  font-size: 100px;
}

.container &gt; div:nth-child(even) {
  background-color: #87EA87;
}

.container &gt; div:nth-child(odd) {
  background-color: #87CCEA;
}</pre>

<p>{{EmbedLiveSample("Example", "100%", "240")}}</p>

<h2>Specification</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS Scroll Snap Points", "#propdef-scroll-snap-destination", "scroll-snap-destination")}}</td>
   <td>{{Spec2("CSS Scroll Snap Points")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("39.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE&nbsp;Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile("39.0") }}<sup>[1]</sup></td>
   <td>{{CompatGeckoMobile("39.0") }}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] On Firefox Mobile, available since Gecko 39, but behind the preference <code>layout.css.vertical-text.enabled</code>, disabled by default.</p>
Revert to this revision