[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/CSS/Reference/Values/fit-content_function [Back]  [Original]

CSS fit-content() - CSS | MDN

MDN Web Docs

View in English Always switch to English

CSS fit-content()

fit-content() CSS min(, max(, ))

grid-template-columns: fit-content(8ch) fit-content(8ch) 1fr;
grid-template-columns: fit-content(100px) fit-content(100px) 1fr;
grid-template-columns: fit-content(40%) fit-content(40%) 1fr;
<section class="default-example" id="default-example">
  <div class="example-container">
    <div class="transition-all" id="example-element">
      <div>One </div>
      <div>Two</div>
      <div>Three</div>
      <div>Four</div>
      <div>Five</div>
    </div>
  </div>
</section>
#example-element {
  border: 1px solid #c5c5c5;
  display: grid;
  grid-gap: 10px;
  width: 250px;
}

#example-element > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  text-align: left;
}

CSS max-content auto auto minmax(auto, max-content) auto

max-content auto grid-template-columns

fit-content() width, height, min-width, min-height, max-width, max-height

css
/* <length>  */
fit-content(200px)
fit-content(5cm)
fit-content(30vw)
fit-content(100ch)

/* <percentage>  */
fit-content(40%)

<length>

<percentage>

<fit-content()> = 
fit-content( <length-percentage> )

<length-percentage> =
<length> |
<percentage>
CSS Grid Layout Module Level 2, CSS Values and Units Module Level 4

fit-content

HTML

html
<div id="container">
  <div></div>
  <div>
     300 
  </div>
  <div></div>
</div>

CSS

css
#container {
  display: grid;
  grid-template-columns: fit-content(300px) fit-content(300px) 1fr;
  grid-gap: 5px;
  box-sizing: border-box;
  height: 200px;
  width: 100%;
  background-color: #8cffa0;
  padding: 10px;
}

#container > div {
  background-color: #8ca0ff;
  padding: 5px;
}

CSS Grid Layout Module Level 2
# funcdef-grid-template-columns-fit-content
CSS Box Sizing Module Level 3
# funcdef-width-fit-content

css.properties.grid-template-columns.fit-content

css.properties.width.fit-content_function


Web Proxy Viewer  |  New URL  |  Original Page