CSS 技能测试:基本布局理解

题目链接

题目要求:

  1. 在一行中显示导航选项,并且选项之间拥有相同的空间。
  2. 导航条应随着内容一起滚动并且在触碰到视口顶部之后于顶部固定。
  3. 文章内的图片应该被文本包围。
  4. articleaside 元素应该为双列布局。它们的列尺寸应该是弹性的,以便在浏览器窗口收缩得更小的时候能够变窄。
  5. 照片应显示为两列网格,图像之间有 1 像素的间隙。

HTML 代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Layout Task</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>

<div class="logo">
My exciting website!
</div>

<nav>
<ul>
<li>
<a href="">Home</a>
</li>
<li>
<a href="">Blog</a>
</li>
<li>
<a href="">About us</a>
</li>
<li>
<a href="">Our history</a>
</li>
<li>
<a href="">Contacts</a>
</li>
</ul>
</nav>

<main class="grid">
<article>
<h1>
An Exciting Blog Post
</h1>
<img src="images/balloon-sq6.jpg" alt="placeholder" class="feature">
<p>Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion daikon amaranth tatsoi tomatillo melon
azuki bean garlic.</p>

<p>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens
dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</p>

<p>Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon
napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko.
Lotus root water spinach fennel kombu maize bamboo shoot green bean swiss chard seakale pumpkin onion chickpea gram
corn pea. Brussels sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot carrot watercress.
Corn amaranth salsify bunya nuts nori azuki bean chickweed potato bell pepper artichoke.</p>

<p>Nori grape silver beet broccoli kombu beet greens fava bean potato quandong celery. Bunya nuts black-eyed pea prairie
turnip leek lentil turnip greens parsnip. Sea lettuce lettuce water chestnut eggplant winter purslane fennel azuki
bean earthnut pea sierra leone bologi leek soko chicory celtuce parsley jícama salsify.</p>

<p>Celery quandong swiss chard chicory earthnut pea potato. Salsify taro catsear garlic gram celery bitterleaf wattle
seed collard greens nori. Grape wattle seed kombu beetroot horseradish carrot squash brussels sprout chard.</p>

</article>

<aside>
<h2>
Photography
</h2>
<ul class="photos">
<li>
<img src="images/balloon-sq1.jpg" alt="placeholder">
</li>
<li>
<img src="images/balloon-sq2.jpg" alt="placeholder">
</li>
<li>
<img src="images/balloon-sq3.jpg" alt="placeholder">
</li>
<li>
<img src="images/balloon-sq4.jpg" alt="placeholder">
</li>
<li>
<img src="images/balloon-sq5.jpg" alt="placeholder">
</li>
</ul>

</aside>
</main>

</body>

</html>

CSS 代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
body {
background-color: #fff;
color: #333;
margin: 0;
font: 1.2em / 1.2 Arial, Helvetica, sans-serif;
}

img {
max-width: 100%;
display: block;
}

.logo {
font-size: 200%;
padding: 50px 20px;
margin: 0 auto;
max-width: 980px;
}

.grid {
margin: 0 auto;
padding: 0 20px;
max-width: 980px;
}

nav {
background-color: #000;
padding: .5em;
position: sticky;
top: 0;
}

nav ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}

nav a {
color: #fff;
text-decoration: none;
padding: .5em 1em;
}

.photos {
list-style: none;
margin: 0;
padding: 0;
}

.feature {
width: 200px;
}

article img {
float: left;
margin-right: 10px;
}
.grid {
display: grid;
grid-template-columns: 2fr 1fr;
grid-gap: 40px;
}
.photos {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 1px;
}