Examining text indentation in html. Change padding and top spacing to CSS Top padding html

Today we will talk with you a little about the principles of layout, namely, about how to organize the indentation of certain elements on your site.

The element in question to be indented can be text, an image, a table, or any other HTML element. The main thing is to follow some important rules, which I will tell you about now.

If you are just creating your site, then I recommend that you insert the following properties at the top of your main stylesheet:

* (-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;) *: before, *: after (-webkit-box-sizing: border- box; -moz-box-sizing: border-box; box-sizing: border-box;)

Why is this necessary, you ask? I am answering your question with an illustrative example.

Let's say you have a layout element like this:

Hello world!

This is how the option would look like without using the properties described above (top element) and using them (bottom element):

What can you see here? That the width of the element in the first version (without using properties) has become larger than the specified one due to the added padding, which is not entirely convenient and correct in terms of layout

The option with properties is much more aesthetically pleasing, but it is worth using it consciously, because when you add them to a ready-made site, you risk getting a bad design and a "headache" in the form of bringing all this into proper form. All projects that I have had a chance to lead from scratch have not been without these properties.

And now, in fact, let's talk about the options for organizing the indentation of elements on your site with illustrative examples.

Padding with the "padding" CSS property

So that you understand the whole logic of things, let's take the following layout snippet as an example:

Hello world!
Hello world!

with their styles:

Test_div (width: 250px; border: 1px solid;)

The visual version is as follows:


What is the property “ padding"? It helps to organize padding on the specified elements. Let's add a 10px padding to our layout:

Test_div (width: 250px; border: 1px solid; padding: 10px; // Padding 10px)

Visually, it turns out like this:


The number 10 in the property means that inside the specified elements, on each of their four sides, an indent of 10px must be added. Pixels (px) can be replaced with percentages or other supported CSS values.

There are two options in total indication of the sides from which to indent.

The first - this with an explicit indication of the parties:

Padding-top: 10px; // 10px padding on top padding-right: 10px; // 10px padding to the right padding-bottom: 10px; // Bottom padding 10px padding-left: 10px; // 10px padding to the left

In this case, each side uses its own property. AND second:

Padding: 10px 0 0 0; // 10px padding on top, everything else is 0px padding: 10px 0; // 10px top and bottom padding and 0px padding on the sides padding: 0 10px; // 0px padding on top and bottom, and 10px on the sides

This is a simple enumeration of values, each corresponding to a different side. The sides are set like this: the first value is top, the second is right, the third is bottom and the fourth is left, that is, everything is clockwise.

If there are two values \u200b\u200b(top and right), then this means that the mirror values \u200b\u200bof the same values \u200b\u200bgo down and to the left, and only so. Everything seems to be clear. If you do not need to set the indent for some of the sides, set the value for this side to "0". I like this option more, as it is more compact, but in my endeavors I used the first option.

This type of indentation is good for separating text, table cell content, and other text information. To separate the elements themselves, similar to those in the example above, there is another property.

Padding with the CSS "margin" property

A distinctive feature of the property " margin"Is what the padding is added outside the element, that is, outside.

There are also two options for adding here.

The first - with an explicit indication of the party:

Margin-top: 10px; // 10px padding on top margin-right: 10px; // 10px margin on the right margin-bottom: 10px; // Bottom padding 10px margin-left: 10px; // 10px padding to the left

Second - with an enumeration of values, each of which corresponds to its own side:

Margin: 10px 0 0 0; // 10px top margin, everything else is 0px margin: 10px 0; // 10px padding on top and bottom, and 0px on the sides margin: 0 10px; // Outside padding is 0px top and bottom and 10px on the sides

I will not describe all the nuances of working with the rules here, everything is the same as about the property “ padding», It is written about it above.

We use margin with the following value:

Test_div (width: 250px; border: 1px solid; margin: 10px; // Padding 10px)

Visually, it will look like this:


As you can see from the example, in this case, an external indent is added, separating the indicated elements.

Important feature: If you looked closely at the result, you might have noticed that adjacent padding of elements is not summed up. That is, if the first element has an outer bottom padding of 10px, and the second has an outer top padding with the same value, then the total distance between them will also be 10px. If 10 and 15, respectively, then the total is 15, and so on.

This type of indentation is often used in text, namely in the design of paragraphs, as well as in elements that have visible borders.

But both properties are not limited to just these elements. You choose the options for using them yourself, I just tried to give you the basis about them.

Anya wrote the following code (example 1) and got the page shown in fig. 1. But Anya needs no space between blocks, as well as to the right and left of the blocks. What changes to the code is required for this?

There is too much indent between the heading and the main text, how can I reduce it?

To paragraph (tag

) and title (tag

) automatically adds top and bottom padding, which add up to a large spacing between the heading and the text. To reduce the amount of padding, you need to explicitly add the margin-bottom property to the H1 selector. Moreover, you can set a positive, zero or negative value. This way it is easy to set the desired indentation value.

How do I indent the first line for each paragraph?

When you need to set up paragraph indentation, it is best to use the text-indent style property. Its value determines how much to shift the text of the first line to the right of its original position. In this case, the width of the text block does not change and remains initially set. The amount of indentation can be specified in pixels, percentage or other available units (example 1).

How to remove top and bottom indentation from the list?

Use the style property margin-top and margin-bottom for the UL or OL selector, depending on the list type. You can also use the generic margin property.

How do I change the indentation on a web page?

The padding on the web page, while not visible, does not allow the content to fit snugly against the edges of the browser window for a comfortable reading. You can set your own margin value by changing the margin property of the body selector.

How do I remove padding around a form?

When adding a form via a tag

padding is automatically added around it at the top and bottom. To remove them, use the nullable margin style property by adding it to the FORM selector.

How do I change the spacing between paragraphs of text?

When using the tag

Indents are automatically added to the top and bottom of the text paragraph. This is done in order to visually separate one block of text from the next. It is clear that the default indentation values \u200b\u200bare not always satisfactory, so sometimes they have to be decreased or increased. To do this, you can use the universal property margin, it defines the indents on all sides of the paragraph or margin-top for the top indent and margin-bottom for the bottom indent.

Hello, dear readers of the blog site! Today we will continue our exploration of Cascading Style Sheets or CSS. In previous articles, we have already examined in general terms the block layout of the site. As a result, we started to get quite professional web pages, but something is missing. And most likely they lack indents and frames. Today we are going to take a look at the style rules margin, padding and border, which allow you to set margins and borders for html-elements.

CSS indentation options

With cascading style sheets, there are two kinds of indentation.

1. Inner padding Is the distance from the imaginary border of an element to its content. The distance is set using the parameter padding... This indentation belongs to the element itself and is located inside it.

2. External indent - the distance between the border of the current element of the web page and the borders of neighboring elements, or the parent element. The size of the distance is controlled by the property margin... This indent is outside the element.

For clarity, the picture:

For example, consider a cell filled with text. Then the padding is the distance between the imaginary border of the cell and the text it contains. And the outer margin is the distance between the borders of adjacent cells. Let's start with padding.

Padding in CSS with padding (top, bottom, left, right)

The style properties padding-left, padding-top, padding-right and padding-bottom allow you to set the amount of padding, respectively, to the left, top, right and bottom of a web page element:

padding-top | padding-right | padding-bottom | padding-left: value | interest | inherit

The amount of indentation can be specified in pixels (px), percentage (%) or other units acceptable for CSS. When specifying a percentage, the value is calculated from the width of the element. The inherit value indicates that it is inherited from the parent.

For example, for the current paragraph, I've applied a style rule that sets the left padding to 20 pixels, the top padding to 5 pixels, to the right padding to 35 pixels, and to the bottom 10 pixels. The rule entry in will look like this:

p.test (
padding-left: 20px;
padding-top: 5px;
padding-right: 35px;
padding-bottom: 10px
}

Combined rule of padding allows you to specify indents on all sides of a web page element at once:

padding:<отступ 1> [<отступ 2> [<отступ 3> [<отступ 4>]]]

In the collective rule, it is allowed to use one, two, three or four values, separating them with a space. In this case, the effect depends on the number of values:

  • if you specify one value, then it will set the amount of indentation on all sides of the page element;
  • if you specify two values, then the first will set the amount of indentation at the top and bottom, and the second - on the left and right;
  • if you specify three values, the first will determine the amount of indentation at the top, the second - to the left and right, and the third - from the bottom;
  • if four values \u200b\u200bare specified, the first will set the padding to the top, the second to the right, the third to the bottom, and the fourth to the left.

Thus, the above CSS rule can be shortened as much as possible and written as follows:

p.test (padding: 5px 35px 10px 20px)

Margin property or margins in CSS

The style attributes margin-left, margin-top, margin-right, and margin-bottom allow you to set the margin values \u200b\u200bfor the left, top, right, and bottom, respectively:

margin-top | margin-right | margin-bottom | margin-left:<значение>| auto | inherit

As mentioned above, the outer padding is the distance from the border of the current element to the border of the adjacent element, or, if there are no adjacent elements, to the inner border of the parent container.

The amount of indentation can be specified in pixels (px), percentage (%) or other units acceptable for CSS:

p (
margin-left: 20px;
}
h1 (
margin-right: 15%;
}

The auto value means that the size of the indents will be automatically calculated by the browser. In the case of using a percentage notation, the indents are calculated depending on the width of the parent container... And this applies not only to margin-left and margin-right, but also for margin-top and margin-bottom indents in percent will be calculated depending on the width, not the height of the container.

It is permissible to use as margins values negative values:

p (
margin-left: -20px;
}

If, with positive values \u200b\u200bof the margins, adjacent elements move away, then with a negative value, the adjacent block will run over the element for which we set such negative margins.

We can also specify margins using the style attribute margin... It sets the amount of indentation from all sides of the web page element simultaneously:

margin:<отступ 1> [<отступ 2> [<отступ 3> [<отступ 4>]]]

This property, in the case of setting one, two, three or four padding values, obeys the same laws as the padding rule.

Border options using the border property

When customizing frames, there are three types of parameters:

  • border-width - border thickness;
  • border-color - border color;
  • border-style - the type of line with which the border will be drawn.

Let's start with the border thickness parameter:

border-width: [value | thin | medium | thick] (1,4) | inherit

Frame thickness can be set in pixels, or in other units available in css. The variables thin, medium and thick set the border thickness to 2, 4 and 6 pixels, respectively:

border-width: medium;

As with the padding and margin properties, you can use one, two, three, or four values \u200b\u200bfor the border-width parameter, thus setting the border width for all sides at once or for each one separately:

border-width: 5px 3px 5px 3px

For the current paragraph, let's make the top border 1px, right 2px, bottom 3px, and left 4px using the rule (border-width: 1px 2px 3px 4px;)

The style attributes border-left-width, border-top-width, border-right-width, and border-bottom-width can be used to set the width of the left, top, right, and bottom sides of the border, respectively:

border-left-width | border-top-width | border-right-width | border-bottom-width: thin | medium | thick |<толщина>| inherit

The next parameter is border-color with which you can control frame color:

border-color: [color | transparent] (1,4) | inherit

The property allows you to set the border color for all sides of the element at once or only for the specified ones. As a value, you can use the methods of specifying colors accepted in html for colors: hexadecimal code, keywords, etc .:

p (border-width: 2px; border-color: red)

The transparent value sets the border color to transparent, and inherit inherits from the parent. By default, if the border color is not specified, then the one used for the font inside this element will be used.

The style attributes border-left-color, border-top-color, border-right-color, and border-bottom-color can be used to set the color of the left, top, right, and bottom sides of the border, respectively:

border-left-color | border-top-color | border-right-color | border-bottom-color: transparent |<цвет>| inherit

And the last border-style parameter sets frame type:

border-style: (1,4) | inherit

The frame type can be specified for all sides of the element at once or only for the specified ones. Several keywords can be used as values. The appearance will depend on the browser used and the thickness of the border. Value none is used by default and does not display the frame and its thickness is set to zero. The hidden value has the same effect. The resulting frame for the rest of the values \u200b\u200bdepending on the thickness is shown in the table below:

The style attributes border-left-style, border-top-style, border-right-style, and border-bottom-style specify the style of the lines that will be used to draw the left, top, right, and bottom sides of the border, respectively:

border-left-style | border-top-style | border-right-style | border-bottom-style: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset | inherit

As with the padding and padding options, there is generic border property... It allows you to simultaneously set the thickness, style and color of the border around the element:

border: | inherit

The values \u200b\u200bcan be in any order, separated by spaces:

td (border: 1px solid yellow)

To set the border only on certain sides of an element, there are the border-top, border-bottom, border-left, border-right properties, which allow you to set the parameters for the top, bottom, left and right sides of the frames, respectively.

It remains only to summarize:

  • to assign padding we use the property padding;
  • for settings margins there is a rule margin;
  • frame options are set using the attribute border.

Note that all these css properties increase the size of the web page element. Therefore, if we change the width of the border or the size of the indents of the block containers that form the design of the web page, we will have to resize these containers accordingly, otherwise they may shift and the design will be broken.

That's all, see you soon!

Hello! Initially I wanted to divide this article into 4 small ones, but then I thought about it. What for? It is more convenient when such information is collected within one material.

Therefore, today we will learn how to indent CSS on the left and on all other sides - right, top and bottom. They can be done for pictures and texts. They are of two types:

  • External;
  • Internal.

For the first, the key property margin is used, for the second, padding. For clarity, I made a small example for you. To make it visually convenient to distinguish between internal and external space, I added a visible table. Let's see what happened?

External padding

By registering them in the CSS stylesheet, you can set the orientation of the information block on the page. For example, move it left and down. Let's immediately demonstrate how it will look.

In general, you can use the options below to set indents.

Left (margin-left).

Right (margin-right).

Top (margin-top).

Bottom (margin-bottom).

Now I'll show you another cool nuance.

As you can see, you can use one of the options - the effect is the same. Only in the second case is the code more compact. Also note that the padding is clockwise. It all starts at the top and ends on the left.

Internal padding

The procedure is similar here. Only now I will add new properties not for the entire table, but for the contents of the columns.

Let's see what came of it.

By analogy with inner margins in CSS, outer margins can be written in shorthand code or for the sides separately.

These were the highlights. Finally, I'll show you how you can make some of the work easier.

Indentation at the level of selected tags

In the cases that we looked at above, they are set for text and images at the same time. In fact, you can set the distance to elements at the level of a specific tag. I'll show you how it works. Undo the last changes and put the custom code in the stylesheet.

Let's take a look at what happened after saving the changes.

The picture remained in place, only the text enclosed in the left moved. Similar manipulations can be applied to other blocks, for example, tr, span.

As additional information, I propose a publication about the task for review. Quite interesting methods are also described there. It can be useful for forming a red line in the text or performing other actions.

Additionally, there is a subscription to the free distribution of information by email addresses. There is a special form for subscribing to the blog. Until next time.

Indentation in html document

"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercising ullamco laboris nisi aliquip ex ea commodo consequat. Duis aute irureit dolor in repre sent velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. " Paragraph 1.10.32 "de Finibus Bonorum et Malorum", written by Cicero in 45 AD. "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam volatatem sitia quasi. consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolim volt minimu aliquamate , quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur , vel illum qui dolorem eum fugiat 1914 English translation, H. Rackham "But I must explain to you how all this mistaken idea of \u200b\u200bdenouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness.No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resulta nt pleasure? " Paragraph 1.10.33 "de Finibus Bonorum et Malorum", written by Cicero in 45 AD. "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati non provident, similique sunt in culpa qui qui officia deserunt mollitia labor. Et al. rerum facilis est et expedita distinctio.Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.Tempor necessitibus autem quibusdam autatiut re officiis debus ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat. " 1914 English translation, H. Rackham "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided.But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains. "