Beispiel:CSS-mask-6.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" media="screen" href="./Beispiel:SELFHTML-Beispiel-Grundlayout.css">  
  <style>
svg { 
  background: white;
  border: thin dotted steelBlue;
  width: 96%;
  padding:0;
  height: 250px;
  }

  </style>
  <title>SVG - Mask</title>
</head>
 
<body>
 
<svg viewBox="0 0 200 80" >

    <defs>
        <mask id="Maske" maskUnits="userSpaceOnUse"
               x="0" y="0" width="200" height="80">
            <rect x="0" y="0" width="100" height="80" fill="white"/>
        </mask>

        <text id="Text" x="84" y="48" 
              font-size="20" font-weight="bold" text-anchor="middle">
            schwarz & weiß 
        </text>
    </defs>

    <!-- Hintergrund: rechteck mit schwarzer Füllung (Standardwert) -->
    <rect x="100" y="10" width="95" height="60"  />
  
    <!-- Text wird doppelt benötigt:
	 1. weißer Text ohne Maske
         2. schwarzer Text mit Maske -->
    <use href="#Text" fill="white"/>
    <use href="#Text" fill="black" mask="url(#Maske)"/>
</svg>

</body>
</html>