2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: 587d78a5367417b2b2512ad9
|
2020-12-16 07:37:30 +00:00
|
|
|
title: 使用 CSS Transform scale 属性可以更改元素的大小
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 0
|
2020-02-11 07:46:34 +00:00
|
|
|
videoUrl: 'https://scrimba.com/c/c2MZVSg'
|
|
|
|
forumTopicId: 301076
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: use-the-css-transform-scale-property-to-change-the-size-of-an-element
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-01-08 19:20:48 +00:00
|
|
|
CSS 属性 `transform` 里面的 `scale()` 函数可以用来改变元素的显示比例。下面的例子把页面的 `p` 元素放大到了原来的 2 倍:
|
2020-02-11 07:46:34 +00:00
|
|
|
|
|
|
|
```css
|
|
|
|
p {
|
|
|
|
transform: scale(2);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --instructions--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
把 id 为 `ball2` 的元素放大到原始大小的 1.5 倍。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --hints--
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
`#ball2` 的 `transform` 属性应该为原始大小的 1.5 倍。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(
|
|
|
|
code.match(
|
|
|
|
/#ball2\s*?{\s*?left:\s*?65%;\s*?transform:\s*?scale\(1\.5\);\s*?}|#ball2\s*?{\s*?transform:\s*?scale\(1\.5\);\s*?left:\s*?65%;\s*?}/gi
|
|
|
|
)
|
|
|
|
);
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
.ball {
|
|
|
|
width: 40px;
|
|
|
|
height: 40px;
|
|
|
|
margin: 50 auto;
|
|
|
|
position: fixed;
|
|
|
|
background: linear-gradient(
|
|
|
|
35deg,
|
|
|
|
#ccffff,
|
|
|
|
#ffcccc
|
|
|
|
);
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
#ball1 {
|
|
|
|
left: 20%;
|
|
|
|
}
|
|
|
|
#ball2 {
|
|
|
|
left: 65%;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<div class="ball" id= "ball1"></div>
|
|
|
|
<div class="ball" id= "ball2"></div>
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
2020-02-11 07:46:34 +00:00
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```html
|
|
|
|
<style>
|
|
|
|
.ball {
|
|
|
|
width: 40px;
|
|
|
|
height: 40px;
|
|
|
|
margin: 50 auto;
|
|
|
|
position: fixed;
|
|
|
|
background: linear-gradient(
|
|
|
|
35deg,
|
|
|
|
#ccffff,
|
|
|
|
#ffcccc
|
|
|
|
);
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
#ball1 {
|
|
|
|
left: 20%;
|
|
|
|
}
|
|
|
|
#ball2 {
|
|
|
|
left: 65%;
|
|
|
|
transform: scale(1.5);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="ball" id= "ball1"></div>
|
|
|
|
<div class="ball" id= "ball2"></div>
|
|
|
|
```
|