Меню
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON PHP КАК СДЕЛАТЬ
     ❯   

CSS Справочники


CSS Свойства





margin-top



Example

Set the top margin for a <p> element to 25 pixels:

p.ex1 {
  margin-top: 25px;
}
Try it Yourself »

Definition margin-top

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

Note: Negative values are allowed.

Show demo ❯

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

Browser Support margin-top

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

Property
margin-top 1.0 6.0 1.0 1.0 3.5


CSS Syntax margin-top

margin-top: length|auto|initial|inherit;

Property Values margin-top

Value Description Demo
length Specifies a fixed top margin in px, pt, cm, etc. Default value is 0px. Negative values are allowed. Read about length units Demo ❯
% Specifies a top margin in percent of the width of the containing element Demo ❯
auto The browser calculates a top 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
p.a {
  margin: 30px 0;
}

p.b {
  margin: 20px 0;
}
Try it Yourself »

In the example above, the <p class="a"> element has a top and bottom margin of 30px. The <p class="b"> element has a top and bottom margin of 20px.

This means that the vertical margin between <p class="a"> and <p class="b"> should be 50px (30px + 20px). But due to margin collapse, the actual margin ends up being 30px!


More Examples margin-top

Example

Set the top margin for a <p> element to 10% of the width of the container:

p.ex1 {
  margin-top: 10%;
}
Try it Yourself »
Example

Set the top margin for a <p> element to 2 em:

p.ex1 {
  margin-top: 2em;
}
Try it Yourself »

Related Pages margin-top

CSS tutorial: CSS Margin

HTML DOM reference: marginTop property



×

Связаться с отделом продаж

Если вы хотите использовать услуги schoolsw3 как образовательное учреждение, команда или предприятие, отправьте нам электронное письмо:
sales@schoolsw3.com

Сообщить об ошибке

Если вы хотите сообщить об ошибке или внести предложение, отправьте нам электронное письмо:
help@schoolsw3.com

Schoolsw3 оптимизирован для обучения и подготовки. Примеры могут быть упрощены для улучшения чтения и обучения. Учебники, ссылки и примеры постоянно проверяются, чтобы избежать ошибок, но мы не можем гарантировать полную правильность всего контента.
При использовании Schoolsw3 вы соглашаетесь прочитать и принять наши условия использования,
политику использования файлов cookie и конфиденциальности.

Авторское право 1999- © Copyright. Все права защищены. Schoolsw3 работает на SW3.CSS.