What could be causing the pseudo elements to not show up on the divs?

I've applied a after pseudo element to divs, but when I check the debugger view, no pseudo elements are showing up.

Even after looking at related posts, I still can't figure out why this is happening.

I would really appreciate any feedback or comments on this issue.

The operations that occur here are:

.col >  div:nth-child(1) {
    background:url("http://gdurl.com/hZIP");
    background-size:cover;
}
.col >  div:nth-child(1):after{
    position:absolute;
    top:0; left:0;  
    width:100%;height:100%;    
    background-color:black;
 }    

Here's a demo, https://jsfiddle.net/Debra321/432574uc/62/

html {
  box-sizing: border-box;
}

body {
  background: #fcfca4;
  background: linear-gradient(to top right, #F3E9D2, #EC9192);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

#phoneContent {
  position: absolute;
  top: 17.7%;
  left: 50px;
  width: 253px;
  height: 455px;
  display: block;
  margin: auto;
  overflow: auto;
}

#phoneContent .col {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.col>div {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.col>div:nth-child(1) {
  background: url("http://gdurl.com/hZIP");
  background-size: cover;
  //filter: brightness(50%);
}

.col>div:nth-child(1):after {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: black;
  //opacity:0;
  //transition: opacity 0.5s;
  //background:rgba(0,0,0,0.6);
}

.col>div:nth-child(1) :hover:after {
  opacity: 1;
}

.col>div:nth-child(2) {
  background-color: red;
}

.col>div:nth-child(3) {
  background-color: blue;
}

.col>div:nth-child(4) {
  background-color: red;
}

.st0 {
  fill: none;
  stroke: #FFFFFF;
  stroke-miterlimit: 10;
}

.st1 {
  fill: none;
  stroke: #DBDDDD;
  stroke-miterlimit: 10;
}

.st2 {
  fill: #FFFFFF;
}

.st3 {
  fill: none;
  stroke: #E5E5E5;
  stroke-miterlimit: 10;
}

.st4 {
  opacity: 0.3; 
  fill: none;
  stroke: #FFFFFF;
  stroke-miterlimit: 10;
}

#myPhone {
  position: relative;
  width: 350px;
  height: 700px;
  display: block;
  margin: auto;
}

Apply local draft version or discard it
<body>
  <div id="myPhone">
    <div id="phonediv">
      <svg version="1.1" id="phone" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 250 500" style="enable-background:new 0 0 250 500;" xml:space="preserve">
<g>
<path class="st0" d="M21,104.5c0,1.4-1.1,2.5-2.5,2.5l0,0c-1.4,0-2.5-1.1-2.5-2.5v-18c0-1.4,1.1-2.5,2.5-2.5l0,0
c1.4,0,2.5,1.1,2.5,2.5V104.5z"/>
 &;// more SVG code below...
<line class="st4" x1="34.5" y1="87" x2="217" y2="87"/>
</svg>
    </div>
    <div id="phoneContent">
      <div class="col">
        <div>

        </div>
        <div>
          <h1>
            TWO
          </h1>
        </div>
        <div>
          <h1>
            THREE
          </h1>
        </div>
        <div>
          <h1>
            FOUR
          </h1>
        </div>

      </div>

    </div>
  </div>
</body>

Answer №1

It is important to remember that the pseudo-elements ::after and ::before must always include the content property, even if it is empty (content: "").


.col > div:nth-child(1) {
  background: url("http://gdurl.com/hZIP");
  background-size: cover;
  filter: brightness(50%);
  position: relative; /* create nearest positioned ancestor for absolute positioning */
}


.col > div:nth-child(1):hover::after {
  content: ""; /* required for pseudo-elements to function */
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  cursor: pointer; /* optional */
}

updated fiddle

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

Is there a way to add a disappearing large space that vanishes when a line break occurs?

I am currently working on a website where I aim to have the name and airport code displayed in a centered title above an image of the airport. https://i.sstatic.net/Vwi2V.png The name and code will be separated by an em space: div.terminal-silhouette- ...

Gallery with blinking hover effect

I'm struggling with a blinking hover effect in my gallery made with HTML and CSS. I've been searching for a solution but can't seem to fix it. Can anyone offer some help? Check out the code on jsfiddle.com HTML: <div id="gallery"> ...

Unable to locate href within form when button is clicked

Whenever I try to click the borrow button, it directs me back to itself instead of executing the borrowing.php action. Can anyone suggest a solution for this issue? <form id = "myform" action="includes/borrowing.php" method = "POST" enctype ="multipart ...

Is there an event handler for clicking on the search field icon in HTML5

My html5 search field includes <input type='search'>, and I have a jQuery event set up to sort items as the user types. However, when the user presses the small X icon that appears on the right side of the input field to clear it, the jQuer ...

Using CSS to select a specific class within an attribute

Having trouble targeting a specific navigation item in a div using an attribute value in CSS. Here's the code I have so far: My goal is to target the navDepts class. HTML <div class="primary-nav" data-name="about"> <div class="sub ...

How to position a div in the center of another div using HTML

I'm struggling to center the bottom div within a container that includes 3 other divs. Despite trying multiple solutions found online, nothing seems to work. This task should be simple, but for some reason, I can't get it right. .container { po ...

Utilizing the Jquery ready method in conjunction with the load function

While utilizing the ready() method to access the DOM, I encountered an issue where jQuery was returning undefined when trying to access an element. Even after nesting the ready() function inside $(window).on("load", function()), there were still instances ...

Stop working to $(this) in jquery when clicking outside

I'm facing an issue with my code and would like some help. I have a button that toggles the visibility of a filter element, which is working fine. However, I now want to implement a "click outside" effect to close the filter when clicking on any body ...

Adjust the position of a trimmed image within an HTML5 canvas

Is there a way to shift the cropped image down by 100 pixels and left by 50 pixels within the canvas? View the code snippet below. Javascript // Grab the Canvas and Drawing Context var canvas = document.getElementById('c'); var ctx = canvas.get ...

Ways to trigger a click event on a dynamically added class utilizing $(this);

I am attempting to retrieve the text when clicking on dynamically appended HTML elements. After some research, I came across the following code snippet: $(document).on('click', '.myClass', function (). However, it seems to work only f ...

Row within table extending beyond boundaries of parent div table

Is there a way to make a table row wider than its parent table? I want the button at the bottom to extend beyond the borders of the table. https://i.sstatic.net/VH0HP.png Do I need to abandon the table styling to achieve this effect? Check out this JsF ...

Mastering the art of sorting HTML tables with various columns using JavaScript and jQuery

When they click the button, it should alphabetize the rows in the table according to the clicked column. Is there a way to achieve this sorting functionality without using a javascript/jquery plugin or library? I prefer to develop my own code for this pa ...

Personalizing Bootstrap 5 button designs and attributes for a customized look

In my project, I've set up my custom.scss file with the following code: $primary: #e84c22; $theme-colors: ( primary: $primary, ); @import "~bootstrap/scss/bootstrap.scss"; Currently, the color looks like this: https://i.sstatic.net/lbL ...

Leverage the power of HTML5 localstorage in order to maintain the toggle state of jQuery even

After discovering the HTML5 "localstorage" function, I decided to try implementing it in combination with jQuery toggle to keep a div in its most recent state even when the page is refreshed. It seems like a more modern alternative to using cookies. Howeve ...

Hide all elements in jQuery that do not have a class assigned

I've implemented a straightforward jQuery script that toggles the "active" class on an li element when it is clicked: $('li').click(function() { $(this).toggleClass('active'); }); My goal is to hide all other li elements in t ...

What is the method for making text uppercase within the Heading feature of Grommet?

Currently implementing grommet in my React project and exploring how to capitalize text within a few <Heading /> components. ...

TPL operating on a List that is stocked with merchandise

I am facing an issue with the following code snippet: {[displayDate(dateRelease);]} Every model available in the store comes with a "dateRelease" property. I want to retrieve that date and format it using my displayDate() function before displaying it. ...

Ways to retrieve the CSS class names associated with an element

To determine if an element has been selected, I rely on checking for the presence of an additional CSS class called "selected" that is added to the element The structure of my element is as follows: <div class="b-wide-option" data-bind="css: { selecte ...

Display a navigation link in Bootstrap 4 when the website is viewed on a mobile

I am facing an issue with displaying a nav link on a responsive page. Below is the code snippet for reference: <div class="collapse navbar-collapse w-100 order-1 order-lg-0" id="navbarNav"> <ul class="n ...

Display various items using only one EJS scriptlet tag

I'm currently facing a challenge with rendering two objects using EJS. I am curious to know if it is feasible to render them both within the same pair of scriptlet tags or if they need to be rendered separately? So far, I have been able to successful ...