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>
			main {
				position: relative;
			}
			aside {
				position: absolute;
				padding: 1.5em;
			}
			#element1 {
				background-color: rgb(128 128 128 / .6);
				left: 2em;
				padding-bottom: 5em;
				top: 5em;
				z-index: 2;
			}
			#element2 {
				background-color: rgb(0 0 255 / .4);
				left: 4em;
				top: 8em;
				z-index: 9;
			}
			#element3 {
				z-index: 0;
				left: 6em;
				top: 11em;
				background-color: rgb(255 215 0 / .8);
			}
			#element4 {
				background-color: rgb(128 0 0 / 1);
				left: 10em;
				padding-left: 8em;
				top: 9em;
				z-index: -10;
			}
		</style>
	</head>
	<body>
		<h1>Verwendung von <code>z-index</code></h1>
		<main>
			<h2>Beispiel für die Überlappung der Elemente</h2>
			<aside id="element1">Element mit z-index 2</aside>
			<aside id="element2">Element mit z-index 9</aside>
			<aside id="element3">Element mit z-index 0</aside>
			<aside id="element4">Element mit z-index -10</aside>
		</main>
	</body>
</html>