CARVIEW |
Select Language
HTTP/2 200
content-type: text/html
x-guploader-uploadid: AAwnv3IozeDzanCkRMhy5SCnLUnajYvACHNSgeO08EIDJONtN39TF9Mw_ZwV4Zy0KKIIPHqa
cache-control: public, max-age=3600
expires: Wed, 08 Oct 2025 14:08:26 GMT
last-modified: Wed, 08 Oct 2025 01:13:36 GMT
etag: W/"319c8ececeeceaffa4906a31cb5fa9d6"
x-goog-generation: 1759886016489507
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 278567
x-goog-meta-goog-reserved-file-mtime: 1759883917
x-goog-hash: crc32c=Fy5hxw==, md5=MZyOzs7s6v+kkGoxy1+p1g==
x-goog-storage-class: STANDARD
accept-ranges: none
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
alt-svc: clear
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
strict-transport-security: max-age=63072000
content-security-policy: default-src 'self'; script-src 'report-sample' 'self' 'wasm-unsafe-eval' https://www.google-analytics.com/analytics.js https://www.googletagmanager.com/gtag/js assets.codepen.io production-assets.codepen.io https://js.stripe.com 'sha256-XNBp89FG76amD8BqrJzyflxOF9PaWPqPqvJfKZPCv7M=' 'sha256-YCNoU9DNiinACbd8n6UPyB/8vj0kXvhkOni9/06SuYw=' 'sha256-PZjP7OR6mBEtnvXIZfCZ5PuOlxoDF1LDZL8aj8c42rw='; script-src-elem 'report-sample' 'self' 'wasm-unsafe-eval' https://www.google-analytics.com/analytics.js https://www.googletagmanager.com/gtag/js assets.codepen.io production-assets.codepen.io https://js.stripe.com 'sha256-XNBp89FG76amD8BqrJzyflxOF9PaWPqPqvJfKZPCv7M=' 'sha256-YCNoU9DNiinACbd8n6UPyB/8vj0kXvhkOni9/06SuYw=' 'sha256-PZjP7OR6mBEtnvXIZfCZ5PuOlxoDF1LDZL8aj8c42rw='; style-src 'report-sample' 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self'; connect-src 'self' developer.allizom.org bcd.developer.allizom.org bcd.developer.mozilla.org updates.developer.allizom.org updates.developer.mozilla.org https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com https://incoming.telemetry.mozilla.org https://observatory-api.mdn.allizom.net https://observatory-api.mdn.mozilla.net https://api.github.com/search/issues stats.g.doubleclick.net https://api.stripe.com; font-src 'self'; frame-src 'self' interactive-examples.mdn.mozilla.net interactive-examples.mdn.allizom.net mdn.github.io live-samples.mdn.mozilla.net live-samples.mdn.allizom.net *.mdnplay.dev *.mdnyalp.dev *.play.test.mdn.allizom.net https://v2.scrimba.com https://scrimba.com jsfiddle.net www.youtube-nocookie.com codepen.io survey.alchemer.com https://js.stripe.com; img-src 'self' data: *.githubusercontent.com *.googleusercontent.com *.gravatar.com mozillausercontent.com firefoxusercontent.com profile.stage.mozaws.net profile.accounts.firefox.com developer.mozilla.org mdn.dev interactive-examples.mdn.mozilla.net interactive-examples.mdn.allizom.net wikipedia.org upload.wikimedia.org https://mdn.github.io/shared-assets/ https://mdn.dev/ https://*.google-analytics.com https://*.googletagmanager.com www.gstatic.com; manifest-src 'self'; media-src 'self' archive.org videos.cdn.mozilla.net https://mdn.github.io/shared-assets/; child-src 'self'; worker-src 'self';
x-frame-options: DENY
origin-trial: AxVILwizhbMjxFeHOn1P3R8niO1RJY/smaK4B4d1rLzc1gTaxtXMSaTi+FoigYgCw40uFRDwFcEAeqDR+vVLOW4AAABfeyJvcmlnaW4iOiJodHRwczovL2RldmVsb3Blci5tb3ppbGxhLm9yZyIsImZlYXR1cmUiOiJQcml2YXRlQXR0cmlidXRpb25WMiIsImV4cGlyeSI6MTc0MjA3OTYwMH0=
x-cloud-trace-context: 95a9f76882fa45375543a98156d75a78
date: Wed, 08 Oct 2025 13:08:26 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache: miss
hypot() - CSS: カスケーディングスタイルシート | MDN
Toggle sidebar
>
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
hypot()
Baseline
2023
Newly available
Since December 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
hypot()
は CSS の関数で、各引数の 2 乗の合計値の平方根を返す指数関数です。
pow()
と sqrt()
は単位のない数値のみを扱いますが、hypot()
は単位を持つ値を受け入れます。ただし、すべての値は同じ型である必要があります。
構文
css
/* <number> 値 */
width: hypot(2em); /* 2em */
width: hypot(3em, 4em); /* 5em */
width: hypot(30px, 40px); /* 50px */
width: hypot(48px, 64px); /* 80px */
width: hypot(3px, 4px, 5px); /* 7.0710678118654755px */
引数
hypot(x [, ...]#)
関数は、1 つ以上のカンマ区切りの計算式を引数として受け取ります。
x
,x2
, ...,xN
-
<number>
、<dimension>
、または<percentage>
に解決される計算式です。
返値
<number>
、<dimension>
、または <percentage>
(入力に基づく) を返します。これは、各引数の 2 乗の合計値の平方根です。
- いずれかの入力が
infinite
の場合、+∞
を返します。 - 引数が 1 つの場合、その絶対値を返します。
hypot(2em)
とhypot(-2em)
はどちらも2em
に解決されます。
形式文法
<hypot()> =
hypot( <calc-sum># )
<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*
<calc-product> =
<calc-value> [ [ '*' | / ] <calc-value> ]*
<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )
<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN
例
>hypot 関数をもとにしたサイズ
この例では、hypot()
関数を使用してサイズを計算します。
HTML
html
<div class="boxes">
<div class="box">100px</div>
<div class="box one">100px</div>
<div class="box two">141.42px</div>
<div class="box three">250px</div>
</div>
CSS
ここではサイズを定義するために、CSS カスタムプロパティ を利用しています。はじめに最初のサイズ (--size-0
) を宣言し、これを使用して他のサイズを計算します。
--size-1
は、--size-0
(100px) の斜辺の長さとして計算されます。値は 2 乗され、他に値がないためその平方根が返され、結果は 100px になります。--size-2
は、2 つの--size-0
(100px) の斜辺の長さとして計算されます。値は 2 乗され (100px * 100px = 10000px2)、それに再び--size-0
の 2 乗が加算され (10000px2 + 10000px2 = 20000px2)、その合計値の平方根 (√(20000px2)) が返され、結果は 141.42px になります。--size-3
は、--size-0
* 1.5 (150px) と--size-0
* 2 (200px) を用いて計算されます。これらの 2 乗の和の平方根が結果となります。それぞれの値は 2 乗され (22500px2 と 40000px2)、それらが加算され (62500px2)、合計値の平方根 (√(62500px2)) が 250px になります。
css
:root {
--size-0: 100px;
--size-1: hypot(var(--size-0)); /* 100px */
--size-2: hypot(var(--size-0), var(--size-0)); /* 141.42px */
--size-3: hypot(
calc(var(--size-0) * 1.5),
calc(var(--size-0) * 2)
); /* 250px */
}
.boxes {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.box {
width: var(--size-0);
height: var(--size-0);
background-color: tomato;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
計算したサイズは、各セレクターの width
と height
の値として使用されます。
css
.one {
width: var(--size-1);
height: var(--size-1);
}
.two {
width: var(--size-2);
height: var(--size-2);
}
.three {
width: var(--size-3);
height: var(--size-3);
}
結果
仕様書
Specification |
---|
CSS Values and Units Module Level 4> # exponent-funcs> |
ブラウザーの互換性
Loading…