記述ポイント
- 横並びを縦並びに変更するために、メディアクエリ内で「display: block;」を指定する
@charset "UTF-8";
*, *::before, *::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul, li {
list-style: none;
}
a {
color: inherit;
text-decoration: none;
}
img {
max-width: 100%;
vertical-align: bottom;
}
html {
font-size: 100%;
}
body {
background-color: #666;
color: #fff;
font-size: 1.0rem;
font-family: Arial, sans-serif;
line-height: 1.0;
}
#top {
width: 100%;
height: 100vh;
background-image: linear-gradient(25deg,
rgba(178, 5, 5, 0.6),
rgba(4, 160, 4, 0.6)),
url(../img/grass.webp);
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
.container {
display: flex;
align-items: center;
}
@media screen and (max-width: 767px) {
.container {
display: block;
}
}
.header {
position: fixed;
top: 0;
width: 100%;
}
.container {
width: min(92%, 960px);
margin: auto;
text-align: center;
}
.header h1 {
padding-top: 2vh;
margin: 0 auto 1.5vh 0;
font-size: 3.6rem;
font-family: 'Caveat', cursive;
}
.gnav ul {
display: flex;
justify-content: center;
gap: 30px;
}
.gnav li {
font-size: 1.2em;
}
.gnav a:hover {
border-bottom: 2px solid #fff;
padding-bottom: 2px;
}
.main {
display: flex;
align-items: center;
width: min(92%, 960px);
height: 100vh;
margin: 0 auto;
text-align: center;
}
a.prof {
display: inline-block;
margin: auto;
padding: 10px 40px;
border: 2px solid #fff;
font-size: 1.125rem;
font-weight: 600;
text-align: center;
letter-spacing: .08em;
}
a.prof:hover {
background-color: rgba(189, 19, 19, 0.5);
}
.footer {
position: fixed;
bottom: 0;
width: 100%;
height: 50px;
text-align: center;
}
index.html
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>The Web Design</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Caveat:wght@400..700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
</head>
<body id="top">
<header class="header">
<div class="container">
<h1>The Web Design</h1>
<nav class="gnav">
<ul>
<li><a href="#">Portfolio</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
</header>
<main class="main">
<a href="#" class="prof">Portfolio</a>
</main>
<footer class="footer">
<p><small>© The Web Design</small></p>
</footer>
</body>
</html>