Using the css property ::before, I am attempting to insert a tag before a paragraph. While I am able to display the tag correctly, it is causing the text within the paragraph to be shifted to the right. Ideally, I would like the tag to appear in the top-left corner of the paragraph with the text positioned beneath it.
In my search for a solution, I referred to w3schools for guidance.
I also explored the website where I found the desired design, however, I was unable to comprehend the underlying technique. The link to the website is: Fetch API. The specific feature I am trying to replicate can be found under section 2.1 URL on this website.
.note {
background-color: #C7FDBC;
padding: 0.6em;
margin-left:1em;
margin-top: 2em;
margin-bottom: 1.5em;
}
.note::before {
content: "Note";
background-color: green;
color: white;
font-weight: bold;
padding: 0.4em;
position: relative;
top: -1.6em;
left: -1.3em;
}
<p class="note">The note</p>
The desired outcome resembles the notes layout in the fetch api. While my result bears similarities, the text within the paragraph is being displaced to the right by an amount equal to the width of the content inserted using ::before.