2021-05-05 10:13:49 -07:00
|
|
|
|
---
|
|
|
|
|
id: 587d7791367417b2b2512ab5
|
|
|
|
|
title: 使用 height 屬性調整元素的寬度
|
|
|
|
|
challengeType: 0
|
|
|
|
|
videoUrl: 'https://scrimba.com/c/cEDaDTN'
|
|
|
|
|
forumTopicId: 301034
|
|
|
|
|
dashedName: adjust-the-height-of-an-element-using-the-height-property
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
|
|
|
|
|
和 `width` 屬性類似,你可以使用 CSS 裏面的 `height` 屬性來指定元素的高度。 下面這段代碼可以把圖片的高度設置爲 20px:
|
|
|
|
|
|
|
|
|
|
```css
|
|
|
|
|
img {
|
|
|
|
|
height: 20px;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
|
|
|
|
|
給 `h4` 標籤添加 `height` 屬性並將屬性值設置爲 25px。
|
|
|
|
|
|
2021-08-25 09:12:11 -07:00
|
|
|
|
**注意:** 可能需要將瀏覽器的縮放比調整爲 100% 才能通過這一挑戰。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
|
|
|
|
`h4` 的 `height` 屬性值應爲 25px。
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert(
|
|
|
|
|
Math.round(document.querySelector('h4').getBoundingClientRect().height) ===
|
|
|
|
|
25 &&
|
|
|
|
|
/h4{\S*height:25px(;\S*}|})/.test($('style').text().replace(/\s/g, ''))
|
|
|
|
|
);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
h4 {
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
p {
|
|
|
|
|
text-align: justify;
|
|
|
|
|
}
|
|
|
|
|
.links {
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
text-align: left;
|
|
|
|
|
}
|
|
|
|
|
.fullCard {
|
|
|
|
|
width: 245px;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
margin: 10px 5px;
|
|
|
|
|
padding: 4px;
|
|
|
|
|
}
|
|
|
|
|
.cardContent {
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<div class="fullCard">
|
|
|
|
|
<div class="cardContent">
|
|
|
|
|
<div class="cardText">
|
|
|
|
|
<h4>Google</h4>
|
|
|
|
|
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="cardLinks">
|
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
|
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
h4 {
|
|
|
|
|
text-align: center;
|
|
|
|
|
height: 25px;
|
|
|
|
|
}
|
|
|
|
|
p {
|
|
|
|
|
text-align: justify;
|
|
|
|
|
}
|
|
|
|
|
.links {
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
text-align: left;
|
|
|
|
|
}
|
|
|
|
|
.fullCard {
|
|
|
|
|
width: 245px;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
margin: 10px 5px;
|
|
|
|
|
padding: 4px;
|
|
|
|
|
}
|
|
|
|
|
.cardContent {
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<div class="fullCard">
|
|
|
|
|
<div class="cardContent">
|
|
|
|
|
<div class="cardText">
|
|
|
|
|
<h4>Google</h4>
|
|
|
|
|
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="cardLinks">
|
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a>
|
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|