Css line. How to make a line using HTML and CSS. Lines in CSS

Hello! Today I will tell you how to make a horizontal line using html.

In fact, the need to make a horizontal line occurs quite often, for example, when you need to separate one part of the text from another.

Horizontal and vertical lines with css

This can be done using css. To do this, I enclose the required area of \u200b\u200btext in a block using the div tag, and then in the style.css file or directly in the html code, we write properties for this block for the top or bottom border using border-top and border-bottom. Here's an example:

Vertical HTML line

Horizontal line using css.

In this case, I set the styling with css directly from the html code, and made the top border a solid line and the bottom one a dashed line.

This is how it will look on the page:

Horizontal line using css.

This method has its advantages:

  • A wide range of settings that allow you to set almost any kind of line;
  • You can create both horizontal and vertical lines. In order to make vertical lines, you need to change border-top to border-left and border-bottom to border-right.

The disadvantages include the relative bulkiness of the code.

However, as it turned out, you can also insert a horizontal line into the text using html. At the same time, it is not even necessary to go into css. To do this, use the tag


.

Horizontal line using html tag

The first feature of this tag is that it does not have a matching end tag. It can be used anywhere in the html code between tags and.

This tag has the following attributes:

  • Width - determines the length of our horizontal line in pixels or percent;
  • Color - defines the line color;
  • Align - sets the alignment of the line to the right - right, left - left, center - center;
  • Size - line width in pixels.

Here is an example html code.

It would seem, why might you need four methods? After all, almost every person uses one method to which he is accustomed. For example, I pressed Shift and the "dash" key several times, and that's a horizontal line.

But what if this results in a dotted line, but you need a solid one?
- Most likely, the Shift key on the keyboard is faulty. Other methods will come to the rescue here.

3.
4.
5.

Perhaps the most common way to make a line in Word is to use a couple of keys on the keyboard.

I Thin, thick, double, dashed line by keyboard

Below is a drawing of a keyboard with an English, but without Russian layout, but it does not matter, because we are only interested in three keys: Shift, dash and Enter.

Figure: 1. Three keys on the keyboard: Shift, dash and Enter for a continuous horizontal line in Word

With these three keys, you can draw a continuous horizontal line in Word: dotted or solid, thin or thick, long or short.

1) When you press the "-" (dash) key several times in the Word editor, we get a dotted line of any length.

To do thin a long line across the full width of the page:

  • We find on the keyboard the "dash" key (to the right of the "zero" key, in the green frame in Fig. 1).
  • With a new (!) Line in Word, press this key several times: -
  • And then press the "Enter" () key. Several dashes that have been printed will suddenly become a continuous, horizontal, thin line across the entire width of the page.

2) When Shift and "-" (dash) are pressed simultaneously, NOT a dash is printed, but an underline _________. Thus, you can make a continuous line of arbitrary length anywhere in the document.

Figure: 2. Thin and thick horizontal line in Word

Now we print thick a horizontal line to fill the entire page width:

  • Again we find the same dash key, as well as the Shift key (left or right, as you like). Press Shift, hold and don't let go.
  • And now with a new (!) Line several times (for example, 3-4 times) press on the dash (without releasing Shift): ___. Release Shift.
  • Now press the Enter key. You will see a thick horizontal solid line.

Let's summarize some results in the form of a table:

(Click to enlarge) Lines in Word using the keyboard

­­­­­­­­­­­­­­­­­­­­­

II Line in Word using a table

A horizontal line can be obtained by using a table of one cell (1 × 1), in which only the upper or lower border is colored (will be visible), and the other three sides of the table have uncolored borders (they will be invisible).

We put the cursor in the place where the line should be. In the top menu of Word, click:

  • Insert (1 in Fig. 3),
  • Table (2 in Fig. 3),
  • One cell (3 in Fig. 3).

Figure: 3. How to insert a 1x1 table in Word (from one cell)

The result will be a table of one large cell (1x1):

It remains in the 1x1 table to remove the borders from three sides. For this

  • go to the "Home" tab (1 in Fig. 4),
  • then next to "Font" we find "Paragraph" and borders (2 in Fig. 4),
  • remove all borders by clicking "No border" (3 in Fig. 4),
  • select "Upper border" or "Lower border" (4 in Fig. 4).

Figure: 4. How to remove the selection of borders in the Word table (make borders invisible)

I show this clearly in the video (at the end of the article).

By the way, in fig. 3 shows that there is an easier way. You can put the cursor at the beginning of the line in Word and click "Horizontal Line" (5 in Fig. 4):

III Line in Word by Drawing

Insert (1 in Fig. 5) - Shapes (2 in Fig. 5) is another way to get a horizontal line in Word.

To keep the line strictly horizontal, hold down the Shift key and draw the line at the same time.

Figure: 5. How to draw a line in Word

IV Line in Word using the on-screen keyboard

To find the on-screen keyboard, in Search, enter the phrase "on-screen keyboard", more for Windows 7, and for Windows 8.

For Windows 10, you can also find the onscreen keyboard by typing “onscreen keyboard” in the Search bar.

Figure: 6. On-screen keyboard

We will create a horizontal line in the same way as in the first version with a regular keyboard. On the onscreen keyboard, you need three buttons: dash, Shift and Enter.

1 Dash and Enter

From a new line in Word, click several times on the dash (1 in Fig. 6) and press Enter. This will create a thin horizontal line.

2 Shift, Dash and Enter

From a new line in Word, first click Shift (2 in Fig. 6), then Dash (1 in Fig. 6). The result is an underline. So let's repeat 2 more times, and then press Enter. As a result, we will see a thick horizontal line.

When creating an HTML page, layout plays an essential role. Especially when we are talking about various symbols and decorative design: these little things help to make the "language" of your page more accessible and clear, moreover, they significantly change its perception and overall appearance. One of the most important elements for design is a horizontal line, and further we will learn in more detail how to work with it and how to make a horizontal line in html.

What is a horizontal line and what is it for

A horizontal line in html is a page design element that performs a number of functions:

  1. Decorative... Helps add attractiveness to the page.
  2. Dividing... Promotes effective separation of information of different meanings.
  3. Emphasizing or underlining... Draws the attention of page guests to the necessary and most important information.

It is the horizontal line that is considered the most affordable way to implement a number of functions. It is very simple to create it, but outwardly it looks very profitable. By simple changes to the html-code, you can adjust:

  • length;
  • width;
  • color characteristics;
  • alignment to one or the other edge.

Note that the horizontal line refers to block elements. This means that it occupies a new line on the page, and the text following it will go below.

Create a horizontal line in HTML

You can set a line using a simple tag - hr in triangle brackets. It is short for "Horisontal Rule" and sets the classic external parameters. It differs from many others in that it does not need an end tag and is able to exist on its own. You can change the external characteristics of an element using additional values \u200b\u200bin the tag:

  1. Length... If you do not want the length of the line to extend over the entire page, then you can set the desired size in pixels or percent. This is done using the additional word "width" in the tag and the numeric length indicator specified after the "\u003d" sign in quotes.

It looks like this. For example, if we want a length of 100 pixels, we would set a tag like this: hr width \u003d "100"

  1. Alignment... Alignment is possible on the left or right edges, and also in the center. This feature is only valid if you have already specified the width parameter, since a full-page line cannot be aligned. To align, set an additional attribute in the "align" tag and add a direction to it: center - for center, left - for left and right - for right alignment.

The finished tag will then look like this. For example, if we need to set the center alignment for a horizontal line with a length of 150 pixels, then the finished tag will look like this: hr align \u003d "center" width \u003d "150".

Note that "align", the measure for alignment, is put in position 1, even though the attribute is dependent on the length measure width.

  1. Width... Optionally, you can also specify the width, creating a bold or thin underline. This criterion does not depend on anything and can be used independently without specifying the length or alignment. For it, we use the size attribute in the tag and a numeric value equal to the desired width in pixels. The number is indicated in quotes after the size attribute and the "\u003d" symbol.

Thus, if we need to create a line 15 pixels wide, we need to create the following tag: hr size \u003d "15".

  1. Colour... It is also set as an independent indicator. To change it, use the color attribute in combination with the color name in the form of a code or in English. The color is indicated in quotes after the "\u003d" symbol.

Thus, the tag for a standard white line can be written in two ways: hr color \u003d "#FFFFFF" or hr color \u003d "white"

Black can be created using code # 000000.

  1. Remove shadow... If you need an element that does not contain a shadow, then the noshade attribute should be used in the tag. It can be used alone or in combination with other elements. A tag for a standard line using it will look like this: hr noshade

Create a horizontal line using video

And if you want to get information in a more visual format, then refer to the next video, which describes in detail the possibilities of working with a horizontal line.

Having determined the required dimensions of the horizontal line, you can design the site pages in such a way that the information is structured and visually competently framed. This helps visitors to more easily perceive the information presented and make your site stand out from others.