2016-10-14 1 views
1

안녕하세요 img 내부에 img의 제목 태그가 필요합니다. 이 예 http://jsfiddle.net/51csqs0b/호버 안에 제목 태그 표시 img

.image { 
 
    position:relative; 
 
    width:200px; 
 
    height:200px; 
 
} 
 
.image img { 
 
    width:100%; 
 
    vertical-align:top; 
 
} 
 
.image:after, .image:before { 
 
    position:absolute; 
 
    opacity:0; 
 
    transition: all 0.5s; 
 
    -webkit-transition: all 0.5s; 
 
} 
 
.image:after { 
 
    content:'\A'; 
 
    width:100%; height:100%; 
 
    top:0; left:0; 
 
    background:rgba(0,0,0,0.6); 
 
} 
 
.image:before { 
 
    content: attr(data-content); 
 
    width:100%; 
 
    color:#fff; 
 
    z-index:1; 
 
    bottom:0; 
 
    padding:4px 10px; 
 
    text-align:center; 
 
    background:red; 
 
    box-sizing:border-box; 
 
    -moz-box-sizing:border-box; 
 
} 
 
.image:hover:after, .image:hover:before { 
 
    opacity:1; 
 
}
<div data-content="Here is a caption" class="image"> 
 
    <img src="http://i.stack.imgur.com/Sjsbh.jpg" alt="" /> 
 
</div> 
 

 
<hr> 
 
    
 
<div data-content="Different caption here..." class="image"> 
 
    <img src="http://i.stack.imgur.com/Sjsbh.jpg" alt="" /> 
 
</div>

하지만 IMG 전에 사업부를 사용하지 않으처럼

.

<a href="#"><img class="" title="TITLE NEED SHOW ON HOVER" src=""/></a> 

표시 할 수 있습니까?

.image 클래스

<a class="image" href="#"><img src="http://i.stack.imgur.com/Sjsbh.jpg" class="" title="TITLE NEED SHOW ON HOVER" src=""/></a> 

a하려면 CSS에서 titledata-content 교체 추가 : 감사

+2

예 가능합니다. 당신은 이미 무엇을 시도 했습니까? 코드를 공유 할 수 있습니까? – RST

+1

관련이없는 경우 : http://stackoverflow.com/questions/8661498/on-image-hover-display-title-alt-tag-in-center –

+0

@RST 안녕하세요, 답변이 제대로 작동하는지 확인해 볼 수 있습니다. 그 코드 –

답변

1

이것은 내가 할 수있는 일이 마지막으로

.image:before { 
    content: attr(title); 
    width:100%; 
    color:#fff; 
    z-index:1; 
    bottom:0; 
    padding:4px 10px; 
    text-align:center; 
    background:red; 
    box-sizing:border-box; 
    -moz-box-sizing:border-box; 
} 

이 jQuery 코드를 추가 :

$("a.image").each(function(){$(this).attr('title',$(this).find("img").attr('title'))}); 

실행 스스로 here 다음은

+0

예. 고마워 천재 야 !! 나는 그것을하는 것에 대해 생각했다. 그러나 나는 Jquery의 일부를 놓쳤다!! 예 :-) –

0

는 쉬운 방법입니다. 마우스를 올리면 pseudoelement를 사용합니다. Pure CSS solution

<a href="" class="img"></a> 

.img{ 
    display: block; 
    width:200px; 
    height:200px; 
    background: url('http://i.stack.imgur.com/Sjsbh.jpg'); 
    background-size: 200px 200px; 
    position: relative; 
} 
.img:hover::after { 
    content:'This is a description'; 
    position: absolute; 
    width:100%; 
    height:20%; 
    bottom:0; left:0; 
    background: rgba(255, 255, 255, 0.8); 
} 

당신은 매우 구체적인하지 않습니다. 나는 그것이 도움이되기를 바랍니다. 툴팁을 만들 수도 있습니다.

+0

네,하지만이 방법으로 콘텐츠를 작성하지 않아도됩니다. 내가 다른 제목이지만 같은 클래스와 함께 많은 img와해야하기 때문에 attr (title)을 사용하고 싶다. 어쨌든 감사합니다! –