2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 587d78a5367417b2b2512ada
|
|
|
|
challengeType: 0
|
2020-02-11 15:46:34 +08:00
|
|
|
videoUrl: 'https://scrimba.com/c/cyLPJuM'
|
|
|
|
forumTopicId: 301077
|
|
|
|
localeTitle: 使用CSS Transform scale 属性在悬停时缩放元素
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-02-11 15:46:34 +08:00
|
|
|
<section id='description'>
|
|
|
|
<code>transform</code> 属性有很多函数,可以对元素进行调整大小、移动、旋转、翻转等操作。当使用伪类描述元素的指定状态如 <code>:hover</code> 时,<code>transform</code> 属性可以方便的给元素添加交互。
|
|
|
|
下面是当用户悬停段落元素时,段落大小缩放到原始大小 2.1 倍的例子:
|
|
|
|
|
|
|
|
```css
|
|
|
|
p:hover {
|
|
|
|
transform: scale(2.1);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
<strong>注意:</strong> 给 <code>div</code> 元素添加 transform 也会影响这个 div 包裹的子元素。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
2020-02-11 15:46:34 +08:00
|
|
|
<section id='instructions'>
|
|
|
|
给 <code>div</code> 伪类 <code>hover</code> 添加 <code>transform</code> 属性,使其当鼠标悬停时大小缩放到原始大小的 1.1 倍。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
2020-02-11 15:46:34 +08:00
|
|
|
- text: '<code>div</code> 元素在悬停时大小应该缩放到原始大小的 1.1 倍。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(code.match(/div:hover\s*?{\s*?transform:\s*?scale\(1\.1\);/gi));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style>
|
2020-02-11 15:46:34 +08:00
|
|
|
div {
|
2018-10-10 18:03:03 -04:00
|
|
|
width: 70%;
|
|
|
|
height: 100px;
|
|
|
|
margin: 50px auto;
|
|
|
|
background: linear-gradient(
|
|
|
|
53deg,
|
|
|
|
#ccfffc,
|
|
|
|
#ffcccf
|
|
|
|
);
|
|
|
|
}
|
2020-02-11 15:46:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
</style>
|
|
|
|
|
|
|
|
<div></div>
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
2020-02-11 15:46:34 +08:00
|
|
|
|
|
|
|
```html
|
2018-10-10 18:03:03 -04:00
|
|
|
// solution required
|
|
|
|
```
|
2020-02-11 15:46:34 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
</section>
|
2020-02-11 15:46:34 +08:00
|
|
|
|