Beispiel:CSS2 z-index.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche
<!DOCTYPE html>
<html lang="de">
	<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" >
		<title>z-index</title>
		<style>
.blau {
  z-index: 1;
}

.gold {
  z-index: auto;
}

/* -------- */ 



div {
  position: absolute;
  width: 8em;
  aspect-ratio: 1/1;
}

.blau {
  top: 4em;
  left: 4em;
  background: steelblue;
}


.gold {
  top: 6em;
  left: 6em;
  background: gold;
  border: thin solid steelblue;
}

.wrapper {
  position: relative;
  z-index: 0;
}

 p{margin-top: 12em;}
		</style>
	</head>
	<body>
		<h1>Verwendung von <code>z-index</code></h1>
<div class="blau"></div>
<div class="gold"></div>
<p>Zuerst wird die blaue, dann die goldene Box darüber gezeichnet. Durch <code>z-index: 1 </code> wird die blaue Box nach vorne geholt.</p>
	</body>
</html>