What is margin and padding in css

What is margin and padding in css

  • CSS Text Formatting
  • CSS text-align-last Property
  • CSS text-decoration Property
  • CSS text-decoration-color Property
  • CSS text-decoration-line Property
  • CSS text-decoration-style Property
  • CSS text-indent Property
  • CSS text-justify Property
  • CSS text-overflow Property
  • CSS text-transform Property
  • CSS text-shadow Property
  • CSS letter-spacing Property
  • CSS line-height Property
  • CSS direction Property
  • CSS word-spacing Property
  • CSS Grid Layout Module
  • CSS column-gap Property
  • CSS gap Property
  • CSS grid Property
  • CSS grid-area Property
  • CSS grid-auto-columns Property
  • CSS grid-auto-flow Property
  • CSS grid-auto-rows Property
  • CSS grid-column Property
  • CSS grid-column-end Property
  • CSS grid-column-gap Property
  • CSS grid-column-start Property
  • CSS grid-gap Property
  • CSS grid-row Property
  • CSS grid-row-end Property
  • CSS grid-row-gap Property
  • CSS grid-row-start Property
  • CSS grid-template Property
  • CSS grid-template-areas Property
  • CSS grid-template-columns Property
  • CSS grid-template-rows Property
  • Write an Interview Experience
  • Share Your Campus Experience
  • CSS Tutorial
  • CSS Introduction
  • CSS Syntax
  • CSS Comments
  • CSS Colors
  • CSS Borders
  • CSS Margins and Padding
  • CSS Height and Width
  • CSS Outline
  • CSS Fonts
  • CSS Icons
  • CSS Links
  • CSS Lists
  • CSS Tables
  • CSS Display property
  • CSS max-width Property
  • CSS Positioning Elements
  • CSS z-index Property
  • CSS Overflow
  • CSS Float
  • CSS Align
  • CSS Combinators
  • CSS Pseudo-classes
  • CSS Pseudo Elements
  • CSS Opacity / Transparency
  • CSS DropDowns
  • CSS Image Gallery
  • CSS Image Sprites
  • CSS Attribute Selector
  • CSS Counters
  • CSS Website Layout
  • CSS Units
  • CSS | Specificity
  • How to apply !important in CSS?
  • CSS Text Formatting
  • CSS text-align-last Property
  • CSS text-decoration Property
  • CSS text-decoration-color Property
  • CSS text-decoration-line Property
  • CSS text-decoration-style Property
  • CSS text-indent Property
  • CSS text-justify Property
  • CSS text-overflow Property
  • CSS text-transform Property
  • CSS text-shadow Property
  • CSS letter-spacing Property
  • CSS line-height Property
  • CSS direction Property
  • CSS word-spacing Property
  • CSS Grid Layout Module
  • CSS column-gap Property
  • CSS gap Property
  • CSS grid Property
  • CSS grid-area Property
  • CSS grid-auto-columns Property
  • CSS grid-auto-flow Property
  • CSS grid-auto-rows Property
  • CSS grid-column Property
  • CSS grid-column-end Property
  • CSS grid-column-gap Property
  • CSS grid-column-start Property
  • CSS grid-gap Property
  • CSS grid-row Property
  • CSS grid-row-end Property
  • CSS grid-row-gap Property
  • CSS grid-row-start Property
  • CSS grid-template Property
  • CSS grid-template-areas Property
  • CSS grid-template-columns Property
  • CSS grid-template-rows Property
Читайте также:  Посчитать произведение цифр числа python

Источник

Чем отличаются padding и margin

У этого элемента есть пока невидимая граница border . Если мы отобразим эту границу, то увидим, что она прилипла к тексту.

А если поставим два таких элемента рядом, они почти прилипнут друг к другу, потому что между ними нет пространства:

Padding

Чтобы отодвинуть рамку нужен padding — внутреннее пространство между содержимым элемента и его границей border .

⭐ Padding — внутренний отступ.

padding можно задать отдельно сверху, справа, снизу и слева (то есть по часовой стрелке, начиная сверху). Или задать отдельно для верха-низа и право-лево, или вообще одинаковый для всех сторон.

Или даже все стороны по отдельности — вот так. Это аналог выражения padding: 10px 20px 30px 40px;

Все варианты padding одной картинкой:

Margin

margin — пространство от border , padding или контента до соседних элементов. Задаётся по такой же логике и тоже по часовой стрелке.

margin тоже можно задавать отдельно для всех сторон или сделать сразу одинаковым.

Внутренние и внешние отступы одной картинкой:

⭐ padding — внутри элемента, margin — снаружи.

Больше статей о выборе

«Доктайп» — журнал о фронтенде. Читайте, слушайте и учитесь с нами.

Источник

CSS Margin VS Padding – What is the Difference? [Solved]

Quincy Larson

Quincy Larson

CSS Margin VS Padding – What is the Difference? [Solved]

When it comes to CSS, there are a lot of properties that control the spacing of elements on a page. Two of the most common properties are margin and padding.

Both margin and padding control the amount of space around an element, but they do it in different ways.

Artboard-1

Margin is the space outside of an element. It is the space between an element and the elements around it.

If you want an element to be farther away from other elements, increase the margin property.

Padding is the space inside of an element. It is the space between an element and its content.

Example of Margin in CSS

Here is how you would give an element a margin in CSS:

Example of Margin in HTML

And here’s how you would style the element to have a margin using in-line in HTML. (Keep in mind that this is seen as a lazy practice in most cases.)

Example of Padding in CSS

Here is how you would give an element padding in CSS:

And of course, you can do this with an in-line style in HTML as well:

That’s it. Go forth and style your elements.

I hope you’ve found this helpful. If you want to learn more about programming and technology, try freeCodeCamp’s core coding curriculum. It’s free.

Quincy Larson

Quincy Larson

The teacher who founded freeCodeCamp.org.

If you read this far, tweet to the author to show them you care. Tweet a thanks

Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

freeCodeCamp is a donor-supported tax-exempt 501(c)(3) charity organization (United States Federal Tax Identification Number: 82-0779546)

Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons — all freely available to the public. We also have thousands of freeCodeCamp study groups around the world.

Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff.

Источник

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