padding-left

CSS padding-left Property

An element’s padding is the space between its content and its border.

The padding-left property sets the left padding (space) of an element.

Note: Negative values are not allowed.

Default value: 0
Inherited: no
Animatable: yes. Read about animatable Try it
Version: CSS1
JavaScript syntax: object.style.paddingLeft=»50px» 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 left padding in px, pt, cm, etc. Default value is 0. Read about length units Demo ❯
% Specifies a left padding in percent of the width of the containing element Demo ❯
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

More Examples

Example

Set the left padding for a

element to 10% of the width of the containing element:

Example

Set the left padding for a

Читайте также:  Java plugin is blocked

element to 2 em:

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

padding-left

The padding-left CSS property sets the width of the padding area to the left of an element.

Try it

An element’s padding area is the space between its content and its border.

Note: The padding property can be used to set paddings on all four sides of an element with a single declaration.

Syntax

/* values */ padding-left: 0.5em; padding-left: 0; padding-left: 2cm; /* value */ padding-left: 10%; /* Global values */ padding-left: inherit; padding-left: initial; padding-left: revert; padding-left: revert-layer; padding-left: unset; 

The padding-left property is specified as a single value chosen from the list below. Unlike margins, negative values are not allowed for padding.

Values

The size of the padding as a fixed value. Must be nonnegative.

The size of the padding as a percentage, relative to the inline size (width in a horizontal language, defined by writing-mode ) of the containing block. Must be nonnegative.

Formal definition

Initial value 0
Applies to all elements, except table-row-group , table-header-group , table-footer-group , table-row , table-column-group and table-column . It also applies to ::first-letter and ::first-line .
Inherited no
Percentages refer to the width of the containing block
Computed value the percentage as specified or the absolute length
Animation type a length

Formal syntax

Examples

Setting left padding using pixels and percentages

.content  padding-left: 5%; > .sidebox  padding-left: 10px; > 

Specifications

Browser compatibility

BCD tables only load in the browser

See also

  • Introduction to the CSS basic box model
  • padding-top , padding-right , padding-bottom and the padding shorthand
  • The mapped logical properties: padding-block-start , padding-block-end , padding-inline-start , and padding-inline-end and the shorthands padding-block and padding-inline

Found a content problem with this page?

This page was last modified on Jul 18, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

padding-left

Устанавливает значение поля от левого края содержимого элемента. Полем называется расстояние от внутреннего края рамки элемента до воображаемого прямоугольника, ограничивающего его содержимое (рис. 1).

Рис. 1. Поле слева от текста

Рис. 1. Поле слева от текста

Синтаксис

padding-left: значение | проценты | inherit

Значения

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

HTML5 CSS2.1 IE Cr Op Sa Fx

       
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat. Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

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

Применение свойства padding-left

Рис. 1. Применение свойства padding-left

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

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

Браузеры

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

Источник

CSS Padding

Padding is used to create space around an element’s content, inside of any defined borders.

CSS Padding

The CSS padding properties are used to generate space around an element’s content, inside of any defined borders.

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

Padding — Individual Sides

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

All the padding properties can have the following values:

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

Note: Negative values are not allowed.

Example

Set different padding for all four sides of a element:

Padding — Shorthand Property

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

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

If the padding property has four values:

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

    Example

    Use the padding shorthand property with four values:

    If the padding property has three values:

    • padding: 25px 50px 75px;
      • top padding is 25px
      • right and left paddings are 50px
      • bottom padding is 75px

      Example

      Use the padding shorthand property with three values:

      If the padding property has two values:

      • padding: 25px 50px;
        • top and bottom paddings are 25px
        • right and left paddings are 50px

        Example

        Use the padding shorthand property with two values:

        If the padding property has one value:

        Example

        Use the padding shorthand property with one value:

        Padding and Element Width

        The CSS width property specifies the width of the element’s content area. The content area is the portion inside the padding, border, and margin of an element (the box model).

        So, if an element has a specified width, the padding added to that element will be added to the total width of the element. This is often an undesirable result.

        Example

        Here, the element is given a width of 300px. However, the actual width of the element will be 350px (300px + 25px of left padding + 25px of right padding):

        To keep the width at 300px, no matter the amount of padding, you can use the box-sizing property. This causes the element to maintain its actual width; if you increase the padding, the available content space will decrease.

        Example

        Use the box-sizing property to keep the width at 300px, no matter the amount of padding:

        More Examples

        Set the left padding
        This example demonstrates how to set the left padding of a

        element.

        Set the right padding
        This example demonstrates how to set the right padding of a

        element.

        Set the top padding
        This example demonstrates how to set the top padding of a

        element.

        Set the bottom padding
        This example demonstrates how to set the bottom padding of a

        element.

        All CSS Padding Properties

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

        Источник

        padding

        Свойство padding устанавливает внутренние отступы/поля со всех сторон элемента. Область отступов это пространство между содержанием элемента и его границей. Отрицательные значения не допускаются.

        Свойство padding краткая форма записи свойств, чтобы не писать отдельное правило для каждой стороны ( padding-top , padding-right , padding-bottom , padding-left ).

        • padding-bottom (en-US): 0
        • padding-left : 0
        • padding-right : 0
        • padding-top (en-US): 0
        • padding-bottom (en-US): процент, как указан, или абсолютная длина
        • padding-left : процент, как указан, или абсолютная длина
        • padding-right : процент, как указан, или абсолютная длина
        • padding-top (en-US): процент, как указан, или абсолютная длина

        Синтаксис

        /* Применяется для всех 4 сторон */ padding: 1em; /* По вертикали | По горизонтали */ padding: 5% 10%; /* Сверху | По горизонтали | Снизу */ padding: 1em 2em 2em; /* Сверху | Справа | Снизу | Слева */ padding: 2px 1em 0 1em; /* Глобальные значения */ padding: inherit; padding: initial; padding: unset; 

        Значения

        Укажите одно, два, три или четыре следующих значения:

        Устанавливает неотрицательный, фиксированный размер. Подробнее в разделе .

        Относительно ширины родительского блока.

        Источник

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