Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

calcの使い方

Posted at

calcの使い方

スクリーンショット 2024-08-26 17.41.29.png

  • 要素の最大幅はmax-width: 600pxを指定
  • 縮めた際に良き具合に余白が入ってほしい
  • width: calc(100% - 16px - 16px);を指定して余白ができるように設定する(margin: 0 auto;でセンター揃えは設定済み)
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Advanced CSS</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <section>
    <h1>テスト</h1>
    <p>こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。こんにちは。</p>
  </section>
</body>
</html>
@charset "utf-8";

body {
  margin: 0;
}

section {
  background: pink;
  max-width: 600px;
  margin: 0 auto;
  width: calc(100% - 16px - 16px);
}

h1 {
  margin: 0;
}

p {
  margin: 0;
}
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?