300x300の画像の上にhoverすると画像上にぴったりキャプションを表示させたいです。
ulのwidth、heightには.column imgのmargin:10px;を加味して、320pxにしています。
それが原因して、キャプションがulの320px分に広がってしまいます。
この場合どうすれば画像の300pxぴったりに表示できるのでしょうか?
画像にposition:relative;を設定したもののうまくいきませんでした。
アドバイスいただけると助かります。
html
1<!DOCTYPE HTML> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>キャプション</title> 6<link rel='stylesheet' href='css/style2.css'> 7</head> 8 9<body> 10 <div class='column'> 11 <ul> 12 <li id='figure'> 13 <a href='#'> 14 <img src="img/pict300x300.png"> 15 <div id='cap1'> 16 <h3>タイトル</h3> 17 <p>テキストテキスト</p> 18 </div> 19 </a> 20 </li><!--#figure--> 21 </ul> 22 </div><!--.column--> 23</body> 24</html>
css
1@charset "utf-8"; 2html,body,ul,li,p,h3{ 3 padding:0; 4 margin:0; 5} 6 7ul{list-style:none;} 8a{text-decoration:none;} 9.column img{ 10 float:left; 11 margin:10px; 12} 13ul{ 14 width:320px; 15 height: 320px; 16 overflow:hidden; 17 margin:0 auto; 18 } 19ul li#figure{ 20 display: block; 21 position: relative; 22 overflow: hidden; 23 padding:0; 24 margin:0; 25 width: 300px;/*画像の幅と同じ*/ 26} 27#cap1 { 28 position: absolute; 29 left:0; 30 bottom:-100%; 31 z-index: 2; 32 width: 100%; 33 height: 100%; 34 background: rgba(0,0,0,0.3); 35 transition: 1s; 36 -webkit-transition: .3s; 37 opacity: 0; 38} 39ul li#figure a:hover #cap1 { 40 position:absolute; 41 opacity: 1; 42 bottom:0; 43}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/14 14:47