2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 587d7791367417b2b2512ab4
|
|
|
|
|
title: Adjust the Width of an Element Using the width Property
|
|
|
|
|
challengeType: 0
|
2020-02-11 15:46:34 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/c/cvVLPtN'
|
|
|
|
|
forumTopicId: 301039
|
|
|
|
|
localeTitle: 使用 width 属性调整元素的宽度
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-02-11 15:46:34 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
你可以使用 CSS 里面的 <code>width</code> 属性来指定元素的宽度。属性值可以是相对单位(比如 em),绝对单位(比如 px),或者包含块(父元素)宽度的百分比。下面这个例子把图片的宽度设置为 220px:
|
|
|
|
|
|
|
|
|
|
```css
|
|
|
|
|
img {
|
|
|
|
|
width: 220px;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-02-11 15:46:34 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
给卡片添加 <code>width</code> 属性,设置它的宽度为 245px。使用 <code>fullCard</code> class 来选择元素。
|
|
|
|
|
</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>fullCard</code> class 选择器将卡片的 <code>width</code> 宽度属性更改为 <code>245px</code>。'
|
|
|
|
|
testString: 'assert(code.match(/.fullCard\s*{[\s\S][^}]*\n*^\s*width\s*:\s*245px\s*;/gm), ''你应该使用 <code>fullCard</code> class 选择器将卡片的 <code>width</code> 宽度属性更改为 <code>245px</code>。'');'
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
h4 {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
p {
|
|
|
|
|
text-align: justify;
|
|
|
|
|
}
|
|
|
|
|
.links {
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
text-align: left;
|
|
|
|
|
}
|
|
|
|
|
.fullCard {
|
2020-02-11 15:46:34 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
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>
|
2020-02-11 15:46:34 +08:00
|
|
|
|
<p>Google 由在斯坦福大学攻读理工博士的拉里·佩奇和谢尔盖·布林共同创建。</p>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</div>
|
|
|
|
|
<div class="cardLinks">
|
2020-02-11 15:46:34 +08:00
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">拉里·佩奇</a>
|
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">谢尔盖·布林</a>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</div>
|
|
|
|
|
</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
|
|
|
|
|