【发布时间】:2016-07-24 01:35:30
【问题描述】:
我正在尝试将鼠标悬停在一个元素上,使其增大几个百分点,但我希望标题和里面的内容保持原样。如果我只是将scale(1.05) 添加到元素中,内容也会缩放。如果我尝试使用scale(0.95) 对内部元素进行反缩放,则大小将与原始元素相同,但位置将不同:
.container {
display: block;
width: 100%;
padding: 50px;
}
.element {
height: 562px;
width: 590px;
display: inline-block;
position: relative;
-webkit-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
background-image: url(https://images.unsplash.com/photo-1451906278231-17b8ff0a8880?crop=entropy&fit=crop&fm=jpg&h=975&ixjsv=2.1.0&ixlib=rb-0.3.5&q=80&w=1925);
background-size: cover;
background-position: center center;
}
.title {
font-size: 45px;
line-height: 48px;
bottom: 10%;
position: absolute;
margin: 0 25px;
color: #fff;
text-shadow: 0 2px 0 rgba(0, 0, 0, 0.14);
font-weight: 700;
font-family: sans-serif;
-webkit-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
.element:hover {
transform: scale(1.05);
z-index: 10;
}
.element:hover .title {
transform: scale(0.95);
}
<div class="container">
<div class="element">
<div class="title">This is the big title.</div>
</div>
</div>
里面的内容是绝对放置的,所以我可能不得不通过指定bottom 和left 属性来修复它,但我认为内部元素仍然会有一些过渡。
有没有办法解决这个问题?只是为了扩展元素而不影响内容?
【问题讨论】:
标签: html css hover css-transitions css-transforms