Spec-Zone.ru › CSS

Свойство CSS `column-wrap`

Экспериментальная: Это экспериментальная технология
Перед использованием в рабочей среде внимательно ознакомьтесь с таблицей совместимости с браузерами.

Экспериментальная: Это экспериментальная технология
Перед использованием в рабочей среде внимательно ознакомьтесь с таблицей совместимости с браузерами.

Свойство column-wrap CSS задаёт поведение переноса переполняющих контейнер столбцов в многоколоночной раскладке CSS.

Синтаксис

/* Keywords */
column-wrap: auto;
column-wrap: nowrap;
column-wrap: wrap;

/* Global values */
column-wrap: inherit;
column-wrap: initial;
column-wrap: revert;
column-wrap: revert-layer;
column-wrap: unset;

Значения

Это свойство задаётся одним из следующих ключевых слов:

auto
Начальное значение. Если для column-height контейнера содержимого задано значение <length>, то auto принимает значение wrap, иначе — nowrap.
nowrap
Столбцы переполняют контейнер в строчном направлении.
wrap
Переполняющие контейнер столбцы размещаются в новой строке в блочном направлении.

Описание

Свойство column-wrap позволяет переносить столбцы многоколоночной раскладки CSS на новую строку, когда они начинают переполнять ширину столбца. Это полезно для создания более удобных для чтения раскладок при использовании свойств column-count или column-width для создания нескольких столбцов.

Без column-wrap лишние столбцы будут переполнять контейнер сбоку, и читателям придётся прокручивать его в строчном направлении, чтобы прочитать всё содержимое. Свойство column-height вместе с column-wrap позволяет задать для столбцов определённую высоту и переносить их на новую строку, когда они достигают края контейнера.

Значение свойства column-wrap по умолчанию — auto. Если для column-height задано значение <length>, оно принимает значение wrap; wrap позволяет переносить столбцы фиксированной высоты на несколько строк. Если column-height равно auto, column-wrap: auto принимает значение nowrap, позволяя столбцам переполнять контейнер по горизонтали, если для него задана фиксированная высота.

Из-за такого поведения по умолчанию обычно нет необходимости явно задавать свойство column-wrap.

Формальное определение

Начальное значение auto
Применяется к элементам multicol
Наследуется нет
Вычисленное значение как задано
Тип анимации дискретный

Формальный синтаксис

column-wrap = 
  auto |
  nowrap |
  wrap

Примеры

Основное использование

В этом примере показано основное использование свойства column-wrap для создания многоколоночной раскладки с переносом путём задания свойства column-height.

HTML

Мы добавляем стихотворение доктора Сьюза с помощью <ol>, содержащего 28 элементов <li>, а затем указываем имя автора в элементе <p>.

<ol>
  <li>One fish</li>
  <li>Two fish</li>
  <li>Red fish</li>
  <li>Blue fish</li>
  ...
</ol>
<p>-- Dr. Seuss</p>
<ol>
  <li>One fish</li>
  <li>Two fish</li>
  <li>Red fish</li>
  <li>Blue fish</li>
  <li>Black fish</li>
  <li>Blue fish</li>
  <li>Old fish</li>
  <li>New fish.</li>
  <li>This one has a little star.</li>
  <li>This one has a little car.</li>
  <li>Say! What a lot</li>
  <li>Of fish there are.</li>
  <li>Yes. Some are red. And some are blue.</li>
  <li>Some are old. And some are new.</li>
  <li>Some are sad.</li>
  <li>And some are glad.</li>
  <li>And some are very, very bad.</li>
  <li>Why are they</li>
  <li>Sad and glad and bad?</li>
  <li>I do not know.</li>
  <li>Go ask your dad.</li>
  <li>Some are thin.</li>
  <li>And some are fat.</li>
  <li>The fat one has</li>
  <li>A yellow hat.</li>
  <li>From there to here, from here to there,</li>
  <li>Funny things</li>
  <li>Are everywhere.</li>
</ol>
<p>--Dr. Seuss</p>

CSS

Мы задаём для <ol> тип многоколоночного контейнера, устанавливая свойство column-width в 150px, то есть контейнер будет содержать максимально возможное количество столбцов шириной не менее 150px каждый. Свойство gap задаёт горизонтальный промежуток между столбцами и вертикальный промежуток между строками столбцов. Затем мы задаём column-height значение 3em, из-за чего значение auto по умолчанию для свойства column-wrap принимает значение wrap, создавая строки столбцов с переносом.

ol {
  column-width: 150px;
  gap: 2em;
  column-height: 3em;
}

Результат

Сравнение wrap и nowrap

В этом примере показана многоколоночная раскладка, демонстрирующая разницу между значениями wrap и nowrap: можно переключать значение column-wrap контейнера со столбцами между ними. В результате раскладка динамически меняется с горизонтальной прокрутки на вертикальную и обратно.

HTML и JavaScript

Разметка этого примера содержит несколько абзацев текста с главных страниц MDN, посвящённых HTML, CSS и JavaScript, а также элемент <input type="checkbox"> с обработчиком на JavaScript для переключения значения свойства column-wrap контейнера между nowrap и wrap. Для краткости HTML и JavaScript скрыты.

<form>
  <label for="set-wrap"
    >Set <code>column-wrap</code> to <code>wrap</code></label
  >
  <input type="checkbox" id="set-wrap" />
</form>
<h1>HTML, CSS, and JavaScript summaries</h1>
<p>
  <strong>HTML</strong> (HyperText Markup Language) is the most basic building
  block of the Web. It defines the meaning and structure of web content. Other
  technologies besides HTML are generally used to describe a web page's
  appearance (CSS) or behavior (JavaScript).
</p>
<p>
  "Hypertext" refers to text containing links that connect web pages to one
  another, either within a single website or between websites. Links are a
  fundamental aspect of the Web. By uploading content to the Internet and
  linking it to pages created by other people, you become an active participant
  in the World Wide Web.
</p>
<p>
  HTML uses "markup" to annotate text, images, and other content for display in
  a Web browser. HTML markup includes special "elements" such as
  <a href="/en-US/docs/Web/HTML/Reference/Elements/head"
    ><code>&lt;head&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/title"
    ><code>&lt;title&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/body"
    ><code>&lt;body&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/header"
    ><code>&lt;header&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/footer"
    ><code>&lt;footer&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/article"
    ><code>&lt;article&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/section"
    ><code>&lt;section&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/p"><code>&lt;p&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/div"
    ><code>&lt;div&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/span"
    ><code>&lt;span&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/img"
    ><code>&lt;img&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/aside"
    ><code>&lt;aside&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/audio"
    ><code>&lt;audio&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/canvas"
    ><code>&lt;canvas&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/datalist"
    ><code>&lt;datalist&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/details"
    ><code>&lt;details&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/embed"
    ><code>&lt;embed&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/nav"
    ><code>&lt;nav&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/search"
    ><code>&lt;search&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/output"
    ><code>&lt;output&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/progress"
    ><code>&lt;progress&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/video"
    ><code>&lt;video&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/ul"
    ><code>&lt;ul&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/ol"
    ><code>&lt;ol&gt;</code></a
  >,
  <a href="/en-US/docs/Web/HTML/Reference/Elements/li"
    ><code>&lt;li&gt;</code></a
  >
  and many others.
</p>
<p>
  An HTML element is set off from other text in a document by "tags", which
  consist of the element name surrounded by <code>&lt;</code> and
  <code>&gt;</code>. The name of an element inside a tag is case-insensitive.
  That is, it can be written in uppercase, lowercase, or a mixture. For example,
  the <code>&lt;title&gt;</code> tag can be written as
  <code>&lt;Title&gt;</code>, <code>&lt;TITLE&gt;</code>, or in any other way.
  However, the convention and recommended practice is to write tags in
  lowercase.
</p>

<hr />

<p>
  <strong>Cascading Style Sheets</strong> (<strong>CSS</strong>) is a
  <a href="/en-US/docs/Web/API/StyleSheet">stylesheet</a> language used to
  describe the presentation of a document written in
  <a href="/en-US/docs/Web/HTML">HTML</a> or
  <a href="/en-US/docs/Web/XML/Guides/XML_introduction">XML</a> (including XML
  dialects such as <a href="/en-US/docs/Web/SVG">SVG</a>,
  <a href="/en-US/docs/Web/MathML">MathML</a> or
  <a href="/en-US/docs/Glossary/XHTML">XHTML</a>). CSS describes how elements
  should be rendered on screen, on paper, in speech, or on other media.
</p>
<p>
  CSS is among the core languages of the <strong>open web</strong> and is
  standardized across web browsers according to
  <a href="https://www.w3.org/Style/CSS/#specs" class="external" target="_blank"
    >W3C specifications</a
  >. Previously, the development of various parts of CSS specification was done
  synchronously, which allowed the versioning of the latest recommendations. You
  might have heard about CSS1, CSS2.1, or even CSS3. There will never be a CSS3
  or a CSS4; rather, everything is now just "CSS" with individual CSS modules
  having version numbers.
</p>
<p>
  After CSS 2.1, the scope of the specification increased significantly and the
  progress on different CSS modules started to differ so much, that it became
  more effective to
  <a
    href="https://www.w3.org/Style/CSS/current-work"
    class="external"
    target="_blank"
    >develop and release recommendations separately per module</a
  >. Instead of versioning the CSS specification, W3C now periodically takes a
  snapshot of
  <a href="https://www.w3.org/TR/css/" class="external" target="_blank"
    >the latest stable state of the CSS specification</a
  >
  and individual modules progress. CSS modules now have version numbers, or
  levels, such as
  <a
    href="https://drafts.csswg.org/css-color-5/"
    class="external"
    target="_blank"
    >CSS Color Module Level 5</a
  >.
</p>

<hr />

<p>
  <strong>JavaScript</strong> (<strong>JS</strong>) is a lightweight interpreted
  (or
  <a href="/en-US/docs/Glossary/Just_In_Time_Compilation"
    >just-in-time compiled</a
  >) programming language with
  <a href="/en-US/docs/Glossary/First-class_Function">first-class functions</a>.
  While it is most well-known as the scripting language for Web pages,
  <a
    href="https://en.wikipedia.org/wiki/JavaScript#Other_usage"
    class="external"
    target="_blank"
    >many non-browser environments</a
  >
  also use it, such as <a href="/en-US/docs/Glossary/Node.js">Node.js</a>,
  <a href="https://couchdb.apache.org/" class="external" target="_blank"
    >Apache CouchDB</a
  >
  and
  <a
    href="https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/"
    class="external"
    target="_blank"
    >Adobe Acrobat</a
  >. JavaScript is a
  <a href="/en-US/docs/Glossary/Prototype-based_programming">prototype-based</a
  >, <a href="/en-US/docs/Glossary/Garbage_collection">garbage-collected</a>,
  <a href="/en-US/docs/Glossary/Dynamic_typing">dynamic</a> language, supporting
  multiple paradigms such as imperative, functional, and object-oriented.
</p>
<p>
  JavaScript's dynamic capabilities include runtime object construction,
  variable parameter lists, function variables, dynamic script creation (via
  <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval"
    ><code>eval</code></a
  >), object introspection (via
  <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in"
    ><code>for...in</code></a
  >
  and
  <a
    href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#static_methods"
    ><code>Object</code> utilities</a
  >), and source-code recovery (JavaScript functions store their source text and
  can be retrieved through
  <a
    href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString"
    ><code>toString()</code></a
  >).
</p>
<p>
  This section is dedicated to the JavaScript language itself, and not the parts
  that are specific to Web pages or other host environments. For information
  about <a href="/en-US/docs/Glossary/API">APIs</a> that are specific to Web
  pages, please see <a href="/en-US/docs/Web/API">Web APIs</a> and
  <a href="/en-US/docs/Glossary/DOM">DOM</a>.
</p>
<p>
  The standards for JavaScript are the
  <a href="https://tc39.es/ecma262/" class="external" target="_blank"
    >ECMAScript Language Specification</a
  >
  (ECMA-262) and the
  <a href="https://tc39.es/ecma402/" class="external" target="_blank"
    >ECMAScript Internationalization API specification</a
  >
  (ECMA-402). As soon as one browser implements a feature, we try to document
  it. This means that cases where some
  <a href="https://github.com/tc39/proposals" class="external" target="_blank"
    >proposals for new ECMAScript features</a
  >
  have already been implemented in browsers, documentation and examples in MDN
  articles may use some of those new features. Most of the time, this happens
  between the
  <a href="https://tc39.es/process-document/" class="external" target="_blank"
    >stages</a
  >
  3 and 4, and is usually before the spec is officially published.
</p>
<p>
  Do not confuse JavaScript with the
  <a
    href="https://en.wikipedia.org/wiki/Java_(programming_language)"
    class="external"
    target="_blank"
    >Java programming language</a
  >
  — <strong>JavaScript is <em>not</em> "Interpreted Java"</strong>. Both "Java"
  and "JavaScript" are trademarks or registered trademarks of Oracle in the U.S.
  and other countries. However, the two programming languages have very
  different syntax, semantics, and use.
</p>
<p>
  JavaScript documentation of core language features (pure
  <a
    href="/en-US/docs/Web/JavaScript/Reference/JavaScript_technologies_overview"
    >ECMAScript</a
  >, for the most part) includes the following:
</p>
const checkbox = document.getElementById("set-wrap");
checkbox.addEventListener("change", () => {
  if (checkbox.checked) {
    document.body.style.columnWrap = "wrap";
  } else {
    document.body.style.columnWrap = "nowrap";
  }
});

CSS

Мы превращаем элемент <body> в многоколоночный контейнер, задавая свойству column-count значение 3. Затем мы задаём свойству gap значение 3em 2em, в результате чего промежуток между строками составляет 3em, а между столбцами — 2em.

Затем мы задаём column-height значение 90vh, благодаря чему высота столбцов почти равна высоте области просмотра. Мы также задаём для column-wrap значение nowrap, из-за чего лишние столбцы переполняют контейнер по горизонтали. Это необходимо, поскольку начальное значение column-wrap — auto, которое принимает значение wrap, если для column-height задано значение <length>.

Флажок переключает значение свойства column-wrap между nowrap и wrap. При значении wrap лишние столбцы с содержимым переполняют контейнер по вертикали и переносятся в новые строки, создавая вертикальную раскладку. Значение column-height приводит к тому, что каждая строка столбцов заполняет область просмотра.

body {
  column-count: 3;
  gap: 3em 2em;
  padding: 0 2em;
  column-height: 90vh;
  column-wrap: nowrap;
}

Далее мы задаём свойству column-span элемента <h1> значение all, чтобы заголовок занимал все столбцы, а свойству margin-top первого элемента <p> задаём значение 0, чтобы он располагался на одном уровне с верхней частью столбцов.

h1 {
  column-span: all;
}

p:first-of-type {
  margin-top: 0;
}
* {
  box-sizing: border-box;
}

html {
  font-family: "Arial", sans-serif;
}

p {
  line-height: 1.5;
}

@supports not (column-wrap: wrap) {
  body::before {
    content: "Your browser does not support the 'column-wrap' property.";
    background-color: wheat;
    position: fixed;
    inset: 40% 0;
    height: fit-content;
    text-align: center;
    padding: 1rem 0;
  }
}

form {
  position: fixed;
  top: 0;
  right: 0;
  background-color: white;
  padding: 5px;
  border: 1px solid black;
}

Результат

Установите или снимите флажок, чтобы изменить значение свойства column-wrap и переключить раскладку между горизонтальной и вертикальной прокруткой. Если для column-wrap задано значение nowrap, столбцы переполняют контейнер по горизонтали; если для column-wrap задано значение wrap, вертикально добавляются новые строки столбцов.

Спецификации

Спецификация
Модуль многоколоночной раскладки CSS, уровень 2
# propdef-column-wrap

Совместимость с браузерами

Настольные компьютеры Мобильные устройства
Chrome Edge Firefox Opera Safari Chrome для Android Firefox для Android Opera для Android Safari на iOS Samsung Internet WebView для Android WebView на iOS
column-wrap
145
145
Нет
129
Нет
145
Нет
96
Нет
Нет
145
Нет
auto
145
145
Нет
129
Нет
145
Нет
96
Нет
Нет
145
Нет
nowrap
145
145
Нет
129
Нет
145
Нет
96
Нет
Нет
145
Нет
wrap
145
145
Нет
129
Нет
145
Нет
96
Нет
Нет
145
Нет

См. также

  • column-count
  • column-width
  • columns — сокращённое свойство
  • column-height
  • модуль многоколоночной раскладки CSS

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/column-wrap

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API