CSSレイアウト[TIPS] position : absoluteについて 「position : absolute」はpositionプロパティのなかの1つで、ボックス要素を絶対的な位置で配置する。 position:absoluteで指定されたボックスは、他の要素との関係は切り離され別物になる。親ボックス以外の他のボックス要素から影響を一切受けない。 position:absoluteには必ず「親」がいる。これが大事。 親にしたいボックスに「position:static」以外のposition指定をし(たいていはrelativeでOK)、そのなかに子を入れてposition:absolute指定をする。「top」「bottom」「left」「right」の値は、親ボックスからの距離。 親ボックスを指定しなければ「ブラウザウィンドウ」が親になる。 結論から言うと、親ボックスが「ブラウ
CSSを使って以下の図のようにDIV要素を下揃えにする方法を示します。 DIV要素を入れ子にして、親に対してposition: relative;を指定し、子に対してposition: absolute;を指定します。すると、子要素は親要素を基準として配置されます。これを使って、親要素からの相対的な位置に子要素を配置できます。これを利用すると、以下の図のようにサムネイルにラベルを重ねることができます。 基本 見本 HTML wrapperにサムネイルを構成するものを挿入します。 <div class="wrapper"> <div class="thumbnail"></div> <div class="label">たい焼き</div> </div> CSS 親要素にposition: relative;を子要素にposition: absolute;を指定します。 サムネイル画像はba
実際の上下左右の距離は「top」「bottom」「left」「right」プロパティを併用します。これらはpositionプロパティの値がstatic以外の時に有効となります。 またこの4つ全てを使う必要はなく、「top」だけ、「top」と「right」だけと必要なもののみ使い、配置された位置からの距離を指定します。 言葉だけではイメージがつきにくいと思いますので、以下より実際配置した時の画像と併せてご説明します。 2.“relative”と“absolute”の動きの違い i)relative 【その1】 100px × 100pxの灰色のボックスの下に、relative指定した を配置しました。 今回は上から0pxの距離を指定しています。 <div class="box">box</div> <div class="relative">relative</div> .box { wid
CSS の position プロパティの使い方を覚えると、画像と画像を重ねる、画像と文字を重ねる、というのが簡単にできるようになります。 画像編集ツールで加工してもよいのですが、CSS で表現すると画像の上に表示されているテキストを検索エンジンが認識してくれるので SEO 効果が期待できる、というメリットがありますね。 それでは position:relative と position:absolute の使い方を見ていきましょう。 position プロパティの使い方基本 positon プロパティで聞いたことがあるのは「相対配置」と「絶対配置」という言葉だと思います。 何となくイメージはできるものの、検索して解説を読んでもイマイチわからず…という状態ではないでしょうか。 position プロパティで使える値をおさらいしておきましょう。 static
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く