margin-bottom

CSS margin-bottom Property

The margin-bottom property sets the bottom margin of an element.

Note: Negative values are allowed.

Default value: 0
Inherited: no
Animatable: yes, see individual properties. Read about animatable Try it
Version: CSS1
JavaScript syntax: object.style.marginBottom=»100px» Try it

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

CSS Syntax

Property Values

Value Description Demo
length Specifies a fixed bottom margin in px, cm, em, etc. Default value is 0. Negative values are allowed. Read about length units Demo ❯
% Specifies a bottom margin in percent of the width of the containing element Demo ❯
auto The browser calculates a bottom margin Demo ❯
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Margin Collapse

Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins.

This does not happen on horizontal (left and right) margins! Only vertical (top and bottom) margins!

Look at the following example:

Example

In the example above, the

element has a top and bottom margin of 20px.

More Examples

Example

Set the bottom margin for a

element to 10% of the width of the container:

Example

Set the bottom margin for a

element to 2 em:

Источник

CSS Margins

Margins are used to create space around elements, outside of any defined borders.

CSS Margins

The CSS margin properties are used to create space around elements, outside of any defined borders.

With CSS, you have full control over the margins. There are properties for setting the margin for each side of an element (top, right, bottom, and left).

Margin — Individual Sides

CSS has properties for specifying the margin for each side of an element:

All the margin properties can have the following values:

  • auto — the browser calculates the margin
  • length — specifies a margin in px, pt, cm, etc.
  • % — specifies a margin in % of the width of the containing element
  • inherit — specifies that the margin should be inherited from the parent element

Tip: Negative values are allowed.

Example

Set different margins for all four sides of a

element:

Margin — Shorthand Property

To shorten the code, it is possible to specify all the margin properties in one property.

The margin property is a shorthand property for the following individual margin properties:

If the margin property has four values:

  • margin: 25px 50px 75px 100px;
    • top margin is 25px
    • right margin is 50px
    • bottom margin is 75px
    • left margin is 100px

    Example

    Use the margin shorthand property with four values:

    If the margin property has three values:

    • margin: 25px 50px 75px;
      • top margin is 25px
      • right and left margins are 50px
      • bottom margin is 75px

      Example

      Use the margin shorthand property with three values:

      If the margin property has two values:

      • margin: 25px 50px;
        • top and bottom margins are 25px
        • right and left margins are 50px

        Example

        Use the margin shorthand property with two values:

        If the margin property has one value:

        Example

        Use the margin shorthand property with one value:

        The auto Value

        You can set the margin property to auto to horizontally center the element within its container.

        The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.

        Example

        The inherit Value

        Example

        div <
        border: 1px solid red;
        margin-left: 100px;
        >

        All CSS Margin Properties

        Property Description
        margin A shorthand property for setting all the margin properties in one declaration
        margin-bottom Sets the bottom margin of an element
        margin-left Sets the left margin of an element
        margin-right Sets the right margin of an element
        margin-top Sets the top margin of an element

        Источник

        margin-bottom

        Устанавливает величину отступа от нижнего края элемента. Отступом является расстояние от внешнего края нижней границы текущего элемента до внутренней границы его родительского элемента (рис. 1).

        Рис. 1. Отступ от нижнего края элемента

        Рис. 1. Отступ от нижнего края элемента

        Синтаксис

        margin-bottom: значение | auto | inherit

        Значения

        Величину нижнего отступа можно указывать в пикселах (px), процентах (%) или других допустимых для CSS единицах. Значение может быть как положительным, так и отрицательным числом.

        auto Указывает, что размер отступов будет автоматически рассчитан браузером. inherit Наследует значение родителя.

        HTML5 CSS2.1 IE Cr Op Sa Fx

               
        Lorem ipsum dolor sit amet

        Результат данного примера показан на рис. 2.

        Применение свойства margin-bottom

        Рис. 2. Применение свойства margin-bottom

        Объектная модель

        [window.]document.getElementById(» elementID «).style.marginBottom

        Браузеры

        Браузер Internet Explorer 6 в некоторых случаях некорректно вычисляет значение отступа, заданное в процентах.

        Internet Explorer до версии 7.0 включительно не поддерживает значение inherit .

        Источник

        margin-bottom¶

        Свойство margin-bottom устанавливает величину отступа от нижнего края элемента.

        Отступом является расстояние от внешнего края нижней границы текущего элемента до внутренней границы его родительского элемента (рис. 1).

        Рис. 1. Отступ от нижнего края элемента

        Демо¶

        Синтаксис¶

         1 2 3 4 5 6 7 8 9 10 11 12
        /* values */ margin-bottom: 10px; /* An absolute length */ margin-bottom: 1em; /* relative to the text size */ margin-bottom: 5%; /* relative to the nearest block container's width */ /* Keyword values */ margin-bottom: auto; /* Global values */ margin-bottom: inherit; margin-bottom: initial; margin-bottom: unset; 

        Значения¶

        Величину нижнего отступа можно указывать в пикселях (px), процентах (%) или других допустимых для CSS единицах. Значение может быть как положительным, так и отрицательным числом.

        auto Указывает, что размер отступов будет автоматически рассчитан браузером.

        Применяется ко всем элементам

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

        Описание и примеры¶

         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
         html> head> meta charset="utf-8" /> title>margin-bottomtitle> style> .layer1  background: #8b0086; /* Цвет фона */ color: white; /* Цвет текста */ padding: 10px; /* Поля вокруг текста */ margin-bottom: -7px; /* Отступ снизу */ > .layer2  margin-left: 40px; /* Отступ слева */ background: #e9c1e4; /* Цвет фона */ padding: 10px; /* Поля вокруг текста */ > style> head> body> div class="layer1"> Невротический инвариант в XXI веке div> div class="layer2"> Весьма существенно следующее: аллегория монотонно иллюстрирует невротический холерик, таким образом, второй комплекс движущих сил получил разработку в трудах А.Берталанфи и Ш.Бюлера. div> body> html> 

        Источник

Оцените статью