CSSでの相対的な位置付け
相対配置では、要素は通常の位置を基準にして配置されます。これには、位置:相対を使用します
例
例を見てみましょう-
<!DOCTYPE html>
<html>
<head>
<style>
div.demo {
position: relative;
color: white;
background-color: orange;
border: 2px dashed blue;
left: 50px;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<p>This is demo text.</p>
<p>This is demo text.</p>
<div class="demo">
position: relative;
</div>
<p>This is another demo text.</p>
</body>
</html> 出力
-
CSSを使用した静的ポジショニング
CSSでの要素の配置は、要素を特別な方法ではなく通常の方法でレンダリングする静的なものとして定義できます。静的に配置されている要素は、CSSの配置プロパティ(左、右、上、下)の影響を受けません。 例 CSS静的測位方法の例を見てみましょう- <!DOCTYPE html> <html> <head> <style> p { margin: 0; } div:first-child { position: static; background-color: orange
-
CSSで機能する相対ポジショニング
CSSでの要素の配置は、要素を通常どおりにレンダリングする相対的なものとして定義できます。相対的な配置方法を持つ要素は、CSSの配置プロパティ(左、右、上、下)によって配置されます。 例 CSS相対測位方法の例を見てみましょう- <!DOCTYPE html> <html> <head> <style> p { margin: 0; } div:first-child { position: relative; top:20px; backg