When you set the content:
for a pseudo-element, it is applied to the pseudo-element itself and not the actual element. This is why adding content to ::before
places it before the text of the element, while using ::after
will place it after the text.
To set the initial text using pseudo-elements as well, you can try the following approach:
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
body {
background-color: #006400;
display: grid;
place-items: center;
}
main {
padding: 1em;
display: flex;
flex-direction: column;
gap: 1em;
}
.btn {
border: 3px solid black;
text-align: center;
border-radius: 20px;
letter-spacing: 2px;
padding: 1em 1.5em;
background-color: #ffd700;
color: black;
font-family: monospace;
display: inline-block;
margin: 1em;
}
.btn::after {
display: inline-block;
}
.btn--empty::after {
content: "";
}
.btn--pseudo::after {
content: "lorem";
}
.btn:hover::after {
content: "ipsum";
}
<html>
<body>
<main>
<a class="btn btn--empty" href="#"></a>
<a class="btn btn--pseudo" href="#"></a>
</main>
</body>
</html>