2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: bad87fee1347bd9aedf08845
|
|
|
|
|
title: Ditch Custom CSS for Bootstrap
|
|
|
|
|
challengeType: 0
|
2020-09-07 16:17:39 +08:00
|
|
|
|
forumTopicId: 17565
|
|
|
|
|
localeTitle: 用 Bootstrap 来取代我们之前的自定义样式
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-09-07 16:17:39 +08:00
|
|
|
|
<section id='description'>
|
|
|
|
|
现在我们可以清理一下之前代码,用 Bootstrap 的内置样式来替换我们之前定义的样式,这样会让我们的 Cat Photo App 看起来更简洁些。
|
|
|
|
|
别担心————以后我们会有大把时间来自定义我们的 CSS 样式的。
|
|
|
|
|
删除 <code>style</code> 元素里的 <code>.red-text</code>, <code>p</code>, 和 <code>.smaller-image</code> CSS 声明,使 <code>style</code> 元素留下的声明只有 <code>h2</code> 和 <code>thick-green-border</code>.
|
|
|
|
|
删除包含死链接的 <code>p</code> 元素。 然后将 <code>h2</code> 的 <code>red-text</code> class 替换为 Bootstrap 的 <code>text-primary</code> class.
|
|
|
|
|
最后, 将你第一个 <code>img</code> 元素的 "smaller-image" class 替换为 <code>img-responsive</code> class.
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-09-07 16:17:39 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-09-07 16:17:39 +08:00
|
|
|
|
- text: h2 元素的 class 不应为 <code>red-text</code>。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(!$("h2").hasClass("red-text"));
|
2020-09-07 16:17:39 +08:00
|
|
|
|
- text: h2 元素的 class 应为 <code>text-primary</code>。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert($("h2").hasClass("text-primary"));
|
2020-09-07 16:17:39 +08:00
|
|
|
|
- text: 你的段落元素(p)应该不再使用 <code>Monospace</code> 字体。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(!$("p").css("font-family").match(/monospace/i));
|
2020-09-07 16:17:39 +08:00
|
|
|
|
- text: 移除你第一张图片的 class 属性 <code>smaller-image</code>。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert(!$("img").hasClass("smaller-image"));
|
2020-09-07 16:17:39 +08:00
|
|
|
|
- text: 给你的第一张图片添加 class 属性 <code>img-responsive</code>。
|
2020-02-18 01:40:55 +09:00
|
|
|
|
testString: assert($(".img-responsive").length > 1);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
|
|
```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>
|
2020-07-15 02:55:06 -07:00
|
|
|
|
<form action="https://freecatphotoapp.com/submit-cat-photo">
|
2018-10-10 18:03:03 -04:00
|
|
|
|
<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>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
2020-09-07 16:17:39 +08: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="/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>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2020-09-07 16:17:39 +08:00
|
|
|
|
</section>
|