Displaying a pseudo-element behind a parent div's text while appearing in front of the parent div itself

I am trying to create a unique design with a psuedo element that has a pink background within a div. Here is the code snippet:

<div>
  Hello
</div>

div {
  background-color: green;
  display: inline-block;
  padding: 20px;
  position: relative;
}

div::after {
  content: "";
  background-color: pink;
  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

If you want to visualize it, check out this Codepen link: http://codepen.io/acha5066/pen/oXVPzg. My goal is to have the pink background in front of the green one but behind the text "Hello." How can I achieve this effect?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Difficulty with Jquery's random selection of grid divs

I am working on a grid layout consisting of 9 divs nested in columns of three. The objective is that when the main grid (with ID #left) is clicked, two divs from the middle row (row="1") should have the class .show randomly applied to them. In the column w ...

Is it possible to reorganize the order of elements in a

My goal is to create a flex column layout where the image appears first. However, I'm facing an issue with the code below, as it only changes the order when the flex direction is set to row (image on the left). It does not work for rows. </head> ...

Tips for altering the color of input text in CSS with the inclusion of the Bootstrap framework

I'm having trouble changing the color of input text to black in Bootstrap. <input type="text" id="name" name="nomclient" style="background-color: white;" style="color: black;" /> ...

What is causing the top and bottom margins to be invisible in my browser?

Why can't I see the top and bottom margins in Safari, Chrome, or Firefox when I've set the margin to 50px? HTML: <div style="width:400px;background-color:#ffffaa"> <p style="background-color:#aaffff; padding:20px; ...

Jquery animation in Wordpress without any need for scrolling

My Wordpress site features some animations that work flawlessly when the site is scrolled. The code looks like this: jQuery(document).ready(function($){ $(window).scroll( function(){ if(!isMobile) { $('.animate_1').each ...

Thinking about how to incorporate the value of a JavaScript variable into a CSS variable?

I am attempting to utilize Window.innerWidth and load the resulting value into a CSS variable, but it doesn't appear to be functioning correctly. What could I be doing incorrectly? function myFunction() { var w = window.innerWidth; document. ...

Tips for concealing a div when clicking on an element solely with CSS

I am currently working on creating a CSS Main Menu in Vue. The functionality is such that it pops up when the mouse hovers over it, and hides when the mouse moves out. However, I am facing an issue with hiding the menu when clicking on a hyperlink a. Any s ...

Turn off Chrome's standard headers and footers when printing to PDF in headless mode

I have encountered a challenge with exporting a multipage HTML document to PDF using headless Google Chrome / Chromium from the command line. The issue arises when Chrome automatically adds headers and footers during the "printing" process. Although some h ...

Why is my Tailwind Grid displaying elements in a horizontal layout?

<div className='grid grid-cols-12 gap-12 mb-8'> <div className='col-span-8'> <div className='box'></div> </div> <div className='col-span-4'> <d ...

Tips for customizing the color scheme of background, rows, row selection, and headers in Angular 4 using Bootstrap 4 data tables

I've integrated Bootstrap 4 data table in my Angular 4 project, but I'm struggling to customize row colors, row selection colors, and header colors. You can check out the example of the data table I'm using at this link: https://github.com/ ...

Reverse the CSS animation direction

I am facing an issue with an animation that moves in one direction. I am looking to reverse the animation so it goes back to its original position: $('#right').click(function() { $('.container').removeClass('.move-left'). ...

What could be causing the dropdown menu to be unresponsive in my HTML and CSS code?

I am struggling to figure out why my drop-down menu is not appearing on my website. Even after removing the 'hidden' property, it still doesn't look right when I hover over the 'servicios' tab. I can't seem to pinpoint the iss ...

Position Bootstrap 5 modal footer elements to the left and right for an enhanced visual

Can anyone assist me with customizing the Bootstrap 5 modal footer? I am looking to align a text (either using span or label) to the left and a button to the right within the modal footer. I came across this solution and attempted to implement it by cha ...

Any idea why divs are not fading in properly?

Seeking assistance to make these div's fade in, but they are not cooperating! Unsure if this is the most effective method, but aiming to acquire the skills needed to create animations similar to the ones on this website: When scrolling down the page, ...

Tips for updating the parent element when hovering over a child in CSS

Is there a way to change the background color of the parent product when hovering over a link or details using only CSS? HTML CODE <div id="summary" align='center'>Products</div> <div id="detail" align='center'& ...

Looking to add elements to a specific div dynamically using jQuery? Let's explore how to insert comments seamlessly

I would like to implement a comment system that adds entered comments to a specific div. Here's the code I have so far: <ul class="comments"> <li> <a class="commenter_name" href="/">Dushyanth Lion</a> ...

error in css styling detected

Why was the CSS style "background-position: center;" missed? It was because the background will override the background-position property. <html> <head> <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" ...

Neighbor wrapping causing Flex to shrink

Is there a way to make the element shrink when the flex container below grows due to flex-wrapping? Currently, the new space is created below the container instead of shrinking the one above. The flex-grow and flex-shrink properties do not seem to work as ...

Can the element be partially covered while remaining exposed to the cursor?

In the design, I am looking to add overlay images to the menu while ensuring that the entire menu item is clickable, not just a portion of it. Currently, only the top part of the button is clickable in the implementation found at .elem { display: inl ...

Generating custom-styled entries using Word VBA

I have set up styles in my Word document, such as My_Style (which I use for titles). I am looking to create entries for illustrations that correspond to the number from that particular style. Here is the code snippet I am using: Sub Macro4() ' &apos ...