html - :hover working on half the element 上的 CSS3 转换

标签 html css

当用户将鼠标悬停在元素上时,我试图让一个简单的正方形稍微向左旋转。我正在围绕 Y 轴旋转元素。当我将鼠标悬停在元素上时,看起来元素的左半部分正确地抬起了悬停。当您尝试将鼠标悬停在右侧时,这很古怪。我知道这肯定与我的转换中的某些东西有关。希望有更多经验的人能够发现它。

更新: 我在这里发现了一个类似的问题,但不知道他们在答案中的意思。如果我从它工作的容器元素中删除高度/宽度。但为什么? :hover works only on lower part of rotateX transformed div

HTML:

<div class='container'>
  <div class='tile'>
          Tile
  </div>
</div>

CSS:

   .tile
    {
        border: 1px solid black;
        width: 100px;
        height: 100px;
        box-shadow: 2px 2px 5px #888888;
        border-radius: 12px;
        -moz-transition: all .5s linear;
        -o-transition: all .5s linear;
        -webkit-transition: all .5s linear;
        transition: all .5s linear;
        -webkit-transform-style: preserve-3d;
        transform-style: preserve-3d;
        position: absolute;
    }

        .tile:hover
        {
            -webkit-transform: rotateY(25deg);
            transform: rotateY(25deg);
            box-shadow: 10px 10px 5px #888888;
        }

    .container
    {
        position: relative;
        margin: 10px auto;
        width: 450px;
        height: 281px;
    }

http://codepen.io/cgatian/pen/lDejJ?editors=110

最佳答案

将悬停从 .title 更改为 .container。随着 .title 的移动,悬停区域会改变形状/位置并导致悬停。

http://jsbin.com/ripicesu/1/edit

CSS

.tile
{
    border: 1px solid black;
    width: 100px;
    height: 100px;
    box-shadow: 2px 2px 5px #888888;
    border-radius: 12px;
    -moz-transition: all .5s linear;
    -o-transition: all .5s linear;
    -webkit-transition: all .5s linear;
    transition: all .5s linear;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    position: absolute;
}

   li:hover .tile
    {
        -webkit-transform: rotateY(25deg);
        transform: rotateY(25deg);
        box-shadow: 10px 10px 5px #888888;
    }

.container
{
    position: relative;
    margin: 10px auto;
    width: 100px;
    height: 100px;
}

li {
  list-style-type: none;
  display: block;
  width: 100px;
  height: 100px;
}

HTML

<div class='container'>
  <ul>
    <li><div class='tile'>Tile</div></li>
    <li><div class='tile'>Tile</div></li>
    <li><div class='tile'>Tile</div></li>
    <li><div class='tile'>Tile</div></li>
  </ul>
</div>

关于html - :hover working on half the element 上的 CSS3 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24919235/

相关文章:

html - CSS3 样式的复选框 - 尝试缩进/左对齐复选框右侧的标签文本

html - 内容器上的滚动条盖

html - ASP.NET MVC 如何将 html 标签显示为 html?

jquery - jquery 事件的调用顺序是什么?

css - Bootstrap 4 响应式导航栏可折叠按钮

height - 旋转后调整div宽度和高度

javascript - JS 淡入和引导 |发出自动计算剩余 % 边距

CSS 布局高度

css - Joomla Gantry css/less 结构

java - 谷歌地图上的黑色方 block