How to make a line in css. Horizontal and vertical lines in HTML. What is a horizontal line and what is it for?

From the author: I salute you. The need to present several blocks on a web page in one line is a very common task that layout designers face. It occurs during the layout of almost every template, so in any case, we all need to know and apply the basic ways to change the behavior of blocks.

Before we look at the most common techniques, I would like to remember a little theory. Web page elements are divided into block and inline elements. And the difference between them is very simple - lowercase ones can be placed on one line, but block ones cannot. Of course, the differences don't end there, but this is the main difference. Blocks can already have padding at the top and bottom (lowercase ones do not), and more properties can be applied to them.

Basic ways to line up blocks in CSS

We won’t complicate anything, there are 3 main ways:

Convert blocks to inline elements. In this case, block properties are lost, so this option is almost never used

Make the necessary elements block-line. This is a special type in which the element retains its properties, but at the same time allows other blocks to be located nearby.

Make elements float using the float property.

Let's focus on these options. We will not consider Flexbox, table display and other aspects. So, let's say we have 3 subheadings.

Heading 1

Heading 2

Heading 3

Naturally, all css properties must be written in a separate file (style.css), which must be connected to the html document. In this file I will write a minimal style so that our subheadings are simply visible.

h3( background: #EEDDCD; )

h3 (

background : #EEDDCD;

Here they are on the page:

They behave like blocks. Each one is located on its own line, there are indents between them. If you wish, you can also set any internal padding and do whatever you want.

Let's convert it to lines and immediately add indents. To do this, the h3 selector needs to add the following properties:

display: inline; padding: 30px;

There are 2 main problems that arise when using this technique. The first is the minimum indentation. It is formed due to the fact that in the code there is one space between the blocks, which forms this indentation. If this problem needs solving, there are 2 main options:

In html, place the code of the required blocks in one line without spaces

Add a negative margin to the right of -4 pixels. That's how much one space takes.

The second problem is that if the elements have different heights, display problems may arise. All in all, best option- floating blocks. Instead of display: inline-block we write this:

Blocks in a line using the framework

I’ll say right away that if you are going to use any normal CSS framework (for example, Bootstrap), then everything is still much simpler. All the CSS code responsible for arranging the elements has already been written and all you have to do is set the correct classes. To do this, just learn the grid system, and you will be able to make multi-column responsive templates without much difficulty. At least it will be much easier than writing css from scratch.

Another challenge of writing code from scratch comes just when you need adaptive design. Of course, you can implement it yourself by owning media queries, but it will be much more difficult if you have a complex template.

For example, when you have big screens there should be 4 columns, on the middle ones - 3, and on mobile phones— 2. With the help of frameworks such as Bootstrap, or rather with the help of its grid, implementing something like this is a matter of just a few minutes.

Smoothly translating the topic to the Bootstrap framework, I will once again note that if you are faced with the task of laying out a complex adaptive template, then it is simply a sin not to use the grid. You don't even need to connect to do this. full version framework - you can customize it and stop there only what you really need.

You can learn how to work with the framework using . The theory is explained there, but most importantly, there is practice. You are making up 3 adaptive template and get great experience that will allow you to design websites to order or for yourself. And if you want to get acquainted with the advantages and capabilities of the framework for free, I suggest you look through our series of articles on Bootstrap, as well as on simple layout design. I wish you success in layout and website building in general.

It would seem, why might four methods be needed? 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 so I got 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, dotted line using keyboard

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

Rice. 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 Word editor we get a dotted line of any length.

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

  • We find the “dash” key on the keyboard (to the right of the “zero” key, in the green frame in Fig. 1).
  • From a new (!) line in Word, press this key several times: -
  • And then press the “Enter” () key. A few printed dashes will suddenly turn into a continuous horizontal thin line across the entire width of the page.

2) When you simultaneously press Shift and “-” (dash), NOT a dash is printed, but an underscore _________. This way you can make a continuous line of arbitrary length anywhere in the document.

Rice. 2. Thin and thick horizontal line in Word

Now let's print fat horizontal line across the entire width of the page:

  • Again we find the same dash key, and also Shift key(left or right, as you like). Press Shift, hold and don't let go.
  • And now, from a new (!) line, click on the dash several times (for example, 3-4 times) (while not 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 (1x1), in which only the top or bottom border is colored (will be visible), and the other three sides of the table have uncolored borders (they will be invisible).

Place 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).

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

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

All that remains is to remove the borders from three sides in the 1x1 table. 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).

Rice. 4. How to remove border selection from a Word table (make borders invisible)

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

By the way, in Fig. 3 it is clear that there is an easier way. You can place the cursor at the beginning of the line in Word and click “Horizontal Line” (5 in Fig. 4):

III Line in Word using drawing

Insert (1 in Fig. 5) - Shapes (2 in Fig. 5) - this 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.

Rice. 5. How to draw a line in Word

IV Line in Word using the on-screen keyboard

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

For Windows 10, you can also find the on-screen keyboard by typing “on-screen keyboard” into the Search bar.

Rice. 6. On-screen keyboard

We will create a horizontal line in the same way as in the first option with regular keyboard. You will need three buttons on the on-screen keyboard: dash, Shift and Enter.

1 Dash and Enter

From a new line in Word, click on the dash (1 in Fig. 6) several times and press Enter. You will get 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). You will get an underline. We will repeat this 2 more times, and then press Enter. As a result, we will see a thick horizontal line.

Hi all! Today I will tell you about how to using html make a horizontal line.

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

Horizontal and vertical lines using css

You can do this with using css. To do this, I enclose the required section of text in a block using a 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 using css directly from the html code, and made the top border solid and the bottom dotted line.

This is what it will look like on the page:

Horizontal line using css.

This method has its advantages:

  • A large assortment settings that allow you to set almost any type 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 cumbersomeness of the code.

However, as it turned out, you can insert a horizontal line into the text using html. At the same time, you don’t even have to go into css. The tag is used for this


.

Horizontal line using html tag

The first feature of this tag is that it does not have a paired closing 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 percentages;
  • Color– defines the color of the line;
  • Align– sets the alignment of the line to the right edge – right, to the left edge – left, in the center – center;
  • Size– line thickness in pixels.

Here is an example of html code.

Horizontal lines formed by an unpaired (no closing tag needed) tag


and can be quite unique design elements. Formatting the text with the addition of horizontal HTML lines will give the page a certain logic of presentation of the text, and will also make it easier for the reader to highlight blocks of information that need to be studied sequentially. Tag
can form horizontal lines of different colors, thicknesses and lengths. And this is quite simple to do, as shown in the examples below.

By the way, you can also use block style properties

And
for forming lines
at a certain location. True, this option may not always be convenient, for example, painting sometimes does not always pay off, but in many cases it is possible to solve problems in this way. For example, inside a line formed tag
you can't insert text. But inside blocks, this is possible and is constantly practiced. So you need to choose your option depending on the design requirements.

Vertical lines in HTML.

A vertical lines are formed in fact in the same blocks

And
.
The only inconvenience is that the tag is not available in all browsers.
works the same, but you have to try
and adjust the page, or use updated browsers.

Formation of horizontal lines:

Tag
inserts a horizontal line onto the page and has the following attributes:

Tag syntax
:

Examples of horizontal lines in HTML:

Examples of vertical lines in HTML:


Here is an example of a red vertical line on the left.

Here is an example of a red vertical line on the right.

Here is an example of a horizontal red line at the top.

Here is an example of a horizontal line in red below.

Here is an example of horizontal and vertical lines.

Syntax for examples of vertical and horizontal lines in HTML:

pay attention to the style attribute
border- left(-right): 4px solid #FF0000;:

Circle formed using a tag


Here is an example of a red vertical line on the left.

Here is an example of a red vertical line on the right.

Here is an example of a horizontal line in red below.

Here is an example of horizontal and vertical lines.

And if we analyze these examples, we can draw a fairly simple conclusion that vertical lines are best formed using, and intermediate line options can be made with tag


But it all depends on imagination and requests. So choose and shape.

While creating HTML pages design plays a significant role. Especially when we are talking about various symbols and decorative design: these little things help make the “language” of your page more accessible and clear, and also significantly change its perception and appearance generally. One of the most important elements for design is the horizontal line, and then 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 the effective separation of information of different meanings.
  3. Highlighting or emphasizing. Draws the attention of page guests to the necessary and most important information.

It is the horizontal line that is considered the most in an accessible way to implement a range of functions. It is very simple to create, and from the outside it looks very advantageous. By simple changes to the html code you can adjust:

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

It is worth noting that the horizontal line refers to block elements. This means that she takes new line on the page, and the text that follows it will go below.

Creating a Horizontal Line in HTML

You can set a line using a simple tag – hr in triangular brackets. It is short for “Horizontal Rule” and sets classic external parameters. It differs from many others in that it does not need a closing tag and is able to exist independently. Change external characteristics element using additional values ​​in 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 percentages. This is done for help additional word“width” in the tag and a numeric length indicated after the “=” sign in quotes.

It looks like this. For example, if we need a length of 100 pixels, we set the following tag: hr width=”100″

  1. Alignment. Alignment is possible to the left or right edges, and also to the center. This characteristic only works if you have already specified the width parameter, since a line that spans the entire page cannot be aligned. For alignment, we set an additional attribute in the “align” tag and add a direction to it: center – for central, left – for left and right – for right alignment.

The finished tag in this case will look like this. For example, if we need to set the center alignment for a horizontal line 150 pixels long, then the finished tag will look like this: hr align=”center” width=”150″.

Note that "align", the alignment metric, is placed in 1st place, even though the attribute is dependent on the width metric.

  1. Width. You can also choose to specify the width, creating a bold or thin underline. This criterion does not depend on anything and can be used as an independent criterion without specifying 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 quotation marks after the size attribute and the “=” symbol.

Thus, if we need to create a line with a width of 15 pixels, we need to create the following tag: hr size=”15″.

  1. Color. It is also specified as an independent indicator. To change it, use the color attribute in combination with the name of the color in the form of a code or English language. The color is indicated in quotation marks after the “=” symbol.

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

Black can be created using the code #000000.

  1. Put away shadow. If you need an element that does not contain a shadow, then you should use the noshade attribute 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

Creating a Horizontal Line Using Video

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

Having determined required dimensions A horizontal line can be used to design website pages in such a way that the information is structured and visually well-designed. This helps visitors more easily perceive the information presented and makes your site stand out from others.