Spec-Zone.ru › CSS

Свойство CSS `shape-margin`

Базовая поддержка Широко доступно

Эта функция хорошо зарекомендовала себя и работает на многих устройствах и в разных версиях браузеров. Она доступна во всех браузерах с января 2020 года.

Свойство shape-margin CSS задаёт отступ для CSS-фигуры, созданной с помощью shape-outside.

Отступ позволяет настроить расстояние между краями фигуры (плавающего элемента) и окружающим содержимым.

Попробуйте

shape-margin: 0;
shape-margin: 20px;
shape-margin: 1em;
shape-margin: 5%;
<section class="default-example" id="default-example">
  <div class="example-container">
    <div class="transition-all" id="example-element"></div>
    We had agreed, my companion and I, that I should call for him at his house,
    after dinner, not later than eleven o'clock. This athletic young Frenchman
    belongs to a small set of Parisian sportsmen, who have taken up "ballooning"
    as a pastime. After having exhausted all the sensations that are to be found
    in ordinary sports, even those of "automobiling" at a breakneck speed, the
    members of the "Aéro Club" now seek in the air, where they indulge in all
    kinds of daring feats, the nerve-racking excitement that they have ceased to
    find on earth.
  </div>
</section>
.example-container {
  text-align: left;
  padding: 20px;
}

#example-element {
  float: left;
  margin: 20px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background-color: rebeccapurple;
  shape-outside: circle(50%);
}

Синтаксис

/* <length> values */
shape-margin: 10px;
shape-margin: 20mm;

/* <percentage> value */
shape-margin: 60%;

/* Global values */
shape-margin: inherit;
shape-margin: initial;
shape-margin: revert;
shape-margin: revert-layer;
shape-margin: unset;

Значения

<length-percentage>
Задаёт отступ фигуры как значение <length> или как <percentage> от ширины содержащего блока элемента.

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

Начальное значение 0
Применяется к плавающим элементам
Наследуется нет
Проценты относительно ширины содержащего блока
Вычисленное значение как задано, но относительные длины преобразуются в абсолютные
Тип анимации $1$, <a href="/en-US/docs/Web/CSS/Reference/Values/percentage#interpolation" title="Значения CSS-типа данных <percentage> интерполируются как действительные числа с плавающей запятой.">процент</a> или calc();

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

shape-margin = 
  <length-percentage>

<length-percentage> = 
  <length> |
  <percentage>

Примеры

Добавление отступа к многоугольнику

HTML

<section>
  <div class="shape"></div>
  We are not quite sure of any one thing in biology; our knowledge of geology is
  relatively very slight, and the economic laws of society are uncertain to
  every one except some individual who attempts to set them forth; but before
  the world was fashioned the square on the hypotenuse was equal to the sum of
  the squares on the other two sides of a right triangle, and it will be so
  after this world is dead; and the inhabitant of Mars, if one exists, probably
  knows its truth as we know it.
</section>

CSS

section {
  max-width: 400px;
}

.shape {
  float: left;
  width: 150px;
  height: 150px;
  background-color: maroon;
  clip-path: polygon(0 0, 150px 150px, 0 150px);
  shape-outside: polygon(0 0, 150px 150px, 0 150px);
  shape-margin: 20px;
}

Результат

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

Спецификация
CSS Shapes Module Level 1
# shape-margin-property

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

Компьютеры Мобильные устройства
Chrome Edge Firefox Opera Safari Chrome Android Firefox для Android Opera Android Safari на iOS Samsung Internet WebView Android WebView на iOS
shape-margin
37
79
62
24
10.1
10.1
37
62
24
10.3
3.0
37
10.3

См. также

  • CSS-фигуры
  • Обзор CSS-фигур
  • shape-outside
  • shape-image-threshold
  • <basic-shape>

© 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/shape-margin

Spec-Zone.ru

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