0

When using this code:

<h2>Text</h2>
<h2>More Text</h2>

It ends up like this:

Text
More Text

For some reason, it feels as though there is an invisible barrier to the right of the two texts, preventing me from placing them side by side. (or even to the opposite side of the screen).

This is what I want it to look like:

Text                             More Text
sadeq shahmoradi
  • 1,395
  • 1
  • 6
  • 22

1 Answers1

0

In HTML, there are two types of elements: block and inline.

The h2 element is a block element.

According to w3schools

A block-level element always starts on a new line, and the browsers automatically add some space (a margin) before and after the element. A block-level element always takes up the full width available (stretches out to the left and right as far as it can). An inline element does not start on a new line. An inline element only takes up as much width as necessary.

for example :

.border-red{
  border: 1px solid red;
}
<span class="border-red" >Hello World (span element is an inline)</span>
<button class="border-red" >Hello World (button element is an inline)</button>

<h2 class="border-red" > Hello world (h2 element is a block) </h2>
<p class="border-red" > Hello world (p element is a block) </p>

You can modify these behaviors using CSS.

.border-red {
  border: 1px solid red;
}

.inline {
  display: inline
}

.block {
  display: block
}
<span class="border-red block" >Hello World (span element is inline)</span>
<button class="border-red block" >Hello World (button element is inline)</button>

<h2 class="border-red inline" > Hello world (h2 element is a block) </h2>
<p class="border-red inline" > Hello world (p element is a block) </p>
sadeq shahmoradi
  • 1,395
  • 1
  • 6
  • 22