-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
78 lines (56 loc) · 7.25 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: margin-right
slug: Web/CSS/margin-right
---
{{CSSRef}}
Свойство [CSS](/en/CSS) **`margin-right`** устанавливает [внешний отступ](/ru/docs/Web/CSS/box_model) справа от элемента. Положительное значение увеличивает расстояние между соседними элементами, тогда как отрицательное - сокращает.
{{EmbedInteractiveExample("pages/css/margin-right.html")}}
Вертикальные внешние отступы двух соседних блоков могут схлопнуться. Это называется [схлопыванием внешних отступов](/ru/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing).
## Синтаксис
```css
/* Ключевые слова */
margin-right: auto;
/* Значения длины */
margin-right: 20px; /* абсолютная длина */
margin-right: 1em; /* относительно размера текста */
margin-right: 5%; /* относительно ширины родительского блока */
/* Глобальные значения */
margin-right: inherit;
margin-right: initial;
margin-right: unset;
```
Свойство `margin-right` может быть выражено как ключевое слово `auto`, как `<число>`, или как `<процент>`. Значение может быть положительным, нулевым или отрицательным.
### Значения
- {{cssxref("<length>")}}
- : Размер отступа - фиксированная величина.
- {{cssxref("<percentage>")}}
- : Размер отступа в процентах - размер относительно длины родительского блока.
- `auto`
- : Внешний отступ слева получает долю неиспользованного горизонтального пространства, определяется в основном [выбранным способом разметки](/ru/docs/Web/CSS/Layout_mode). Если значения `margin-left` и `margin-right` одновременно установлены как `auto`, расчётное пространство распределяется равномерно. Эта таблица кратко излагает различные:
| Значение {{cssxref("display")}} | Значение {{cssxref("float")}} | Значение {{cssxref("position")}} | Расчётное значение `auto` | Комментарий |
| ------------------------------------------------------------------------------------------------- | ----------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `inline`, `inline-block`, `inline-table` | _любое_ | `static` или `relative` | `0` | Строчный способ разметки |
| `block`, `inline`, `inline-block`, `block`, `table`, `inline-table`, `list-item`, `table-caption` | _любое_ | `static` или `relative` | `0`, кроме случаев, когда `margin-left` и `margin-right` установлены как `auto`. В этом случае устанавливается значение, центрирующее элемент внутри его родителя | Блочный способ разметки |
| `block`, `inline`, `inline-block`, `block`, `table`, `inline-table`, `list-item`, `table-caption` | `left` или `right` | `static` или `relative` | `0` | Блочный способ разметки (плавающие элементы) |
| _любое_ `table-*`_, кроме_ `table-caption` | _любое_ | _любое_ | `0` | Внутренние `table-*` элементы не имеют отступов, вместо этого используйте {{ cssxref("border-spacing") }} |
| _любое, кроме `flex`,_ `inline-flex`_, или_ `table-*` | _любое_ | _`fixed`_ или `absolute` | `0`, кроме случаев, когда `margin-left` и `margin-right` установлены как `auto`. В этом случае, устанавливается значение центрирующее границы области внутри доступной `width` (ширины), если значение фиксировано. | Способ разметки абсолютным позиционированием |
| `flex`, `inline-flex` | _любое_ | _любое_ | `0`, кроме случаев, когда есть положительное горизонтальное свободное пространство. В этом случае, распределяется равномерно по всем горизонтальным `auto` отступам. | Способ разметки с помощью flexbox |
### Формальный синтаксис
{{csssyntax}}
## Примеры
```css
.content {
margin-right: 5%;
}
.sidebox {
margin-right: 10px;
}
.logo {
margin-right: -5px;
}
```
## Спецификации
{{Specifications}}
{{cssinfo}}
## Совместимость с браузерами
{{Compat}}