Example:
<h1>s</h1>
<h2>ame</h2>
<p>li</p>
<p>ne</p>
How would I all these elements on the same line instead of each one being put on a new line by default.
Any help is sincerely appreciated :)
Example:
<h1>s</h1>
<h2>ame</h2>
<p>li</p>
<p>ne</p>
How would I all these elements on the same line instead of each one being put on a new line by default.
Any help is sincerely appreciated :)
Add display: inline
or display: inline-block
to the CSSs OF the elements:
<h1>s</h1>
<h2>ame</h2>
<p>li</p>
<p>ne</p>
OUTPUT:
S
ame
li
ne
Add the CSSs:
<h1>s</h1>
<h2>ame</h2>
<p>li</p>
<p>ne</p>
<style>
h1, h2, p {
display: inline;
}
</style>
OUTPUT:
Sa me li ne
These (by default) are displayed as block elements.
Using CSS, you can change the way they behave.
For example, by default display parameter in CSS for the <h1>
tag in CSS is this:
h1 { display: block; }
To make it appear inline, you would do:
h1 { display: inline-block; }
So if you were to do:
h1, h2, p { display: inline-block; }
The output of your HTML code:
<h1>s</h1>
<h2>ame</h2>
<p>li</p>
<p>ne</p>
Would be:
sameline
View this answer to understand the differences between block
and inline-block
:
https://stackoverflow.com/a/14033814/1332068
I don't know why you are using those HTML Elements but with CSS you can achieve it:
<h1 style="display:inline-block">s</h1><h2 style="display:inline-block">ame</h2><p style="display:inline-block">li</p><p style="display:inline-block">ne</p>