这是您可以做到的一种方法:http: //jsfiddle.net/yJ8wh/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.image {position: relative; text-align: center;}
.image span {position: absolute; line-height: 20px; display: block; top: 50%; margin-top: -10px; width: 100%; color: white;}
img.ri
{
position: relative;
max-width: 75%;
display: inline-block;
vertical-align: middle;
}
@media screen and (orientation: portrait) {
img.ri { max-width: 90%; }
}
@media screen and (orientation: landscape) {
img.ri { max-height: 90%; }
}
img#hv {
filter: url(filters.svg#grayscale); /* Firefox 3.5+ */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(1); /* Google Chrome & Safari 6+ */
}
img#hv:hover {
filter: none;
-webkit-filter: grayscale(0);}
</style>
</head>
<body>
<div class="image">
<img src="http://static.inqmind.co/content/2013/05/aap-mob-always-strive-and-prosper/feature.jpg" class="ri" id="hv">
<span>ASAP ROCKY - Jack New City</span>
</div>
</body>
</html>
如果您想让所有内容保持对齐,这里有另一个选择:http: //jsfiddle.net/DqCuA/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.image {position: relative; text-align: center;}
.image b {display: block;position: absolute;line-height: 20px; top: 50%; margin-top: -10px; width: 100%; color: white; font-weight: normal;}
img.ri
{
position: relative;
max-width: 75%;
vertical-align: middle;
}
@media screen and (orientation: portrait) {
img.ri { max-width: 90%; }
}
@media screen and (orientation: landscape) {
img.ri { max-height: 90%; }
}
img#hv {
filter: url(filters.svg#grayscale); /* Firefox 3.5+ */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(1); /* Google Chrome & Safari 6+ */
}
img#hv:hover {
filter: none;
-webkit-filter: grayscale(0);}
</style>
</head>
<body>
<span class="image">
<img src="http://static.inqmind.co/content/2013/05/aap-mob-always-strive-and-prosper/feature.jpg" class="ri" id="hv">
<b>ASAP ROCKY - Jack New City</b>
</span>
</body>
</html>