html - 使用 CSS,如何在鼠标悬停在元素上时创建更大的元素?

标签 html css dropshadow

看到的效果是,当鼠标悬停在盒子上时,盒子会变大,并且还有阴影。

当鼠标不在框上时,它们会恢复到相同大小且没有阴影。

正常:

enter image description here

鼠标悬停:

enter image description here

滚动框查看效果 here .

最佳答案

jsFiddle DEMO

可以通过多种方式将鼠标悬停在元素上并使它们变大,这取决于您的布局要求和您使用的框架。

因为这些盒子看起来是带有 CSS3 盒子阴影属性的 div,你可以在纯 CSS 中使用 :hover 做类似的事情

HTML:

<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>

CSS:

body {
  background-color: black;
}

.box {
  background-color: grey;
  width: 200px;
  height: 400px;
  float: left;
  border: 6px solid red;
  margin: 10px;
}

.box:hover{
  width: 250px;
  /* This is 52px total. 1/2 of that is for top and the other half is for bottom. */
  height: 452px;
  /* Below we are not using -26px for margin-top because .box has 6px border and 10px margin. */
  /* That 16px is then divide by 2 since it's for both top and bottom, or 8px per side. */
  /* Having said that, 26px - 8px is 18px. We need negative value to position it correctly. */
  margin-top: -18px;
 -moz-box-shadow:    0 0 50px red;
 -webkit-box-shadow: 0 0 50px red;
 box-shadow:         0 0 50px red;    
}

编辑 2:

Revised jsFiddle DEMO

enter image description here

关于html - 使用 CSS,如何在鼠标悬停在元素上时创建更大的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14130543/

相关文章:

javascript - 有没有办法在 JS 中一次更改几个图像的 src?

javascript - 将文本超链接翻转为图像

css - Sass/Compass 编译时不做数学运算

javascript - 父级点击触发事件,子级不触发

Jquery 打开和关闭按钮单击

html - 无法在 css 中设置图像样式

javascript - 更改 Bootstrap 下拉菜单的方向

filter - 有什么理由在投影上使用 css box-shadow 吗?

css - 滤镜阴影导致图像模糊

ios - 如何在拖动时删除单元格的阴影?