CSS Reference
rem()
剰余(余り)を計算する
rem()
関数は CSSで剰余(余り)を計算するための CSS 関数です。
剰余とは、数を割ったときの余りを意味します。例えば、5
を 2
で割ると余り(剰余)が 1
です。つまり、margin: mod(18px, 4px);
を計算すると、剰余は 2px
となるため、算出される margin
の値は 2px
となります。
rem()
関数は、JavaScript の剰余演算子(%
)と同様の動作を期待する場合に使用することができます。
mod()
関数も同様に剰余を計算しますが、引数の値によって計算値が異なる場合があります。
計算結果は、任意の <number>
、<dimension>
、または <percentage>
値となりますが、2つの引数は同じデータ型を持たなければならず、そうでない場合、関数は無効となります。また、導き出される値も同じデータ型になります。
mod()
関数と rem()
関数のどちらを選ぶべきか?
通常は mod()
関数を選ぶべきでしょう。多くの場合、B
値は制作者が制御し、A
値が変動するもの思われますが、mod()
関数を使用すれば、A
の値が正の値でも負の値でも、結果が 0
と B
の間に収まるためです。これは、多くの場合に期待される動作だと思われますし、直感的です。
一方で、JavaScript の剰余演算子(%
演算子)と同様の動作を期待する場合は、rem()
関数を使用することができます。
rem()のサンプルソース
.example01 { margin: mod(-18px, 5px); /* 2px と計算される */ } .example02 { margin: rem(-18px, 5px); /* -3px と計算される */ }
.example01 { rotate: mod(140deg, -90deg) ; /* -40deg と計算される */ } .example02 { rotate: rem(140deg, -90deg) ; /* 50deg と計算される */ }
主要ブラウザの対応
IE11 | × |
---|---|
Edge(EdgeHTML) | × |
Edge(Chromium) | ○ |
Chrome | ○ |
Firefox | ○ |
Safari | ○ |
iOS Safari | ○ |
Android Chrome | ○ |
関連するCSS関数
用途から CSS プロパティやセレクタを探す
用途から CSS プロパティやセレクタを逆引きできます。
- 疑似クラス
-
- :active
- :any-link
- :checked
- :default
- :defined
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :focus-visible
- :focus-within
- :fullscreen
- :has()
- :host
- :hover
- :in-range
- :indeterminate
- :invalid
- :is()
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :placeholder-shown
- :read-only
- :read-write
- :required
- :right
- :root
- :scope
- :state()
- :target
- :valid
- :visited
- :where()
対応ブラウザから CSS プロパティやセレクタを探す
対応ブラウザから CSS プロパティやセレクタを逆引きできます。
- IE11
-
- ::after
- ::backdrop
- ::before
- ::first-letter
- ::first-line
- ::selection
- :active
- :checked
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :fullscreen
- :hover
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :placeholder-shown
- :required
- :right
- :root
- :target
- :valid
- :visited
- @charset
- @keyframes
- ID セレクタ
- attr()
- background
- background-color
- calc()
- hyphens
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ
- Edge(EdgeHTML)
-
- ::after
- ::backdrop
- ::before
- ::first-letter
- ::first-line
- ::placeholder
- ::selection
- :active
- :checked
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :fullscreen
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :read-only
- :read-write
- :required
- :right
- :root
- :target
- :valid
- :visited
- @charset
- @keyframes
- @supports
- ID セレクタ
- attr()
- background
- background-color
- calc()
- hyphens
- minmax()
- prefers-color-scheme
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ
- Edge(Chromium)
-
- ::after
- ::backdrop
- ::before
- ::cue
- ::file-selector-button
- ::first-letter
- ::first-line
- ::marker
- ::part()
- ::placeholder
- ::selection
- ::slotted()
- :active
- :any-link
- :checked
- :default
- :defined
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :focus-visible
- :focus-within
- :fullscreen
- :has()
- :host
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :placeholder-shown
- :read-only
- :read-write
- :required
- :right
- :root
- :scope
- :state()
- :target
- :valid
- :visited
- @charset
- @color-profile
- @container
- @counter-style
- @font-feature-values
- @font-palette-values
- @keyframes
- @layer
- @property
- @scope
- @start-style
- @supports
- ID セレクタ
- accent-color
- acos()
- appearance
- asin()
- atan()
- atan2()
- attr()
- background
- background-color
- calc()
- circle()
- clamp()
- color()
- color-mix()
- contain
- contain-intrinsic-block-size
- contain-intrinsic-height
- contain-intrinsic-inline-size
- contain-intrinsic-size
- contain-intrinsic-width
- container
- container-name
- container-type
- cos()
- ellipse()
- exp()
- field-sizing
- font-palette
- hyphenate-character
- hyphens
- hypot()
- inset()
- log()
- max()
- min()
- minmax()
- mod()
- polygon()
- pow()
- prefers-color-scheme
- rem()
- round()
- ruby-align
- ruby-position
- scroll-behavior
- sin()
- sqrt()
- tan()
- text-spacing-trim
- text-wrap
- white-space-collapse
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 入れ子セレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ
- Firefox
-
- ::after
- ::backdrop
- ::before
- ::cue
- ::file-selector-button
- ::first-letter
- ::first-line
- ::marker
- ::part()
- ::placeholder
- ::selection
- ::slotted()
- :active
- :any-link
- :checked
- :default
- :defined
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :focus-visible
- :focus-within
- :fullscreen
- :has()
- :host
- :hover
- :in-range
- :indeterminate
- :invalid
- :is()
- :lang()
- :last-child
- :last-of-type
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :placeholder-shown
- :read-only
- :read-write
- :required
- :root
- :scope
- :state()
- :target
- :valid
- :visited
- :where()
- @charset
- @color-profile
- @container
- @counter-style
- @font-feature-values
- @font-palette-values
- @keyframes
- @layer
- @property
- @scroll-timeline
- @start-style
- @supports
- ID セレクタ
- accent-color
- acos()
- appearance
- asin()
- atan()
- atan2()
- attr()
- background
- background-color
- calc()
- circle()
- clamp()
- color()
- color-mix()
- contain
- contain-intrinsic-block-size
- contain-intrinsic-height
- contain-intrinsic-inline-size
- contain-intrinsic-size
- contain-intrinsic-width
- container
- container-name
- container-type
- cos()
- ellipse()
- exp()
- font-palette
- hyphenate-character
- hyphens
- hypot()
- inset()
- log()
- max()
- min()
- minmax()
- mod()
- polygon()
- pow()
- prefers-color-scheme
- rem()
- round()
- ruby-align
- ruby-position
- scroll-behavior
- sin()
- sqrt()
- tan()
- text-wrap
- text-wrap-mode
- text-wrap-style
- white-space-collapse
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 入れ子セレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ
- Chrome
-
- ::after
- ::backdrop
- ::before
- ::cue
- ::file-selector-button
- ::first-letter
- ::first-line
- ::marker
- ::part()
- ::placeholder
- ::selection
- ::slotted()
- :active
- :any-link
- :checked
- :default
- :defined
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :focus-visible
- :focus-within
- :fullscreen
- :has()
- :host
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :placeholder-shown
- :read-only
- :read-write
- :required
- :right
- :root
- :scope
- :state()
- :target
- :valid
- :visited
- @charset
- @color-profile
- @container
- @counter-style
- @font-feature-values
- @font-palette-values
- @keyframes
- @layer
- @property
- @scope
- @start-style
- @supports
- ID セレクタ
- accent-color
- acos()
- appearance
- asin()
- atan()
- atan2()
- attr()
- background
- background-color
- calc()
- circle()
- clamp()
- color()
- color-mix()
- contain
- contain-intrinsic-block-size
- contain-intrinsic-height
- contain-intrinsic-inline-size
- contain-intrinsic-size
- contain-intrinsic-width
- container
- container-name
- container-type
- cos()
- ellipse()
- exp()
- field-sizing
- font-palette
- hyphenate-character
- hyphens
- hypot()
- inset()
- log()
- max()
- min()
- minmax()
- mod()
- polygon()
- pow()
- prefers-color-scheme
- rem()
- round()
- ruby-align
- ruby-position
- scroll-behavior
- sin()
- sqrt()
- tan()
- text-spacing-trim
- text-wrap
- white-space-collapse
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 入れ子セレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ
- Safari
-
- ::after
- ::before
- ::cue
- ::file-selector-button
- ::first-letter
- ::first-line
- ::marker
- ::part()
- ::placeholder
- ::selection
- ::slotted()
- :active
- :any-link
- :checked
- :default
- :defined
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :focus-visible
- :focus-within
- :has()
- :host
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :placeholder-shown
- :read-only
- :read-write
- :required
- :right
- :root
- :scope
- :state()
- :target
- :valid
- :visited
- @charset
- @color-profile
- @container
- @counter-style
- @font-feature-values
- @font-palette-values
- @keyframes
- @layer
- @property
- @scope
- @start-style
- @supports
- ID セレクタ
- accent-color
- acos()
- appearance
- asin()
- atan()
- atan2()
- attr()
- background
- background-color
- calc()
- circle()
- color()
- color-mix()
- contain
- contain-intrinsic-block-size
- contain-intrinsic-height
- contain-intrinsic-inline-size
- contain-intrinsic-size
- contain-intrinsic-width
- container
- container-name
- container-type
- cos()
- ellipse()
- exp()
- font-palette
- hyphenate-character
- hyphens
- hypot()
- inset()
- log()
- max()
- min()
- minmax()
- mod()
- polygon()
- pow()
- prefers-color-scheme
- rem()
- round()
- ruby-position
- scroll-behavior
- sin()
- sqrt()
- tan()
- text-wrap
- text-wrap-mode
- text-wrap-style
- white-space-collapse
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 入れ子セレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ
- iOS Safari
-
- ::after
- ::before
- ::cue
- ::file-selector-button
- ::first-letter
- ::first-line
- ::marker
- ::part()
- ::placeholder
- ::selection
- ::slotted()
- :active
- :any-link
- :checked
- :default
- :defined
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :focus-visible
- :focus-within
- :fullscreen
- :has()
- :host
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :placeholder-shown
- :read-only
- :read-write
- :required
- :right
- :root
- :scope
- :state()
- :target
- :valid
- :visited
- @charset
- @color-profile
- @container
- @counter-style
- @font-feature-values
- @font-palette-values
- @keyframes
- @layer
- @property
- @scope
- @start-style
- @supports
- ID セレクタ
- accent-color
- acos()
- appearance
- asin()
- atan()
- atan2()
- attr()
- background
- background-color
- calc()
- circle()
- color()
- color-mix()
- contain
- contain-intrinsic-block-size
- contain-intrinsic-height
- contain-intrinsic-inline-size
- contain-intrinsic-size
- contain-intrinsic-width
- container
- container-name
- container-type
- cos()
- ellipse()
- exp()
- font-palette
- hyphenate-character
- hyphens
- hypot()
- inset()
- log()
- max()
- min()
- minmax()
- mod()
- polygon()
- pow()
- prefers-color-scheme
- rem()
- round()
- ruby-position
- scroll-behavior
- sin()
- sqrt()
- tan()
- text-wrap
- text-wrap-mode
- text-wrap-style
- white-space-collapse
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 入れ子セレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ
- Android Chrome
-
- ::after
- ::backdrop
- ::before
- ::cue
- ::file-selector-button
- ::first-letter
- ::first-line
- ::marker
- ::part()
- ::placeholder
- ::selection
- ::slotted()
- :active
- :any-link
- :checked
- :default
- :defined
- :disabled
- :empty
- :enabled
- :first
- :first-child
- :first-of-type
- :focus
- :focus-visible
- :focus-within
- :fullscreen
- :has()
- :host
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :left
- :link
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-child
- :only-of-type
- :optional
- :out-of-range
- :placeholder-shown
- :read-only
- :read-write
- :required
- :right
- :root
- :scope
- :state()
- :target
- :visited
- @charset
- @color-profile
- @container
- @counter-style
- @font-feature-values
- @font-palette-values
- @keyframes
- @layer
- @property
- @scope
- @start-style
- @supports
- ID セレクタ
- accent-color
- acos()
- appearance
- asin()
- atan()
- atan2()
- attr()
- background
- background-color
- calc()
- circle()
- clamp()
- color()
- color-mix()
- contain
- contain-intrinsic-block-size
- contain-intrinsic-height
- contain-intrinsic-inline-size
- contain-intrinsic-size
- contain-intrinsic-width
- container
- container-name
- container-type
- cos()
- ellipse()
- exp()
- field-sizing
- font-palette
- hyphenate-character
- hyphens
- hypot()
- inset()
- log()
- max()
- min()
- minmax()
- mod()
- polygon()
- pow()
- prefers-color-scheme
- rem()
- round()
- ruby-align
- ruby-position
- scroll-behavior
- sin()
- sqrt()
- tan()
- text-spacing-trim
- text-wrap
- white-space-collapse
- クラスセレクタ
- タイプセレクタ
- ユニバーサルセレクタ
- 入れ子セレクタ
- 子セレクタ
- 子孫セレクタ
- 属性セレクタ
- 間接セレクタ
- 隣接セレクタ