CSS 技能测试:响应式设计与媒体查询

题目链接

题目要求:用响应式设计为移动端网站设计一个桌面端的界面。

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
91
92
93
94
95
96
97
98
99
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Responsive Web Design Task: Task</title>
<link rel="stylesheet" href="../styles.css" />
</head>

<body>
<header>
<div class="title">My Website</div>
<nav>
<ul>
<li>
<a href="">Link 1</a>
</li>
<li>
<a href="">Link 2</a>
</li>
<li>
<a href="">Link 3</a>
</li>
</ul>
</nav>
</header>

<main>
<article>
<h1>This is the main heading</h1>
<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>

<ul class="cards">
<li>
<h2>Card One</h2>
<div class="inner">
<p>
Turnip greens yarrow ricebean rutabaga endive cauliflower sea
lettuce kohlrabi amaranth water spinach avocado.
</p>
</div>
</li>
<li>
<h2>Card Two</h2>
<div class="inner">
<p>
Daikon napa cabbage asparagus winter purslane kale. Celery
potato scallion desert raisin horseradish spinach carrot soko.
</p>
</div>
</li>
<li>
<h2>Card Three</h2>
<div class="inner">
<p>
Lotus root water spinach fennel kombu maize bamboo shoot green
bean swiss chard seakale pumpkin onion chickpea gram corn pea.
</p>
</div>
</li>
<li>
<h2>Card Four</h2>
<div class="inner">
<p>
Lotus root water spinach fennel kombu maize bamboo shoot green
bean swiss chard seakale pumpkin onion chickpea gram corn pea.
</p>
</div>
</li>
<li>
<h2>Card Five</h2>
<div class="inner">
<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.
</p>
</div>
</li>
</ul>
</article>
<aside class="sidebar">
<p>
Have you discovered all of the other excellent content on this
website?
</p>
</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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
* {
box-sizing: border-box;
}

html {
font:
1.2em/1.4 Arial,
Helvetica,
sans-serif;
}

body {
padding: 0 0 1em;
}

header {
background-color: #333;
color: #fff;
border: 5px solid #000;
}

header ul {
list-style: none;
margin: 0;
padding: 0;
}

header a {
color: #fff;
text-decoration: none;
display: block;
padding: 0.5em 1em;
border-top: 1px solid #999;
}

header .title {
font-size: 150%;
font-style: italic;
font-weight: bold;
padding: 1em;
}

main {
padding: 0 1em;
}

.cards {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 20px;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.cards li {
border: 5px solid #000;
margin-bottom: 1em;
}

.cards h2 {
background-color: #333;
color: #fff;
margin: 0;
padding: 0.5em 1em;
}

.cards .inner {
padding: 0.5em 1em;
}

.sidebar {
background-color: #333;
border: 5px solid #000;
padding: 0.5em 1em;
color: #fff;
}
@media (min-width: 576px)
{
header
{
display: flex;
position: relative;
}
header nav ul
{
display: flex;
flex-direction: row;
position: absolute;
right:0;
top: 20%;
}
header a{
border: none;
}
main {
display: grid;
grid-template-columns: 3fr 1fr;
grid-gap: 20px;
margin-top: 20px;
}
}