CSS3
verkannte & neue Features

DWX, Nürnberg 25.06.2013

 

Sven Wolfermann | maddesigns

L O A D I N G

Wer ist die Flitzpiepe da überhaupt?

Sven Wolfermann - Certified TYPO3 Integrator

Twitter: @maddesigns
Web: http://maddesigns.de

CSS is awesome

CSS is awesome

CSS ist kompliziert

CSS animated GIF

Pseudo-Selektoren / neue Selektoren

neue Attribut-Selektoren

[title]
[href="foo"]
[href*="google"]
[href^="http"]
[href$=".jpg"]
[data-*="foo"]
[foo~="bar"]

Pseudo-Selektoren / neue Selektoren

Pseudo-Klassen

:link
:active
:hover
:visited
:checked

:first-child
:after
:before

:target
:not(selector)
::pseudoElement - style fragments of an element
:nth-child(n) - target nth child element.
:nth-last-child(n) - target nth child element but from the end
:last-child

CSS3 transition

Übergänge zwischen dynamischen Pseudoklassen steuern

Transition zwischen Pseudoklassen

dynamische Pseudoklassen

:hover, :active, :focus, :target, :link, :visited, :disabled, ...

aber auch zwischen @media-Queries

Eigenschaften animieren

mit Kurzschreibweise und allen benötigten Browser-Präfixen

.box {
  -webkit-transition: all 1s ease;
       -o-transition: all 1s ease;
          transition: all 1s ease;
}
.box:hover {
  background-color: #184070
}
              

ohne CSS3
mit CSS3 transition

bestimmte Eigenschaften animieren

a.transition1 {
  transition: color 1s ease-out;
  /* weitere Browser Varianten */
}
a.transition2 {
  transition: background-color 1s ease-out;
  /* weitere Browser Varianten */
}
a:hover {
  background-color: red;
  color: white;
}

ohne CSS3 color animiert background-color animiert

CSS Transitions » Überblick Einzeleigenschaften

transition-property
welche Eigenschaft wird verändert, z.B. background-color, opacity, … oder all – also alle Eigenschaften gleichzeitig

transition-duration
Die Dauer der Veränderung – Angabe einer Zeit für alle oder kommagetrennt je “transition-property” Eigenschaft

transition-timing-function
Bézierkurve á la jQuery Animation, also ob die Animation gleichmäßig abläuft linear oder ease-Kurven.

transition-delay
Eine Verzögerung der Veränderung, sozusagen bis die Animation beginnt

CSS Transition » Tools

Ceaser - CSS Easing Animation Tool (matthewlein.com/ceaser/)

cubic-bezier.com (cubic-bezier.com)

Link-Tipps

CSS Transitions 101 (www.webdesignerdepot.com/2010/01/css-transitions-101/)

Let the Web move you — CSS3 Animations and Transitions (www.webdirections.org/blog/let-the-web-move-you-css3-animations-and-transitions/)

CSS3 transitions » Browser-Support

* Opera mit WebKit-Engine

CSS3 animation

jetzt kommt Bewegung ins Spiel!

Ähnlichkeiten zwischen CSS transition und animation

Die Unterschiede von CSS animation zu transition

@-webkit-keyframes pulse {
  from {
    -webkit-transform: scale(1);
  }
  to {
    -webkit-transform: scale(2);
  }
}
.animation {
  -webkit-animation: pulse 1s ease 0s alternate none infinite;
     -moz-animation: pulse 1s ease 0s alternate none infinite;
          animation: pulse 1s ease 0s alternate none infinite;
}
.animation:hover {
  -webkit-animation-play-state:paused;
     -moz-animation-play-state:paused;
          animation-play-state:paused;
}

Animation Eigenschaften

Shorthand:

/* plus prefix */
animation: pulse 1s ease 0s alternate none infinite;
              

Einzeleigenschaften

animation-name: pulse
animation-duration: 1s
animation-timing-function: ease
animation-delay: 0s
animation-direction: alternate
animation-fill-mode: none
animation-iteration-count: infinite

Animation-Demo

Animation-Demo

HTML

<div class="bubble">
  <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/BMW.svg/50px-BMW.svg.png" alt="" />
  <q>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos aut quod facere enim eos</q>
  <cite>BMW</cite>
</div>

Animation-Demo

Animation-Demo – CSS Teil 1

.bubble {
  position: relative;
  width: 300px;
  height: 300px;
  margin: 1em auto;
  padding: 1.5em;
  text-align: center;
}
.bubble:before {
  content: '';
  background-color: #fff;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: -1;
  border-radius: 50% 50% 0 50%;
}

Animation-Demo

Animation-Demo – CSS Teil 2

@keyframes bubble {
  0% {
    transform: rotate(40deg);
  }
  100% {
    transform: rotate(20deg);
  }
}

.bubble:before {
  animation-name: bubble;

  animation-duration: 3s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
  animation-fill-mode: both;
  animation-direction: alternate;
}

Animation-Demo

CSS Animation » Tools (fertige "Libraries" mit Keyframe-Sets)

Animate.css (daneden.me/animate/)

Animatable (leaverou.github.com/animatable/)

Umsichtig mit den Animationen vorgehen!

CSS3 animations » Browser-Support

* Opera mit WebKit-Engine und -webkit-prefix

3D-Transform

Neuland

3D-Transform – 3D Card-Flip

Elemente 3-dimensional transformieren

 

3D-Transform – 3D Card-Flip

HTML

<section class="container">
  <div class="card">
    <figure class="card__front">front</figure>
    <figure class="card__back">back</figure>
  </div>
</section>

CSS

.container {
  width: 200px;
  height: 260px;

  position: relative;
  margin: 3em auto;
  border: 1px solid #CCC;

  perspective: 800px;
}

3D-Transform – 3D Card-Flip

.card {
  width: 100%;
  height: 100%;
  position: absolute;
  transition: transform 1s;
  transform-style: preserve-3d;
}
.container:hover .card {
  transform: rotateY(180deg);
}
.card figure {
  height: 100%;
  width: 100%;
  line-height: 260px;
  color: white;
  text-align: center;
  font-weight: bold;
  font-size: 36px;
  position: absolute;
  backface-visibility: hidden;
}
.card__front {
  background: red;
}
.card__back {
  background: blue;
  transform: rotateY(180deg);
}

http://starlogs.net/

weitere tolle Helferlein

box-sizing – Border-Box-Model ändern

box-sizing – Border-Box-Model ändern

element {
  width: 80%;
  padding: 0 2.5%;
  border: 1px solid #333;
}

Breite des Elements?

* {
  -webkit-box-sizing: border-box; /* Android 2.1-3.0 */
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

Die Breite der Element beinhaltet die Inhaltsbreite inklusive Padding & Border.

calc() - Berechnungen

.content {
  height: calc(100% - 3em;)
}
.footer {
  height: 3em;
}

calc() - Beispiel background-position

.bgposcalc {
  background-image: url(http://placekitten.com/g/300/200);
  background-repeat: no-repeat;
  background-position: calc(100% - 30px) calc(100% - 10px);
}

calc() - Beispiel background-position

calc() » Browser-Support

* Opera mit WebKit-Engine und -webkit-prefix

relative Schriftgrößen

<h1>Überschrift
  <span>mit Subline </span>
</h1>
    
body {
  font-size: 16px; }
h1 {
  font-size: 1.5em; /* 24px / 16px */
  line-height: 1; }
span {
  font-size: 1em; /* 16px / 16px */
  display: block; }
    
Überschrift mit Subline

relative Schriftgrößen

Bei der Berechnung von em-basierenden Schriften acht geben. Der em-Wert bezieht sich auf das Elternelement

span {
  font-size: 0.666666667em; /* 16px / 24px */
}
Überschrift mit Subline

In fast allen Browsern ist 16px die Default-Schriftgröße, nur einige Mobile-Browser haben höhere Schriftgrößen. Blackberry OS 6.0 = 22px, Kindle Touch = 26px.

relative Schriftgrößen – rem

Schriftgröße in rem

rem Schriftgrößen basieren auf das Rootelement (<html>)

html {
  font-size: 16px;
}
span {
  font-size: 1rem; /* 16px / 16px */
}
span {
  font-size: 2rem; /* 32px / 16px */
}

relative Schriftgrößen – rem

SCSS Pixel-Fallback für OldIE

$main-font-size: 16px;

@mixin x-rem ($property, $value) {
  #{$property}: $value * $main-font-size;
  #{$property}: #{$value}rem;
}

.some-class {
  @include x-rem(font-size, 1.4);
}
.some-class {
  font-size: 22.4px;
  font-size: 1.4rem;
}

CSS3 rem unit » Browser-Support

IE 9 / 10 interpretieren rem nicht in der "font" Shorthand-Notation

text-overflow: ellipsis

Textlängen beschneiden

.class {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

Demo: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab eaque dignissimos eveniet aliquid perferendis pariatur dolorum fugit earum nisi id repellendus tenetur odit alias laudantium minima deleniti beatae sed rem.

 

"Problem": geht nur bei einzeiligen Texten (white-space: nowrap)

text-overflow: ellipsis

Wörter trennen

Wörter trennen

h3 {
  font-size: 16px;
  line-height: 1.4;
  max-height: 46px;
  overflow: hidden;
  width: 180px;
}

.shy {
  /* use the HTML-entity ­ */
}

.hyphens {
-webkit-hyphens: auto;
   -moz-hyphens: auto;
        hyphens: auto;
}

.word-break {
/* Non standard for webkit */
    word-break: break-word;
-ms-word-break: break-all;
    word-break: break-all;
}

hyphenation – automatische Trennung

-webkit-hyphens: auto;
   -moz-hyphens: auto;
        hyphens: auto;
}
hyphenate-limit-lines: 2;
hyphenate-limit-chars: 6 3 2;/* longer than 6 characters, 3 or more
                                before break, 2 or more after break */

HSL Color

HSL ist ein weiterer Farbraum – Hue, Saturation, Luminance (Farbton, Sättigung, Helligkeit)

RGBA/HSLA

transparente Hintergrundfarbe

/* RGBA */
element {
  background: rgba(255, 0, 255, 0.5);
}
/* HSLA */
element {
  background: hsla(300, 100%, 50%, 0.5);
}

Demo – transparente Background-Images

opacity vererbt sich auf Kind-Elemente

transparente Background-Images

div {
    position: relative;
    z-index: 1;
}

.opacity-bg:before {
    background: black url("http://placekitten.com/g/400/300") no-repeat;
    background-size: cover;
    opacity: 0.5;
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: -1;
}

Simple CSS-Lightbox Effect

Simple CSS-Lightbox Effect

HTML

<div class="lightbox">
  Lightbox
</div>

CSS

.lightbox {
  background: white;
  background-clip: padding-box;
  text-align: center;
  margin: 8em -15em;
  padding: 5em 1em;
  width: 30em;
  position: absolute;
  left: 50%;
  border: 1em solid rgba(0,0,0,0.7);
  border-radius: 1em;

  box-shadow: 0 0 0 9999px rgba(0,0,0,0.5);
}

Danke für die Aufmerksamkeit!

Sven Wolfermann | maddesigns

 

Twitter: @maddesigns