練習用のHTML・CSS
本文のコード例を章ごとに掲載しています。コードは本文と同じ内容です。各例のファイルを保存してブラウザーで開くか、CSSファイルをHTMLに読み込んで試してください。
第1章 コード例1
<h1>Open Campus</h1>
<p>Visit our school.</p>第1章 コード例2
h1 {
color: #174a6e;
}
p {
margin-top: 2rem;
}第2章 コード例1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Open Campus</title>
</head>
<body>
<h1>Open Campus</h1>
<p>Visit our school.</p>
</body>
</html>第2章 コード例2
<a href="program.html">Program</a>第2章 コード例3
<p>Bring a <strong>student card</strong>.</p>第2章 コード例4
<h1>Open Campus</h1>
<p>Choose a place to visit.</p>
<ul>
<li>Library</li>
<li>Design room</li>
<li>Science lab</li>
</ul>第2章 コード例5
<h1>Open Campus</h1>
<p>Choose one event to explore.</p>
<ul>
<li>Campus tour</li>
<li>Design class</li>
<li>Science show</li>
</ul>
<p><a href="program.html">See the program</a></p>第3章 コード例1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Open Campus</title>
</head>
<body>
<header>
<h1>Open Campus</h1>
<p>Visit our school.</p>
</header>
<nav>
<ul>
<li><a href="#classes">Classes</a></li>
<li><a href="#visit">Visit</a></li>
</ul>
</nav>
<main>
<section id="classes">
<h2>Classes</h2>
<p>Try a short design class.</p>
<section>
<h3>What to bring</h3>
<p>Bring a notebook.</p>
</section>
</section>
<section id="visit">
<h2>Visit</h2>
<p>Check the meeting place before you come.</p>
</section>
</main>
<footer>
<p>Contact the school office.</p>
</footer>
</body>
</html>第3章 コード例2
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Open Campus</title>
</head>
<body>
<header><h1>Open Campus</h1></header>
<nav><a href="#classes">Classes</a> <a href="#visit">Visit</a></nav>
<main>
<section id="classes"><h2>Classes</h2><p>Try a design class.</p></section>
<section id="visit"><h2>Visit</h2><p>Check the meeting place before you come.</p></section>
</main>
<footer><p>Contact the school office.</p></footer>
</body>
</html>第4章 コード例1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Campus tour</title>
</head>
<body>
<main>
<h1>Campus tour</h1>
<p>May 10, 10:00. Meet at the library entrance.</p>
<img src="campus-map.svg" alt="Map showing the library with its entrance marked at the lower middle of the building">
<img src="blue-rule.svg" alt="">
<table>
<caption>Tour schedule</caption>
<thead>
<tr><th scope="col">Time</th><th scope="col">Event</th></tr>
</thead>
<tbody>
<tr><td>10:00</td><td>Welcome</td></tr>
<tr><td>11:00</td><td>Library</td></tr>
</tbody>
</table>
<form>
<label for="email">Email</label>
<input id="email" name="email" type="email">
<button type="submit" disabled>Send</button>
</form>
</main>
</body>
</html>この例では、同じフォルダーに campus-map.svg と blue-rule.svg を置いてください。
第4章 コード例2
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Campus tour</title></head>
<body><main><h1>Campus tour</h1><p>May 10, 10:00. Meet at the library entrance.</p>
<img src="campus-map.svg" alt="Map showing the library with its entrance marked at the lower middle of the building">
<table><caption>Tour schedule</caption><thead><tr><th scope="col">Time</th><th scope="col">Event</th></tr></thead><tbody><tr><td>10:00</td><td>Welcome</td></tr><tr><td>11:00</td><td>Library</td></tr></tbody></table>
<form><label for="email">Email</label><input id="email" name="email" type="email"><button type="submit" disabled>Send</button></form>
</main></body></html>この例では、同じフォルダーに campus-map.svg と blue-rule.svg を置いてください。
第5章 コード例1
<link rel="stylesheet" href="styles.css">第5章 コード例2
.notice {
color: #19324a;
padding: 1rem;
border: 1px solid #315b78;
}第5章 コード例3
.notice {
color: #19324a;
}
.notice {
color: #315b78;
}第5章 コード例4
.notice {
color: #19324a;
padding: 1rem;
}第6章 コード例1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Campus events</title>
<style>
body {
font-family: sans-serif;
line-height: 1.5;
margin: 1rem;
}
.site-nav {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.event-list {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 1rem;
}
.event-list article {
border: 1px solid #345;
padding: 1rem;
}
</style>
</head>
<body>
<header>
<h1>Campus events</h1>
</header>
<nav class="site-nav" aria-label="Main">
<a href="#program">Program</a>
<a href="#access">Access</a>
<a href="#contact">Contact</a>
</nav>
<main>
<section class="event-list" aria-label="Events">
<article id="program">
<h2>Program</h2>
<p>Talk and campus tour.</p>
</article>
<article id="access">
<h2>Access</h2>
<p>Find the main entrance.</p>
</article>
<article>
<h2>Library</h2>
<p>Visit the study area.</p>
</article>
<article>
<h2>Studio</h2>
<p>See student projects.</p>
</article>
<article>
<h2>Support</h2>
<p>Ask about student life.</p>
</article>
<article id="contact">
<h2>Contact</h2>
<p>Send a question.</p>
</article>
</section>
</main>
</body>
</html>第6章 コード例2
.card {
display: grid;
grid-template-columns: repeat(3, 1fr);
}第7章 コード例1
<meta name="viewport" content="width=device-width, initial-scale=1">第7章 コード例2
img {
max-width: 100%;
height: auto;
}第7章 コード例3
.cards {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
}
@media (min-width: 42rem) {
.cards {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}第8章 コード例1
<section class="card">
<h2>Open Campus A</h2>
<p>June 15, 10:00</p>
<p>Main Hall</p>
<p class="deadline">Deadline: June 10</p>
</section>第8章 コード例2
.card { padding: 1rem; border: 1px solid #6b7280; }
.card h2 { margin: 0 0 0.75rem; }
.deadline { color: #173b57; font-weight: 700; }第9章 コード例1
<div class="field-example">
<label for="name">Name</label>
<input id="name" name="name" type="text" aria-describedby="name-error">
<p class="error" id="name-error">Enter your name.</p>
</div>第9章 コード例2
<style>.error { border: 2px solid #c00; }</style>
<h1>Open Campus</h1>
<h3 id="program">Program</h3>
<a href="#program">Click here</a>
<img src="map.png">
<label for="student">Name</label>
<input id="name" type="text">
<p class="error"> </p>第10章 コード例1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Campus event</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Campus event</h1>
<p>14 November 2026, 10:00</p>
</header>
<nav aria-label="Main">
<a href="#program">Program</a>
</nav>
<main>
<section aria-labelledby="visit-title">
<h2 id="visit-title">Visit</h2>
<p>Main Hall</p>
<p>Join our open campus day.</p>
</section>
<section id="program" aria-labelledby="program-title">
<h2 id="program-title">Program</h2>
<div class="cards">
<article>
<h3>Tour</h3>
<p>10:00</p>
</article>
<article>
<h3>Workshop</h3>
<p>13:00</p>
</article>
</div>
</section>
<section aria-labelledby="question-title">
<h2 id="question-title">Question</h2>
<div class="field-example">
<label for="email">Email</label>
<input id="email" name="email" type="email">
</div>
</section>
</main>
<footer>
<p>Last reviewed: 27 October 2026</p>
</footer>
</body>
</html>第10章 コード例2
*{
box-sizing: border-box;
}
body {
margin: 0;
padding: 1rem;
color: #19324a;
font-family: sans-serif;
line-height: 1.6;
}
header,
main,
footer {
max-width: 52rem;
margin-inline: auto;
}
nav {
max-width: 52rem;
margin: 0 auto 1rem;
}
.cards {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
}
article {
padding: 1rem;
border: 1px solid #52734d;
border-radius: 0.5rem;
}
.field-example {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
input {
max-width: 100%;
}
@media (min-width: 42rem) {
.cards {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}