From b878d4a1cf8abdbaef200f64391ed6af2d80c2a6 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Tue, 16 Nov 2021 10:16:30 +0900 Subject: CSS Box Sizing 関連のリファレンスを更新 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 2021/11/14 時点の英語版に同期 --- files/ja/web/css/width/index.md | 206 ++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 112 deletions(-) (limited to 'files/ja/web/css/width') diff --git a/files/ja/web/css/width/index.md b/files/ja/web/css/width/index.md index 322e08849b..96b073a1f7 100644 --- a/files/ja/web/css/width/index.md +++ b/files/ja/web/css/width/index.md @@ -3,33 +3,32 @@ title: width slug: Web/CSS/width tags: - CSS - - CSS Property - - Layout - - Reference - - dimensions + - CSS プロパティ + - レイアウト + - リファレンス + - 寸法 - recipe:css-property - size - width browser-compat: css.properties.width translation_of: Web/CSS/width --- -

{{CSSRef}}

+{{CSSRef}} -

width は CSS のプロパティで、要素の幅を設定します。既定では、このプロパティはコンテンツ領域の幅を設定しますが、 {{cssxref("box-sizing")}} を border-box に設定すると、境界領域の幅を設定します。

+**`width`** は CSS のプロパティで、要素の幅を設定します。既定では、このプロパティは[コンテンツ領域](/ja/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model#content-area)の幅を設定しますが、 {{cssxref("box-sizing")}} を `border-box` に設定すると、[境界領域](/ja/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model#border-area)の幅を設定します。 -
{{EmbedInteractiveExample("pages/css/width.html")}}
+{{EmbedInteractiveExample("pages/css/width.html")}} - +{{cssxref("min-width")}} および {{cssxref("max-width")}} プロパティは `width` を上書きします。 -

{{cssxref("min-width")}} および {{cssxref("max-width")}} プロパティは width を上書きします。

+## 構文 -

構文

- -
/* <length> 値 */
+```css
+/*  値 */
 width: 300px;
 width: 25em;
 
-/* <percentage> 値 */
+/*  値 */
 width: 75%;
 
 /* キーワード値 */
@@ -43,57 +42,58 @@ width: inherit;
 width: initial;
 width: revert;
 width: unset;
-
+``` -

+### 値 -
-
{{cssxref("<length>")}}
-
絶対的な値で幅を定義します。
-
{{cssxref("<percentage>")}}
-
親となる包含ブロックの幅に対するパーセント値で定義します。
-
auto
-
指定された要素の幅をブラウザーが計算して決めます。
-
max-content
-
望ましい固有の幅です。
-
min-content
-
最小の固有の幅です。
-
fit-content({{cssxref("<length-percentage>")}})
-
利用可能な空間に対して fit-content 式を使用し、指定された引数に置き換えられます。すなわち min(max-content, max(min-content, <length-percentage>)) です。
-
+- {{cssxref("<length>")}} + - : 絶対的な値で幅を定義します。 +- {{cssxref("<percentage>")}} + - : 親となる包含ブロックの幅に対するパーセント値で定義します。 +- `auto` + - : 指定された要素の幅をブラウザーが計算して決めます。 +- `max-content` + - : 望ましい固有の幅です。 +- `min-content` + - : 最小の固有の幅です。 +- `fit-content({{cssxref("<length-percentage>")}})` + - : 利用可能な空間に対して fit-content 式を使用し、指定された引数に置き換えられます。すなわち `min(max-content, max(min-content, ))` です。 -

アクセシビリティの考慮

+## アクセシビリティの考慮 -

ページを拡大してテキストサイズを大きくしたときに、 width を設定した要素が切り捨てられたり、他のコンテンツが見えなくなったりしないようにしてください。

+ページを拡大してテキストサイズを大きくしたときに、 `width` を設定した要素が切り捨てられたり、他のコンテンツが見えなくなったりしないようにしてください。 - +- [MDN WCAG の理解、 ガイドライン 1.4 の説明](/ja/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.4_make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background) +- [Understanding Success Criterion 1.4.4 | W3C Understanding WCAG 2.0](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-scale.html) -

公式定義

+## 公式定義 -

{{CSSInfo}}

+{{CSSInfo}} -

形式文法

+## 形式文法 {{csssyntax}} -

+## 例

既定の幅

-
p.goldie {
+```css
+p.goldie {
   background: gold;
-}
+} +``` -
<p class="goldie">The Mozilla community produces a lot of great software.</p>
+```html +

The Mozilla community produces a lot of great software.

+``` -

{{EmbedLiveSample('Default_width', '500px', '64px')}}

+{{EmbedLiveSample('Default_width', '500px', '64px')}}

ピクセル数と em 単位

-
.px_length {
+```css
+.px_length {
   width: 200px;
   background-color: red;
   color: white;
@@ -106,96 +106,78 @@ width: unset;
   color: red;
   border: 1px solid black;
 }
-
+``` -
<div class="px_length">Width measured in px</div>
-<div class="em_length">Width measured in em</div>
+```html +
Width measured in px
+
Width measured in em
+``` -

{{EmbedLiveSample('Pixels_and_ems', '500px', '64px')}}

+{{EmbedLiveSample('Pixels_and_ems', '500px', '64px')}}

パーセント値

-
.percent {
+```css
+.percent {
   width: 20%;
   background-color: silver;
   border: 1px solid red;
-}
+} +``` -
<div class="percent">Width in percentage</div>
+```html +
Width in percentage
+``` -

{{EmbedLiveSample('Percentage', '500px', '64px')}}

+{{EmbedLiveSample('Percentage', '500px', '64px')}} -

max-content

+### max-content -
p.maxgreen {
+```css
+p.maxgreen {
   background: lightgreen;
   width: intrinsic;           /* Safari/WebKit uses a non-standard name */
   width: -moz-max-content;    /* Firefox/Gecko */
   width: -webkit-max-content; /* Chrome */
   width: max-content;
-}
+} +``` -
<p class="maxgreen">The Mozilla community produces a lot of great software.</p>
+```html +

The Mozilla community produces a lot of great software.

+``` -

{{EmbedLiveSample('max-content', '500px', '64px')}}

+{{EmbedLiveSample('max-content', '500px', '64px')}} -

min-content

+### min-content -
p.minblue {
+```css
+p.minblue {
   background: lightblue;
   width: -moz-min-content;    /* Firefox */
   width: -webkit-min-content; /* Chrome */
   width: min-content;
-}
- -
<p class="minblue">The Mozilla community produces a lot of great software.</p>
- -

{{EmbedLiveSample('min-content', '500px', '155px')}}

- -

仕様書

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
仕様書状態備考
{{SpecName('CSS4 Sizing', '#width-height-keywords', 'width')}}{{Spec2('CSS4 Sizing')}}
{{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}}{{Spec2('CSS3 Sizing')}}キーワード max-content, min-content, fit-content を追加
{{SpecName('CSS2.1', 'visudet.html#the-width-property', 'width')}}{{Spec2('CSS2.1')}}適用対象の要素を詳しく記載
{{SpecName('CSS1', '#width', 'width')}}{{Spec2('CSS1')}}初回定義
- -

ブラウザーの互換性

- -

{{Compat}}

- -

関連情報

- - +} +``` + +```html +

The Mozilla community produces a lot of great software.

+``` + +{{EmbedLiveSample('min-content', '500px', '155px')}} + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- [ボックスモデル](/ja/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model) +- {{cssxref("height")}} +- {{cssxref("box-sizing")}} +- {{cssxref("min-width")}}, {{cssxref("max-width")}} +- 対応する論理的プロパティ: {{cssxref("block-size")}}, {{cssxref("inline-size")}} -- cgit v1.2.3-54-g00ecf