Reputation: 165
I have created code to print some data.
<!DOCTYPE html>
<html>
<body>
<h1>The p element</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
This give me a result below:
The p element
This is a paragraph.
This is a paragraph.
This is a paragraph.
But what i want to do is to join this three lines without removing <p>
tag.
My expected result is:
The p element
This is a paragraph. This is a paragraph. This is a paragraph.
Upvotes: 2
Views: 508
Reputation: 421
Use display: flex
and flex-direction: row
, optionaly can include gap
:
<!DOCTYPE html>
<html lang="en">
<head>
<title>The p element</title>
<style>
.wrapper {
display: flex;
flex-direction: row;
gap: 4px;
}
</style>
</head>
<body>
<h1>The p element</h1>
<div class="wrapper">
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</div>
</body>
</html>
Upvotes: 2
Reputation: 36512
THere is no need to add to the DOM in order to achieve this, and to keep your semantics as they are you probably shouldn't.
Instead CSS can be used to make the p elements display inline-block.
<!DOCTYPE html>
<html>
<head>
<style>
p {
display: inline-block;
}
</style>
</head>
<body>
<h1>The p element</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
Upvotes: 3
Reputation: 1154
You can add display:inline for p tag:
p {
display: inline
}
<!DOCTYPE html>
<html>
<body>
<h1>The p element</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
Upvotes: 2
Reputation: 554
As mentioned above, changing a bit the structure should do the trick. Just wrap your three p
elements into a div
and use flexbox
.
.wrapper {
display: flex;
align-items: center;
}
<h1>The p element</h1>
<div class="wrapper">
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</div>
Upvotes: 6