サンプル①
サンプル②
サンプル③
サンプル④
#sample1, #sample2, #sample3, #sample4 { position: relative; width: 150px; height: 150px; box-shadow: 1px 1px 1px #ccc; display: inline-block; margin: 45px 15px; cursor: pointer; } #sample1 img, #sample2 img, #sample3 img, #sample4 img { position: relative; width: 100%; height: 100%; } #sample1 div { position: absolute; width: 150px; height: 200px; /* 画像の高さと吹き出しの高さをプラスした値 */ top: 0; left: 0; background-color: #bbb; box-shadow: 1px 1px 1px #111; display: none; } #sample1 p { position: absolute; font-size: 16px; left: 4px; top: 150px; color: #000; padding-left: 10px; padding-right: 10px; } #sample2 div { position: absolute; width: 150px; height: 200px; /* 画像の高さと吹き出しの高さをプラスした値 */ top: -50px; /* 文字を表示する文だけ上にずらす */ left: 0; background-color: #ccc; box-shadow: 1px 1px 3px #000; display: none; } #sample2 p { position: absolute; font-size: 16px; top: 4px; left: 4px; color: #000; } #sample1:hover img, #sample2:hover img { z-index: 4; /* .boxよりも上に表示 */ } #sample1:hover div, #sample2:hover div { z-index: 3; /* imgよりも下に表示 */ display: block; } #sample3 div { position: absolute; width: 150px; /* 吹き出しの幅 */ height: 30px; /* 吹き出しの高さ */ top: 156px; /* 画像と三角形の高さをプラスした値 */ left: 0; border-radius: 10px 10px 10px 10px; background-color: #ccc; display: none; } #sample3 div:after { /* 三角形を作成 */ position: absolute; content: ""; width: 0; height: 0; top: -32px; /* 三角形の高さを2倍した値 */ left: 32px; border: 16px solid transparent; border-bottom: 16px solid #ccc; } #sample3 p { position: absolute; font-size: 15px; top: -12px; left: 8px; color: #000; } #sample4 div { position:absolute; width: 150px; /* 吹き出しの幅 */ height: 30px; /* 吹き出しの高さ */ top: -36px; /* 吹き出しと三角形の高さをプラスした値 */ left: 0px; border-radius: 10px 10px 10px 10px; background-color: #ccc; display: none; } #sample4 div:after { /* 三角形を作成 */ position: absolute; content: ""; width: 0; height: 0; top: 30px; /* 吹き出しの高さと同じ値 */ left: 32px; border: 16px solid transparent; border-top: 16px solid #ccc; } #sample4 p { font-size: 15px; position: absolute; top: -10px; left: 8px; color: #000; } #sample3:hover div, #sample4:hover div { z-index: 2; display: block; }