悬停时放大图像并在其上显示文本CSS3
On hover image enlarge and text display over it CSS3
我正在尝试为我的网站制作一个响应图像页面。到目前为止,我已经做到了,所以页面上的图像都是响应的,并保持浏览器大小的中心。
我的问题是,当我把鼠标悬停在一个图像上时,它会放大,但会把所有其他图像都推掉。我希望它能放大,但所有其他图像都保持它们的位置,我尝试过绝对位置,但这不起作用。
此外,我真的很想在图像中添加悬停文本,这样当图像悬停时,你可以从中心看到文本,我只想用html/css来完成这项工作,而不需要单独的文本图像,也可能不需要javascript。
这是我当前的HTML;
<div class="imgwrap">
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
<img src="http://placehold.it/120x120" alt="DTE" />
</div>
这是我的CSS;
.imgwrap {
width:90%;
margin:0 auto;
padding:5px;
overflow:hidden;
text-align:center;
}
.imgwrap img {
display:inline-block;
width:300px;
height:200px;
margin:5px;
cursor:pointer;
-webkit-transition:opacity 0.26s ease-out;
-moz-transition:opacity 0.26s ease-out;
-ms-transition:opacity 0.26s ease-out;
-o-transition:opacity 0.26s ease-out;
transition:opacity 0.26s ease-out;
border-style:solid;
border-color:black;
border-width:1px;
padding:5px;
transition:500ms;
}
.imgwrap:hover img {
opacity:0.5;
}
.imgwrap:hover img:hover {
opacity:1;
width:400px;
height:266px;
transition:500ms;
}
@media screen and (max-width:500px) {
.imgwrap img {
width:200px;
height:133px;
}
}
这里还有一个JS fiddle,供您查看我的图像页面的实时版本http://jsfiddle.net/Z66Z9/您可能需要扩展"结果"框,以便查看我的图像页面的真实外观。
非常感谢你的帮助。
图像聚焦:使用CSS3 transform: scale
属性。
悬停文本:使用CSS中的div.wrap
和:hover
规则将文本opacity
从0更改为1。
FIDDLE
HTML:
<div id="container">
<div class="wrap">
<img src="http://lorempixel.com/output/fashion-q-g-640-480-2.jpg" alt="DTE" />
<p>Text here</p>
</div>
<div class="wrap">
<img src="http://lorempixel.com/output/city-q-c-640-480-2.jpg" alt="DTE" />
<p>Text here</p>
</div>
<div class="wrap">
<img src="http://lorempixel.com/output/sports-q-g-640-480-4.jpg" alt="DTE" />
<p>Text here</p>
</div>
<div class="wrap">
<img src="http://lorempixel.com/output/nature-q-c-640-480-8.jpg" alt="DTE" />
<p>Text here</p>
</div>
<div class="wrap">
<img src="http://lorempixel.com/output/fashion-q-c-640-480-7.jpg" alt="DTE" />
<p>Text here</p>
</div>
</div>
CSS:
#container {
text-align:center;
margin: 50px;
}
.wrap{
display:inline-block;
position:relative;
cursor:pointer;
}
.wrap p{
position:absolute;
opacity:0;
top:50%;
left:-8%;
padding:5px;
text-align:center;
width:113%;
font-size:20px;
line-height:20px;
margin-top:-10px;
z-index:3;
background:rgba(255,255,255, 0.7);
transition:1s;
}
.wrap img {
display:block;
width:300px;
height:200px;
margin:5px;
-webkit-transition:opacity 0.26s ease-out;
-moz-transition:opacity 0.26s ease-out;
-ms-transition:opacity 0.26s ease-out;
-o-transition:opacity 0.26s ease-out;
transition:opacity 0.26s ease-out;
transition:500ms;
}
#container:hover img {
opacity:0.5;
}
#container:hover .wrap:hover img {
opacity:1;
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-ms-transform: scale(1.2);
-o-transform: scale(1.2);
transform: scale(1.2);
z-index:2;
position:relative;
transition:500ms;
}
.wrap:hover p {
opacity :1;
}
@media screen and (max-width:500px) {
#container img {
width:200px;
height:133px;
}
}
相关文章:
- xmlhttp.responseText不显示文本
- 如何在MVC中使用jQuery在文本框旁边显示文本
- 根据页面的位置突出显示文本中的字符
- 当选择值x时,Javascript需要在正确的位置显示文本区域,从而循环通过具有选择选项的表单
- 操作javascript变量[HTML]以只显示文本
- 如何显示文本长度,即使它超过ng最大长度
- 如何在悬停时显示文本而不移动页面上的内容
- ASP.NET MVC,在文本框旁边显示文本
- 可单击滚动图像以显示文本框
- 使用鼠标悬停JavaScript/HTML显示文本
- 延迟高亮显示文本区域中的文本
- 选择“选择选项”时显示文本.怎么做
- 无法使用JavaScript在画布上显示文本
- 在不更改HTML源代码的情况下,在管理员TinyMCE编辑器中突出显示文本
- 将鼠标悬停在图像上时显示文本
- javascript:在for循环中使用settimeout来定期显示文本
- 一页主题搜索/用下一个按钮突出显示文本
- JavaScript 在更改选择时不显示文本区域
- 用于突出显示文本的JQuery/JavaScript插件
- 模式显示文本区域内容不是字符串