Перейти к содержимому

Свойство CSS margin-right

Свойство margin-right используется для определения размера правого отступа элемента.

INFO

Допускаются отрицательные значения.

Начальное значение0
Применяется кВсем элементам. Также применяется к ::first-letter.
НаследуетсяНет.
АнимируетсяДа. Правый отступ элемента может анимироваться.
ВерсияCSS2
Синтаксис DOMobject.style.marginRight = "50px";

Синтаксис

Синтаксис свойства CSS margin-right

css
margin-right: length | auto | initial | inherit;

Пример свойства margin-right:

Пример использования свойства CSS margin-right со значением в пикселях

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .right {
        margin-right: 400px;
      }
    </style>
  </head>
  <body>
    <h2>Margin-right property example</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p class="right">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </body>
</html>

Результат

Свойство CSS margin-right

Пример свойства margin-right, заданного в "%":

Пример использования свойства CSS margin-right со значением в процентах

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .right {
        margin-right: 50%;
      }
    </style>
  </head>
  <body>
    <h2>Margin-right property example</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <p class="right">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
  </body>
</html>

Пример свойства margin-right со значением "auto":

Пример свойства margin-right со значением "auto":

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .right {
        margin-right: auto;
      }
    </style>
  </head>
  <body>
    <h2>Margin-right property example</h2>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
    </p>
    <p class="right">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
    </p>
  </body>
</html>

Значения

ЗначениеОписаниеЗапустить
autoУстанавливает правый отступ. Это значение по умолчанию для данного свойства.Запустить »
lengthОпределяет правый отступ в пикселях, пунктах, сантиметрах и т. д. Значение по умолчанию — 0.Запустить »
%Устанавливает правый отступ в % от размера родительского элемента.Запустить »
initialЗаставляет свойство использовать значение по умолчанию.Запустить »
inheritНаследует свойство от родительского элемента.

Практика

Что делает CSS-свойство 'margin-right'?

Считаете ли это полезным?

Предпросмотр dual-run — сравните с маршрутами Symfony на продакшене.