2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
id: bad87fee1347bd9aedf08845
|
2021-03-05 02:55:32 +00:00
|
|
|
|
title: 用 Bootstrap 来取代我们之前的自定义样式
|
2018-10-10 22:03:03 +00:00
|
|
|
|
challengeType: 0
|
2020-09-07 08:17:39 +00:00
|
|
|
|
forumTopicId: 17565
|
2021-01-13 02:31:00 +00:00
|
|
|
|
dashedName: ditch-custom-css-for-bootstrap
|
2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --description--
|
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
现在可以清理一下之前代码,用 Bootstrap 的内置样式来替换之前定义的样式,这样 Cat Photo App 看起来更简洁些。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
别担心——以后会有大把时间来自定义 CSS 样式的。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
删除 `style` 元素里的 `.red-text`,`p`,和 `.smaller-image` CSS 定义,使 `style` 元素只留下 `h2` 和 `thick-green-border`。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
删除包含死链接的 `p` 元素。 然后将 `h2` 的 `red-text` class 替换为 Bootstrap 的 `text-primary` class。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
最后,从第一个 `img` 元素中删除 `smaller-image` class,并将其替换为 `img-responsive` class。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
`h2` 元素不应该有 `red-text` class。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert(!$('h2').hasClass('red-text'));
|
2018-10-10 22:03:03 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
`h2` 元素应有 `text-primary` class。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert($('h2').hasClass('text-primary'));
|
2018-10-10 22:03:03 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
段落元素(p)不应该再使用 `Monospace` 字体。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert(
|
|
|
|
|
!$('p')
|
|
|
|
|
.css('font-family')
|
|
|
|
|
.match(/monospace/i)
|
|
|
|
|
);
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
移除第一张图片的 `smaller-image` class 属性。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert(!$('img').hasClass('smaller-image'));
|
2018-10-10 22:03:03 +00:00
|
|
|
|
```
|
2020-08-13 15:24:35 +00:00
|
|
|
|
|
2021-03-05 02:55:32 +00:00
|
|
|
|
给第一张图片添加 `img-responsive` class 属性。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert($('.img-responsive').length > 1);
|
|
|
|
|
```
|
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
|
|
|
|
|
<style>
|
|
|
|
|
.red-text {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
|
font-family: Lobster, Monospace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
font-family: Monospace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thick-green-border {
|
|
|
|
|
border-color: green;
|
|
|
|
|
border-width: 10px;
|
|
|
|
|
border-style: solid;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.smaller-image {
|
|
|
|
|
width: 100px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="container-fluid">
|
|
|
|
|
<h2 class="red-text text-center">CatPhotoApp</h2>
|
|
|
|
|
|
|
|
|
|
<p>Click here for <a href="#">cat photos</a>.</p>
|
|
|
|
|
|
|
|
|
|
<a href="#"><img class="smaller-image thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
|
|
|
|
|
|
|
|
|
<img src="https://bit.ly/fcc-running-cats" class="img-responsive" alt="Three kittens running towards the camera.">
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-xs-4">
|
|
|
|
|
<button class="btn btn-block btn-primary">Like</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-xs-4">
|
|
|
|
|
<button class="btn btn-block btn-info">Info</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-xs-4">
|
|
|
|
|
<button class="btn btn-block btn-danger">Delete</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Things cats love:</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>cat nip</li>
|
|
|
|
|
<li>laser pointers</li>
|
|
|
|
|
<li>lasagna</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p>Top 3 things cats hate:</p>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>flea treatment</li>
|
|
|
|
|
<li>thunder</li>
|
|
|
|
|
<li>other cats</li>
|
|
|
|
|
</ol>
|
|
|
|
|
<form action="https://freecatphotoapp.com/submit-cat-photo">
|
|
|
|
|
<label><input type="radio" name="indoor-outdoor"> Indoor</label>
|
|
|
|
|
<label><input type="radio" name="indoor-outdoor"> Outdoor</label>
|
|
|
|
|
<label><input type="checkbox" name="personality"> Loving</label>
|
|
|
|
|
<label><input type="checkbox" name="personality"> Lazy</label>
|
|
|
|
|
<label><input type="checkbox" name="personality"> Crazy</label>
|
|
|
|
|
<input type="text" placeholder="cat photo URL" required>
|
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
|
# --solutions--
|
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
|
```html
|
|
|
|
|
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
|
|
|
|
|
<style>
|
|
|
|
|
h2 {
|
|
|
|
|
font-family: Lobster, Monospace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thick-green-border {
|
|
|
|
|
border-color: green;
|
|
|
|
|
border-width: 10px;
|
|
|
|
|
border-style: solid;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<div class="container-fluid">
|
|
|
|
|
<h2 class="text-primary text-center">CatPhotoApp</h2>
|
|
|
|
|
|
|
|
|
|
<a href="#"><img class="img-responsive thick-green-border" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
|
|
|
|
|
|
|
|
|
|
<img src="https://bit.ly/fcc-running-cats" class="img-responsive" alt="Three kittens running towards the camera.">
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-xs-4">
|
|
|
|
|
<button class="btn btn-block btn-primary">Like</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-xs-4">
|
|
|
|
|
<button class="btn btn-block btn-info">Info</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-xs-4">
|
|
|
|
|
<button class="btn btn-block btn-danger">Delete</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Things cats love:</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>cat nip</li>
|
|
|
|
|
<li>laser pointers</li>
|
|
|
|
|
<li>lasagna</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p>Top 3 things cats hate:</p>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>flea treatment</li>
|
|
|
|
|
<li>thunder</li>
|
|
|
|
|
<li>other cats</li>
|
|
|
|
|
</ol>
|
|
|
|
|
<form action="https://freecatphotoapp.com/submit-cat-photo">
|
|
|
|
|
<label><input type="radio" name="indoor-outdoor"> Indoor</label>
|
|
|
|
|
<label><input type="radio" name="indoor-outdoor"> Outdoor</label>
|
|
|
|
|
<label><input type="checkbox" name="personality"> Loving</label>
|
|
|
|
|
<label><input type="checkbox" name="personality"> Lazy</label>
|
|
|
|
|
<label><input type="checkbox" name="personality"> Crazy</label>
|
|
|
|
|
<input type="text" placeholder="cat photo URL" required>
|
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
```
|