jquery - 使悬停图像对齐中心

标签 jquery html css image

我将以下 css 代码用于我的 html 文件, 悬停时出现的图像位于左上角,如何使其居中?

这是html代码

<a class="thumbnail" href="#thumb">View Sample
  <span>
    <img src="images/1.png" /><br>Simply beautiful.
  </span>
</a>

这是CSS代码

.gallerycontainer{
position: relative;
/*Add a height attribute and set to largest image's height to prevent overlaying*/
}

.thumbnail img{

}

.thumbnail:hover{
background-color: transparent;
}

.thumbnail:hover img{

}

.thumbnail span{ /*CSS for enlarged image*/
position: absolute;
background-color: #F0F0F0 ;
border-radius: 20px;
padding: 0px;


visibility: hidden;
color: black;
text-decoration: none;
}

.thumbnail span img{ /*CSS for enlarged image*/
border-width: 10;

padding: 2px;
}

.thumbnail:hover span{ /*CSS for enlarged image*/
visibility: visible;
top: 0;
left: 230px; /*position where enlarged image should offset horizontally */
z-index: 50;
}

最佳答案

在这里查看我的 jsfiddle:http://jsfiddle.net/93863/7/

我添加的CSS:-

.thumbnail:hover span
{
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    margin-top: -194px;    /* Half of the popups height */
    margin-left: -190px;   /* Half of the popups width */
}

关于jquery - 使悬停图像对齐中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21752202/

相关文章:

javascript - jQuery:单击*仅*此元素

javascript - 我的 jQuery 图像预加载器功能可以工作吗?

javascript - 在 jQuery 的 css() 函数中使用 !important

html - 如何让包装器在我的网页的 CSS 上工作?

html - 无法弄清楚内联显示?

css - React - 使用三元在功能组件中应用 CSS 类

css - 通过添加类触发的 css3 动画中不需要的延迟

javascript - 未捕获的类型错误 : Object #<HTMLBodyElement> has no method 'css'

html - 如何使用显示垂直对齐网格元素:grid and fill all vertical empty space?

javascript - 使用 javascript 和 php 循环 Div