The border is there, but the left and right border take up the whole screen. How do i get it to just border the “Welcome To My First Website” bit? This is a probably a real basic thing but i cant seem to figure it out.
edit: i see you cant see the html, but its basically the text enclosed with p tags
It is difficult to know what you are talking about, can you share more details?
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I am new to HTML/CSS as well so I apologise in advance if I make a mistake. p is a block element an it takes up the whole screen by default. This is why the border is over the entire screen. For now you can add width property for the p element and play around with different values in pixels.
So i used text-align: center; but adding display: inline-block; resetted it to the left again. Is that expected behavior and how can i center it again?
There is no difference between using inline-block and setting the width to fit the content in this regard. You can’t center the content if the element is content sized. What you can do, is center the element itself.
<p class="fit-content">Welcome To My First Website</p>
<p class="inline-block">Welcome To My First Website</p>
<hr>
<div class="container">
<p class="fit-content">Welcome To My First Website</p>
<p class="inline-block">Welcome To My First Website</p>
</div>
.fit-content {
border: 2px solid red;
width: fit-content;
/* visually does nothing */
text-align: center;
}
.inline-block {
display: inline-block;
border: 2px solid red;
/* visually does nothing */
text-align: center;
}
/* centers the elements, not the element content */
.container {
display: grid;
justify-content: center;
}