freeCodeCamp/curriculum/challenges/chinese-traditional/01-responsive-web-design/applied-visual-design/adjust-the-width-of-an-elem...

116 lines
2.6 KiB
Markdown
Raw Normal View History

---
id: 587d7791367417b2b2512ab4
title: 使用 width 屬性調整元素的寬度
challengeType: 0
videoUrl: 'https://scrimba.com/c/cvVLPtN'
forumTopicId: 301039
dashedName: adjust-the-width-of-an-element-using-the-width-property
---
# --description--
你可以使用 CSS 裏的 `width` 屬性來指定元素的寬度。 屬性值可以是相對單位(比如 `em`),絕對單位(比如 `px`),或者包含塊(父元素)寬度的百分比。 下面這段代碼可以把圖片的寬度設置爲 220px
```css
img {
width: 220px;
}
```
# --instructions--
爲卡片元素添加 `width` 屬性,並將它的寬度設置爲 245px。 使用 `fullCard` class 來選擇卡片元素。
# --hints--
應使用 `fullCard` class 選擇器將卡片的 `width` 屬性值設置爲 `245px`
```js
const fullCard = code.match(/\.fullCard\s*{[\s\S]+?[^}]}/g);
assert(
fullCard &&
/width\s*:\s*245px\s*(;|})/gi.test(fullCard[0]) &&
$('.fullCard').css('maxWidth') === 'none'
);
```
# --seed--
## --seed-contents--
```html
<style>
h4 {
text-align: center;
}
p {
text-align: justify;
}
.links {
margin-right: 20px;
text-align: left;
}
.fullCard {
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;
}
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>
```